7 static char *rcsid_mailmaint_c = "$Header$";
11 static char rcsid_mailmaint_c[] = "$Header$";
15 /***********************************************************************/
16 /* mailmaint.c - pjlevine - 20 August 1987
19 /***********************************************************************/
26 #include </usr/include/sys/types.h>
28 #include "mit-copyright.h"
36 #define CTL(ch) ((ch) & 037)
37 #define MAX(A,B) ((A) > (B) ? (A) : (B))
43 static int bool_answer();
45 typedef struct list_info {
51 static char *ascbuff={"0123456789"};
52 static int print_2(), print_1();
53 static List_info *current_li = (List_info *) NULL;
54 static int get_list_info();
55 static int fetch_list_info();
64 typedef struct _menu {
70 MENU *main_menu, *help_menu;
72 int position[2], oldpos[2];
73 int level, found_some, currow, page, num_members;
74 int moreflg, toggle, first_time;
78 /****************************************************/
91 if (getenv("TERM") == (char *) NULL) {
92 printf("Please set your TERM environment variable\n");
95 if (getenv("TERMCAP") == (char *) NULL) {
96 printf("Please set your TERMCAP environment variable\n");
99 if ((whoami = rindex(argv[0], '/')) == NULL)
103 uname = (char *) calloc(20, 1);
104 if ((current_li = (List_info *) malloc(sizeof(List_info)))
105 == (List_info *) NULL) {
106 (void) sprintf(buf, ": allocating list info");
109 current_li->acl = (char *) NULL;
110 current_li->desc = (char *) NULL;
111 current_li->expdate = (char *) NULL;
113 if ((uname = getlogin()) == NULL) {
114 struct passwd *getpwuid();
115 uname = getpwuid(getuid())->pw_name;
117 uname = (uname && strlen(uname))? ds(uname): "";
119 printf("Connecting to database for %s...please hold on.\n", uname);
121 status = sms_connect();
123 (void) sprintf(buf, "\nConnection to SMS server failed");
129 (void) sprintf(buf, "\nAuthorization failed.\n");
135 if ((LINES < 24) || (COLS < 60)) {
136 printf("Display window too small.\n\n");
138 printf("Current window parameters are (%d lines, %d columns)\n", LINES, COLS);
139 printf("Please resize your window\n");
140 printf("to at least 24 lines and 60 columns.\n");
145 position[0] = oldpos[0] = 1;
149 display_menu(main_menu);
158 com_err(whoami, status, buf);
159 /* sms_disconnect(); */
163 /****************************************************/
170 oldpos[level] = position[level];
174 toggle = num_members = moreflg = 0;
177 if (position[level] == 7)
180 c = ascbuff[position[level]];
184 case 'L' & 037: /* clear screen */
185 display_menu(main_menu);
187 case 'q': case 'Q': /*quit*/
189 highlight(main_menu);
195 case '1': /* show all lists */
201 case '2': /* get all members of a list */
207 case '3': /* display list which user is a recipient */
213 case '4': /* show description */
219 case '5': /* add to list */
225 case '6': /* delete */
231 case 27: /* up arrow */
237 if (!position[level])
243 if (position[level] > 7)
253 highlight(main_menu);
256 /****************************************************/
263 show_text(DISPROW, STARTCOL, "Show information about a list.\n\r");
264 buf = (char *) calloc(1024, 1);
265 if (Prompt("Enter List Name: ", buf, LISTSIZE)==1) {
267 if (fetch_list_info(buf, current_li) == 0) {
268 (void) sprintf(buf, "Description: %s\n\r", current_li->desc);
269 if (strlen(buf) > 60)
272 show_text(currow, STARTCOL, buf);
274 (void) sprintf(buf, "List Administrator: %s", current_li->acl);
275 show_text(currow, STARTCOL, buf);
277 (void) sprintf(buf, "Expiration date: %s", current_li->expdate);
278 show_text(currow, STARTCOL, buf);
282 show_text(currow, STARTCOL, "madm: No such list found.");
285 show_text(currow, STARTCOL, "Press any Key to continue...");
290 /****************************************************/
303 printbuf = (char *) calloc(maxcol, 1);
304 for(i=0; i<=strlen(buf); i++) {
305 printbuf[cnt] = buf[i];
308 start_display_buff(printbuf);
311 printbuf = (char *) calloc(maxcol, 1);
314 if (strlen(buf)%maxcol != 0) {
315 start_display_buff(printbuf);
320 /****************************************************/
321 start_display_buff(buff)
330 if (currow >= LINES-2) {
333 mvcur(0,0,currow,STARTCOL);
335 if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
336 printf("Flushing query...");
342 show_text(currow, STARTCOL, "continued");
345 show_text(currow, STARTCOL, buff);
348 /****************************************************/
355 show_text(DISPROW, STARTCOL, "Add yourself to a list\n\r");
356 buf = (char *) calloc(LISTMAX, 1);
357 if (Prompt("Enter List Name: ", buf, LISTSIZE)==1) {
359 argv[0] = strsave(buf);
360 argv[1] = strsave("user");
361 argv[2] = strsave(uname);
362 if (status = sms_query("add_member_to_list", 3, argv,
363 scream, (char *) NULL)) {
365 com_err(whoami, status, " found.\n");
368 sprintf(buf, "User %s added to list\r", uname);
369 show_text(DISPROW+3, STARTCOL, buf);
372 show_text(DISPROW+4, STARTCOL, "Press any Key to continue...");
378 /****************************************************/
385 show_text(DISPROW, STARTCOL, "Remove yourself from a list\n\r");
386 buf = (char *) calloc(LISTMAX, 1);
387 if (Prompt("Enter List Name: ", buf, LISTSIZE)==1) {
389 argv[0] = strsave(buf);
390 argv[1] = strsave("user");
391 argv[2] = strsave(uname);
392 if (status = sms_query("delete_member_from_list", 3, argv,
393 scream, (char *) NULL)) {
395 com_err(whoami, status, " found.\n");
398 sprintf(buf, "User %s deleted from list\r", uname);
399 show_text(DISPROW+3, STARTCOL, buf);
402 show_text(DISPROW+4, STARTCOL, "Press any Key to continue...");
407 /****************************************************/
408 list_by_member(argc, argv)
415 argv[1] = strsave("user");
416 argv[2] = strsave(uname);
417 buf = (char *) calloc(BUFSIZ, 1);
418 sprintf(buf, "%s is on the following lists:\r", uname);
419 show_text(DISPROW, STARTCOL, buf);
420 mvcur(0,0,currow, STARTCOL);
422 if (status = sms_query("get_lists_of_member", 2, argv+1,
423 print_1, (char *) NULL)) {
425 com_err(whoami, status, " in get_lists_of_member");
427 show_text(currow, STARTCOL, "Press any Key to continue...");
432 /****************************************************/
437 show_text(DISPROW, STARTCOL, "This function may take a while...proceed[y]?");
439 if (c == 'n' || c == 'N') {
440 erase_line(DISPROW, STARTCOL);
443 move(DISPROW+1, STARTCOL);
444 addstr("Processing query...please hold");
449 /****************************************************/
451 print_1(argc, argv, callback)
453 char *argv[], *callback;
457 /* no newline 'cause Put_message adds one */
458 (void) sprintf(buf, "%s\r", argv[0]);
463 /****************************************************/
465 print_all(argc, argv, callback)
467 char *argv[], *callback;
473 erase_line(DISPROW+1, STARTCOL);
474 show_text(DISPROW+1, STARTCOL, "All mailing lists:");
477 (void) sprintf(buf, "%s\r", argv[0]);
483 /****************************************************/
488 if (status = sms_query("get_all_visible_maillists", 0, (char **) NULL,
489 print_all, (char *) NULL)) {
491 com_err(whoami, status, " in list_all_groups\n");
495 return (DM_NORMAL); /* HA! */
497 /****************************************************/
505 move(DISPROW, STARTCOL);
506 mvcur(0,0,DISPROW,STARTCOL);
508 buf = (char *) calloc(LISTMAX, 1);
509 if (Prompt("Enter List Name: ", buf, LISTSIZE)==1) {
510 sprintf(buffer, "The members of list '%s' are:", buf);
511 show_text(DISPROW+1, STARTCOL, buffer);
513 if (status = sms_query("get_members_of_list", 1, argv,
514 print_2, (char *) NULL)) {
516 com_err(whoami, status, " found.\n");
520 show_text(currow, STARTCOL,"List is empty (no members).");
527 return (DM_NORMAL); /* HA! */
530 /****************************************************/
532 print_2(argc, argv, callback)
534 char *argv[], *callback;
539 (void) sprintf(buf, "%s %s", argv[0], argv[1]);
544 /****************************************************/
554 buffer = (char *) calloc(50, 1);
555 if (currow >= LINES-2) {
558 mvcur(0,0,currow,STARTCOL);
560 if (Prompt("--RETURN for more, ctl-c to exit--", buffer, 1) == 0) {
561 printf("Flushing query...");
567 sprintf(buffer, "Continued (Page %d)", page);
568 show_text(currow, STARTCOL, buffer);
573 show_text(currow, STARTCOL, buff);
575 show_text(currow, SECONDCOL, buff);
580 /****************************************************/
590 buffer = (char *) calloc(50, 1);
592 sprintf(buffer, "End of List. %d Total Members\r", num_members);
593 show_text(currow, STARTCOL, buffer);
595 show_text(currow, STARTCOL, "Press any key to continue...");
600 /****************************************************/
608 mvcur(0,0,STARTROW, STARTCOL);
610 for(i=0; i<=menu->num_items-1; i++) {
611 move(STARTROW+i, STARTCOL);
613 addstr(menu->items[i]);
616 center_text(STARTROW+menu->num_items+2,
617 "Enter a number, <up arrow>, or <down arrow>.");
619 center_text(STARTROW+menu->num_items+3,
620 "Press 'q' to exit, <return> to confirm choice.");
622 center_text(STARTROW+menu->num_items+3,
623 "Press 'q' to exit, 'r' for main menu, <return> to confirm choice.");
626 highlight(main_menu);
629 /****************************************************/
634 main_menu = (MENU *) malloc((unsigned) sizeof(MENU));
635 main_menu->num_items = 7;
636 main_menu->items = (char **) malloc((unsigned) sizeof(char *) * main_menu->num_items);
638 buf = (char *) calloc(50, 1);
639 sprintf(buf, "Mail List Program for %s", uname);
640 main_menu->title = strsave(buf);
641 main_menu->items[0] = strsave("1. Show all mailing lists.");
642 main_menu->items[1] = strsave("2. Get all members of a mailing list.");
643 main_menu->items[2] = strsave("3. Display lists of which you are a member.");
644 main_menu->items[3] = strsave("4. Show description of list.");
645 main_menu->items[4] = strsave("5. Add yourself to a mailing list.");
646 main_menu->items[5] = strsave("6. Delete yourself from a mailing list.");
647 main_menu->items[6] = strsave("q. Quit.");
650 /****************************************************/
653 help_menu = (MENU *) malloc((unsigned) sizeof(MENU));
654 help_menu->num_items = 5;
655 help_menu->items = (char **) malloc((unsigned) sizeof(char *) * help_menu->num_items);
657 help_menu->title = strsave("madm is designed as a basic mail list administration program.");
658 help_menu->items[0] = strsave("if you need to perform more advanced list manipulation like");
659 help_menu->items[1] = strsave("adding lists, or changing list characteristics, refer to the");
660 help_menu->items[2] = strsave("program listmaint.");
661 help_menu->items[3] = strsave(" ");
662 help_menu->items[4] = strsave("Press any key to continue.");
664 /****************************************************/
670 show_text(currow, STARTCOL, help_menu->title);
671 for(i=0;i<=help_menu->num_items-1;i++) {
673 show_text(currow, STARTCOL, help_menu->items[i]);
678 /****************************************************/
684 if (oldpos[level] != position[level]) {
685 move(STARTROW+oldpos[level]-1, STARTCOL);
687 addstr(menu->items[oldpos[level]-1]);
691 move(STARTROW+position[level]-1, STARTCOL);
693 addstr(menu->items[position[level]-1]);
699 /****************************************************/
703 move(0, MAX(0, (COLS - strlen(buff))>>1));
709 /****************************************************/
715 mvcur(0,0,row,STARTCOL);
720 mvcur(0,0,row,STARTCOL);
728 /****************************************************/
729 center_text(row, buff)
733 move(row, MAX(0, (COLS - strlen(buff))>>1));
738 /****************************************************/
739 show_text(row, col, buff)
748 /****************************************************/
755 buff = (char *) calloc(COLS, 1);
756 for(i=0; i<=COLS-2; i++)
758 buff[i] = 0; /* just to be sure ! */
765 /****************************************************/
772 /****************************************************/
782 maxcol = 80; /* limit width */
784 buff = (char *) calloc(maxcol+1, 1);
785 for(i=0; i<=maxcol-1; i++)
787 buff[i] = 0; /* just to be sure ! */
788 mvcur(0,0,erase_row, STARTCOL);
790 for(i=erase_row; i<=currow-1; i++) {
791 printf("%s\n\r", buff);
794 mvcur(erase_row,STARTCOL,STARTROW+oldpos[level]-1, STARTCOL);
798 /****************************************************/
804 if ((p = (char *) calloc(1, strlen(s)+1)) != NULL) {
808 printf("error in alloc\n\r");
811 /****************************************************/
812 /* jean's routine ??? */
815 com_err(whoami, status, "\nAn SMS update returned a value -- programmer \
820 /****************************************************/
821 static int fetch_list_info(list, li)
828 if ((status = sms_query("get_list_info", 1, argv,
829 get_list_info, (char *) NULL)) == 0) {
833 com_err(whoami, status, " found.\n");
839 static int get_list_info(argc, argv)
845 free(current_li->acl);
846 current_li->acl = strsave(argv[2]);
847 if (current_li->desc)
848 free(current_li->desc);
849 current_li->desc = strsave(argv[3]);
850 if (current_li->expdate)
851 free(current_li->expdate);
852 current_li->expdate = strsave(argv[4]);
859 /****************************************************/
860 /* Prompt the user for input */
861 int Prompt(prompt, buf, buflen)
870 printf("%s", prompt);
872 for (p = buf; abs(strlen(p)-strlen(buf)) <= buflen;) {
882 display_menu(main_menu);
888 if (strlen(buf) < 1) /* only /n or /r in buff */
909 if (abs(strlen(p)-strlen(buf)) >= buflen) {
930 register char *newstr = malloc((unsigned) strlen(str) + 1);
932 if (newstr == (char *) NULL)
933 return ((char *) NULL);
935 return (strcpy(newstr, str));
938 int bool_query(name, argc, argv)
944 sms_query(name, argc, argv, bool_answer, (caddr_t) &result);
948 static int bool_answer(argc, argv, arg)
953 int *result = (int *) arg;
954 if (strcmp(argv[0], "true") == 0)
956 else if (strcmp(argv[0], "false") == 0)
965 * c-continued-statement-offset: 4
967 * c-argdecl-indent: 4