4 * Citadel/UX message support routines
5 * see copyright.txt for copyright information
11 #include <sys/types.h>
22 #if TIME_WITH_SYS_TIME
23 # include <sys/time.h>
27 # include <sys/time.h>
39 #include "citadel_ipc.h"
45 #define MAXWORDBUF SIZ
49 char text[MAXWORDBUF];
52 void sttybbs(int cmd);
53 int haschar(const char *st, int ch);
54 int checkpagin(int lp, int pagin, int height);
55 void getline(char *string, int lim);
56 void formout(char *name);
58 void newprompt(char *prompt, char *str, int len);
59 int file_checksum(char *filename);
60 void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd);
65 char rc_alt_semantics;
66 extern char room_name[];
67 extern unsigned room_flags;
68 extern long highest_msg_read;
69 extern struct CtdlServInfo serv_info;
72 extern int screenwidth;
73 extern int screenheight;
74 extern long maxmsgnum;
77 extern char is_room_aide;
78 extern char fullname[];
80 extern unsigned userflags;
81 extern char sigcaught;
82 extern char editor_path[];
83 extern char printcmd[];
84 extern int rc_allow_attachments;
85 extern int rc_display_message_numbers;
86 extern int rc_force_mail_prompts;
88 extern int editor_pid;
90 void ka_sigcatch(int signum)
93 signal(SIGALRM, ka_sigcatch);
99 * server keep-alive version of wait() (needed for external editor)
101 pid_t ka_wait(int *kstatus)
106 signal(SIGALRM, ka_sigcatch);
110 } while (errno == EINTR);
111 signal(SIGALRM, SIG_IGN);
118 * version of system() that uses ka_wait()
120 int ka_system(char *shc)
129 perror("Cannot fork");
131 return ((pid_t) childpid);
135 execlp("/bin/sh", "sh", "-c", shc, NULL);
141 waitpid = ka_wait(&retcode);
142 } while (waitpid != childpid);
152 * add a newline to the buffer...
154 void add_newline(struct cittext *textlist)
159 while (ptr->next != NULL)
162 while (ptr->text[strlen(ptr->text) - 1] == 32)
163 ptr->text[strlen(ptr->text) - 1] = 0;
164 /* strcat(ptr->text,"\n"); */
166 ptr->next = (struct cittext *)
167 malloc(sizeof(struct cittext));
170 strcpy(ptr->text, "");
175 * add a word to the buffer...
177 void add_word(struct cittext *textlist, char *wordbuf)
182 while (ptr->next != NULL)
185 if (3 + strlen(ptr->text) + strlen(wordbuf) > screenwidth) {
186 ptr->next = (struct cittext *)
187 malloc(sizeof(struct cittext));
190 strcpy(ptr->text, "");
193 strcat(ptr->text, wordbuf);
194 strcat(ptr->text, " ");
199 * begin editing of an opened file pointed to by fp
201 void citedit(FILE * fp)
203 int a, prev, finished, b, last_space;
205 struct cittext *textlist = NULL;
207 char wordbuf[MAXWORDBUF];
209 /* first, load the text into the buffer */
211 textlist = (struct cittext *) malloc(sizeof(struct cittext));
212 textlist->next = NULL;
213 strcpy(textlist->text, "");
217 while (a = getc(fp), a >= 0) {
219 if ((a == 32) || (a == 9) || (a == 13) || (a == 10)) {
220 add_word(textlist, wordbuf);
222 if ((prev == 13) || (prev == 10)) {
223 add_word(textlist, "\n");
224 add_newline(textlist);
225 add_word(textlist, "");
228 wordbuf[strlen(wordbuf) + 1] = 0;
229 wordbuf[strlen(wordbuf)] = a;
231 if (strlen(wordbuf) + 3 > screenwidth) {
232 add_word(textlist, wordbuf);
240 prev = (appending ? 13 : (-1));
252 /******* new ***********/
253 if ((a > 32) && (a < 127) && (prev == 13)) {
254 add_word(textlist, "\n");
257 /***********************/
259 if ((a == 32) && (prev == 13)) {
260 add_word(textlist, "\n");
261 add_newline(textlist);
265 if (strlen(wordbuf) > 0) {
266 wordbuf[strlen(wordbuf) - 1] = 0;
271 } else if (a == 23) {
273 wordbuf[strlen(wordbuf) - 1] = 0;
277 } while (strlen(wordbuf) && wordbuf[strlen(wordbuf) - 1] != ' ');
278 } else if (a == 13) {
280 if (strlen(wordbuf) == 0)
283 for (b = 0; b < strlen(wordbuf); ++b)
284 if (wordbuf[b] == 32) {
292 add_word(textlist, wordbuf);
297 wordbuf[strlen(wordbuf) + 1] = 0;
298 wordbuf[strlen(wordbuf)] = a;
300 if ((strlen(wordbuf) + 3) > screenwidth) {
302 for (b = 0; b < strlen(wordbuf); ++b)
303 if (wordbuf[b] == 32)
305 if (last_space >= 0) {
306 for (b = 0; b < strlen(wordbuf); ++b)
307 if (wordbuf[b] == 32) {
315 for (b = 0; b < strlen(wordbuf); ++b) {
320 scr_printf("\n%s", wordbuf);
322 add_word(textlist, wordbuf);
328 } while (finished == 0);
331 /* write the buffer back to disk */
333 for (ptr = textlist; ptr != NULL; ptr = ptr->next) {
334 fprintf(fp, "%s", ptr->text);
338 ftruncate(fileno(fp), ftell(fp));
340 /* and deallocate the memory we used */
341 while (textlist != NULL) {
342 ptr = textlist->next;
348 /* Read a message from the server
351 long num, /* message number */
352 char pagin, /* 0 = normal read, 1 = read with pagination, 2 = header */
353 FILE *dest) /* Destination file, NULL for screen */
360 struct ctdlipcmessage *message = NULL;
362 char reply_subject[SIZ];
363 int r; /* IPC response code */
368 r = CtdlIPCGetSingleMessage(num, (pagin == READ_HEADER ? 1 : 0), 0,
371 err_printf("*** msg #%ld: %d %s\n", num, r, buf);
374 checkpagin(lines_printed, pagin, screenheight);
379 strcpy(reply_to, "nobody ... xxxxx");
382 fprintf(dest, "\n ");
386 lines_printed = checkpagin(lines_printed, pagin, screenheight);
389 if (pagin == 1 && !dest) {
393 /* View headers only */
395 sprintf(buf, "nhdr=%s\nfrom=%s\ntype=%d\nmsgn=%s\n",
396 message->nhdr ? "yes" : "no",
397 message->author, message->type,
399 /* FIXME output buf */
400 if (strlen(message->subject)) {
401 sprintf(buf, "subj=%s\n", message->subject);
402 /* FIXME: output buf */
404 if (strlen(message->email)) {
405 sprintf(buf, "rfca=%s\n", message->email);
406 /* FIXME: output buf */
408 sprintf(buf, "hnod=%s\nroom=%s\nnode=%s\ntime=%s",
409 message->hnod, message->room,
411 asctime(localtime(&message->time)));
412 if (strlen(message->recipient)) {
413 sprintf(buf, "rcpt=%s\n", message->recipient);
414 /* FIXME: output buf */
416 if (message->attachments) {
419 for (ptr = message->attachments; ptr; ptr = ptr->next) {
420 sprintf(buf, "part=%s|%s|%s|%s|%s|%ld\n",
421 ptr->name, ptr->filename, ptr->number,
422 ptr->disposition, ptr->mimetype,
424 /* FIXME: output buf */
431 if (rc_display_message_numbers) {
433 fprintf(dest, "[#%s] ", message->msgid);
438 scr_printf("#%s", message->msgid);
443 if (nhdr == 1 && !is_room_aide) {
445 fprintf(dest, " ****");
450 fmt_date(now, sizeof now, message->time, 0);
452 fprintf(dest, "%s from %s ", now, message->author);
453 if (strlen(message->email)) {
454 fprintf(dest, "<%s> ", message->email);
458 scr_printf("%s ", now);
462 scr_printf("%s ", message->author);
463 if (strlen(message->email)) {
467 scr_printf("%s", message->email);
472 if (strlen(message->node)) {
473 if ((room_flags & QR_NETWORK)
474 || ((strcasecmp(message->node, serv_info.serv_nodename)
475 && (strcasecmp(message->node, serv_info.serv_fqdn))))) {
476 if (strlen(message->email) == 0) {
478 fprintf(dest, "@%s ", message->node);
482 color(BRIGHT_YELLOW);
483 scr_printf("%s ", message->node);
488 if (strcasecmp(message->hnod, serv_info.serv_humannode)
489 && (strlen(message->hnod)) && (!strlen(message->email))) {
491 fprintf(dest, "(%s) ", message->hnod);
496 scr_printf("%s", message->hnod);
501 if (strcasecmp(message->room, room_name) && (strlen(message->email) == 0)) {
503 fprintf(dest, "in %s> ", message->room);
507 color(BRIGHT_MAGENTA);
508 scr_printf("%s> ", message->room);
511 if (strlen(message->recipient)) {
513 fprintf(dest, "to %s ", message->recipient);
518 scr_printf("%s ", message->recipient);
529 if (strlen(message->email) > 0) {
530 strcpy(reply_to, message->email);
532 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
533 message->author, message->node);
536 if (pagin == 1 && !dest)
540 lines_printed = checkpagin(lines_printed, pagin, screenheight);
543 strcpy(reply_subject, message->subject);
544 if (strlen(message->subject) > 0) {
546 fprintf(dest, "Subject: %s\n", message->subject);
548 scr_printf("Subject: %s\n", message->subject);
550 lines_printed = checkpagin(lines_printed,
551 pagin, screenheight);
555 /******* end of header output, start of message text output *******/
557 /* scr_printf("message->mime_chosen is <%s>\n", message->mime_chosen); FIXME */
559 if (format_type == 0) {
560 fr = fmout(screenwidth, NULL, message->text, dest,
561 ((pagin == 1) ? 1 : 0), screenheight, (-1), 1);
565 for (i = 0; i < num_tokens(message->text, '\n'); i++) {
566 if (sigcaught == 0) {
567 extract_token(buf, message->text, i, '\n');
569 fprintf(dest, "%s\n", buf);
571 scr_printf("%s\n", buf);
572 lines_printed = lines_printed + 1 +
573 (strlen(buf) / screenwidth);
575 checkpagin(lines_printed, pagin,
588 lines_printed = checkpagin(lines_printed, pagin, screenheight);
593 if (pagin == 1 && !dest)
600 * replace string function for the built-in editor
602 void replace_string(char *filename, long int startpos)
611 int substitutions = 0;
614 scr_printf("Enter text to be replaced:\n: ");
615 getline(srch_str, (sizeof(srch_str)-1) );
616 if (strlen(srch_str) == 0)
619 scr_printf("Enter text to replace it with:\n: ");
620 getline(rplc_str, (sizeof(rplc_str)-1) );
622 fp = fopen(filename, "r+");
627 fseek(fp, startpos, 0);
629 while (a = getc(fp), a > 0) {
631 buf[strlen(buf) + 1] = 0;
632 buf[strlen(buf)] = a;
633 if (strlen(buf) >= strlen(srch_str)) {
634 ptr = (&buf[strlen(buf) - strlen(srch_str)]);
635 if (!strncasecmp(ptr, srch_str, strlen(srch_str))) {
636 strcpy(ptr, rplc_str);
640 if (strlen(buf) > 384) {
643 fwrite((char *) buf, 128, 1, fp);
644 strcpy(buf, &buf[128]);
651 fwrite((char *) buf, strlen(buf), 1, fp);
654 truncate(filename, wpos);
655 scr_printf("<R>eplace made %d substitution(s).\n\n", substitutions);
659 * Function to begin composing a new message
661 int client_make_message(char *filename, /* temporary file name */
662 char *recipient, /* NULL if it's not mail */
663 int anon_type, /* see MES_ types in header file */
666 char *subject) /* buffer to store subject line */
676 if (strlen(editor_path) == 0) {
678 ("*** No editor available, using built-in editor\n");
682 fmt_date(datestr, sizeof datestr, time(NULL), 0);
685 if (room_flags & QR_ANONONLY && !recipient) {
686 snprintf(header, sizeof header, " ****");
689 snprintf(header, sizeof header,
690 " %s from %s", datestr, fullname);
691 if (strlen(recipient) > 0) {
692 size_t tmp = strlen(header);
693 snprintf(&header[tmp], sizeof header - tmp,
694 " to %s", recipient);
697 scr_printf("%s\n", header);
698 if (subject != NULL) if (strlen(subject) > 0) {
699 scr_printf("Subject: %s\n", subject);
705 scr_printf("(Press ctrl-d when finished)\n");
709 fp = fopen(filename, "r");
711 fmout(screenwidth, fp, NULL, NULL, 0, screenheight, 0, 0);
715 fp = fopen(filename, "w");
717 err_printf("*** Error opening temp file!\n"
719 filename, strerror(errno));
729 fp = fopen(filename, "r+");
731 err_printf("*** Error opening temp file!\n"
733 filename, strerror(errno));
741 fp = fopen(filename, "a");
743 err_printf("*** Error opening temp file!\n"
745 filename, strerror(errno));
765 e_ex_code = 1; /* start with a failed exit code */
767 cksum = file_checksum(filename);
768 if (editor_pid == 0) {
771 chmod(filename, 0600);
774 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", header);
776 execlp(editor_path, editor_path, filename, NULL);
782 b = ka_wait(&e_ex_code);
783 } while ((b != editor_pid) && (b >= 0));
790 MECR: if (mode == 2) {
791 if (file_checksum(filename) == cksum) {
792 err_printf("*** Aborted message.\n");
800 b = keymenu("Entry command (? for options)",
801 "<A>bort|<C>ontinue|<S>ave message|<P>rint formatted|"
803 "<R>eplace string|<H>old message");
812 scr_printf(" %s from %s", datestr, fullname);
813 if (strlen(recipient) > 0)
814 scr_printf(" to %s", recipient);
816 if (subject != NULL) if (strlen(subject) > 0) {
817 scr_printf("Subject: %s\n", subject);
819 fp = fopen(filename, "r");
821 fmout(screenwidth, fp, NULL, NULL,
822 ((userflags & US_PAGINATOR) ? 1 : 0),
830 replace_string(filename, 0L);
837 if (subject != NULL) {
838 newprompt("Subject: ", subject, 70);
845 MEABT: scr_printf("Are you sure? ");
849 MEABT2: unlink(filename);
854 * Transmit message text to the server.
856 * This loop also implements a "tick" counter that displays the progress, if
857 * we're sending something that will take a long time to transmit.
859 void transmit_message(FILE *fp)
866 fseek(fp, 0L, SEEK_END);
869 lasttick = time(NULL);
871 while (ch = getc(fp), (ch >= 0)) {
873 if (!strcmp(buf, "000"))
881 if ((ch == 32) && (strlen(buf) > 200)) {
883 if (!strcmp(buf, "000"))
888 if (strlen(buf) > 250) {
889 if (!strcmp(buf, "000"))
896 if ((time(NULL) - lasttick) > 2L) {
897 scr_printf(" %3ld%% completed\r",
898 ((ftell(fp) * 100L) / msglen));
900 lasttick = time(NULL);
912 * entmsg() - edit and create a message
913 * returns 0 if message was saved
915 int entmsg(int is_reply, /* nonzero if this was a <R>eply command */
926 char reply_subject[SIZ];
937 * First, check to see if we have permission to enter a message in
938 * this room. The server will return an error code if we can't.
940 snprintf(cmd, sizeof cmd, "ENT0 0||0|%d", mode);
944 if ((strncmp(cmd, "570", 3)) && (strncmp(cmd, "200", 3))) {
945 scr_printf("%s\n", &cmd[4]);
949 /* Error code 570 is special. It means that we CAN enter a message
950 * in this room, but a recipient needs to be specified.
953 if (!strncmp(cmd, "570", 3))
956 /* If the user is a dumbass, tell them how to type. */
957 if ((userflags & US_EXPERT) == 0) {
961 /* Handle the selection of a recipient, if necessary. */
963 if (need_recp == 1) {
966 strcpy(buf, reply_to);
968 scr_printf("Enter recipient: ");
969 getline(buf, (SIZ-100) );
970 if (strlen(buf) == 0)
974 strcpy(buf, "sysop");
978 if (strlen(reply_subject) > 0) {
979 if (!strncasecmp(reply_subject,
981 strcpy(subject, reply_subject);
993 if (room_flags & QR_ANONOPT) {
994 scr_printf("Anonymous (Y/N)? ");
999 /* If it's mail, we've got to check the validity of the recipient... */
1000 if (strlen(buf) > 0) {
1001 snprintf(cmd, sizeof cmd, "ENT0 0|%s|%d|%d|%s", buf, b, mode, subject);
1004 if (cmd[0] != '2') {
1005 scr_printf("%s\n", &cmd[4]);
1010 /* Learn the number of the newest message in in the room, so we can
1011 * tell upon saving whether someone else has posted too.
1014 serv_puts("MSGS LAST|1");
1016 if (cmd[0] != '1') {
1017 scr_printf("%s\n", &cmd[5]);
1019 while (serv_gets(cmd), strcmp(cmd, "000")) {
1021 if ((num_msgs + 1) > msg_arr_size) {
1022 msg_arr_size += 512;
1023 msg_arr = realloc(msg_arr,
1024 ((sizeof(long)) * msg_arr_size) );
1027 msg_arr[num_msgs++] = atol(cmd);
1031 /* Now compose the message... */
1032 if (client_make_message(temp, buf, b, 0, c, subject) != 0) {
1036 /* Reopen the temp file that was created, so we can send it */
1037 fp = fopen(temp, "r");
1039 /* Yes, unlink it now, so it doesn't stick around if we crash */
1043 err_printf("*** Internal error while trying to save message!\n"
1045 temp, strerror(errno));
1049 /* Transmit message to the server */
1050 snprintf(cmd, sizeof cmd, "ENT0 1|%s|%d|%d|%s|", buf, b, mode, subject);
1053 if (cmd[0] != '4') {
1054 scr_printf("%s\n", &cmd[4]);
1058 transmit_message(fp);
1063 highmsg = msg_arr[num_msgs - 1];
1065 serv_puts("MSGS NEW");
1067 if (cmd[0] != '1') {
1068 scr_printf("%s\n", &cmd[5]);
1070 while (serv_gets(cmd), strcmp(cmd, "000")) {
1071 msg_arr[num_msgs++] = atol(cmd);
1075 /* get new highest message number in room to set lrp for goto... */
1076 maxmsgnum = msg_arr[num_msgs - 1];
1078 /* now see if anyone else has posted in here */
1080 for (a = 0; a < num_msgs; ++a) {
1081 if (msg_arr[a] > highmsg) {
1086 /* In the Mail> room, this algorithm always counts one message
1087 * higher than in public rooms, so we decrement it by one.
1094 scr_printf("*** 1 additional message has been entered "
1095 "in this room by another user.\n");
1098 scr_printf("*** %d additional messages have been entered "
1099 "in this room by other users.\n", b);
1106 * Do editing on a quoted file
1108 void process_quote(void)
1110 FILE *qfile, *tfile;
1112 int line, qstart, qend;
1114 /* Unlink the second temp file as soon as it's opened, so it'll get
1115 * deleted even if the program dies
1117 qfile = fopen(temp2, "r");
1120 /* Display the quotable text with line numbers added */
1122 fgets(buf, 128, qfile);
1123 while (fgets(buf, 128, qfile) != NULL) {
1124 scr_printf("%2d %s", ++line, buf);
1126 scr_printf("Begin quoting at [ 1] : ");
1128 qstart = (buf[0] == 0) ? (1) : atoi(buf);
1129 scr_printf(" End quoting at [%d] : ", line);
1131 qend = (buf[0] == 0) ? (line) : atoi(buf);
1134 fgets(buf, 128, qfile);
1135 tfile = fopen(temp, "w");
1136 while (fgets(buf, 128, qfile) != NULL) {
1137 if ((++line >= qstart) && (line <= qend))
1138 fprintf(tfile, " >%s", buf);
1140 fprintf(tfile, " \n");
1149 * List the URL's which were embedded in the previous message
1156 if (num_urls == 0) {
1157 scr_printf("There were no URL's in the previous message.\n\n");
1161 for (i = 0; i < num_urls; ++i) {
1162 scr_printf("%3d %s\n", i + 1, urls[i]);
1165 if ((i = num_urls) != 1)
1166 i = intprompt("Display which one", 1, 1, num_urls);
1168 snprintf(cmd, sizeof cmd, rc_url_cmd, urls[i - 1]);
1174 * Read the messages in the current room
1177 int c, /* 0=Read all 1=Read new 2=Read old 3=Read last q */
1178 int rdir, /* 1=Forward (-1)=Reverse */
1179 int q /* Number of msgs to read (if c==3) */
1181 int a, b, e, f, g, start;
1187 char prtfile[PATH_MAX];
1190 char targ[ROOMNAMELEN];
1192 FILE *dest = NULL; /* Alternate destination other than screen */
1193 int r; /* IPC response code */
1200 strcpy(prtfile, tmpnam(NULL));
1203 strcpy(cmd, "MSGS ");
1215 snprintf(&cmd[5], sizeof cmd - 5, "LAST|%d", q);
1220 if (cmd[0] != '1') {
1221 scr_printf("%s\n", &cmd[5]);
1223 while (serv_gets(cmd), strcmp(cmd, "000")) {
1225 if ((num_msgs + 1) > msg_arr_size) {
1226 msg_arr_size += 512;
1227 msg_arr = realloc(msg_arr,
1228 ((sizeof(long)) * msg_arr_size) );
1231 msg_arr[num_msgs++] = atol(cmd);
1235 if (num_msgs == 0) {
1237 scr_printf("*** There are no ");
1238 if (c == 1) scr_printf("new ");
1239 if (c == 2) scr_printf("old ");
1240 scr_printf("messages in this room.\n");
1246 /* this loop cycles through each message... */
1247 start = ((rdir == 1) ? 0 : (num_msgs - 1));
1248 for (a = start; ((a < num_msgs) && (a >= 0)); a = a + rdir) {
1249 while (msg_arr[a] == 0L) {
1251 if ((a == num_msgs) || (a == (-1)))
1255 RAGAIN: pagin = ((arcflag == 0)
1257 && (userflags & US_PAGINATOR)) ? 1 : 0;
1259 /* If we're doing a quote, set the screenwidth to 72 */
1261 hold_sw = screenwidth;
1265 /* If printing or archiving, set the screenwidth to 80 */
1267 hold_sw = screenwidth;
1271 /* now read the message... */
1272 e = read_message(msg_arr[a], pagin, dest);
1274 /* ...and set the screenwidth back if we have to */
1275 if ((quotflag) || (arcflag)) {
1276 screenwidth = hold_sw;
1278 RMSGREAD: scr_flush();
1279 highest_msg_read = msg_arr[a];
1284 enable_color = hold_color;
1291 enable_color = hold_color;
1294 freopen(prtfile, "r", stdin);
1296 sttybbs(SB_RESTORE);
1297 ka_system(printcmd);
1298 sttybbs(SB_NO_INTR);
1306 } while ((g != f) && (g >= 0));
1307 scr_printf("Message printed.\n");
1309 if (rc_alt_semantics && c == 1) {
1312 r = CtdlIPCSetMessageSeen(msg_arr[a], 1, buf);
1316 if (((userflags & US_NOPROMPT) || (e == 2))
1317 && (((room_flags & QR_MAILBOX) == 0)
1318 || (rc_force_mail_prompts == 0))) {
1323 color(BRIGHT_WHITE);
1324 scr_printf("%d", num_msgs - a - 1);
1328 keyopt("<B>ack <A>gain <Q>uote <R>eply <N>ext <S>top m<Y> next ");
1329 if (rc_url_cmd[0] && num_urls)
1330 keyopt("<U>RLview ");
1331 keyopt("<?>help -> ");
1335 e = (inkey() & 127);
1337 /* return key same as <N> */ if (e == 10)
1339 /* space key same as <N> */ if (e == 32)
1341 /* del/move for aides only */
1343 && ((room_flags & QR_MAILBOX) ==
1345 if ((e == 'd') || (e == 'm'))
1348 /* print only if available */
1349 if ((e == 'p') && (strlen(printcmd) == 0))
1351 /* can't file if not allowed */
1353 && (rc_allow_attachments == 0))
1355 /* link only if browser avail*/
1357 && (strlen(rc_url_cmd) == 0))
1359 } while ((e != 'a') && (e != 'n') && (e != 's')
1360 && (e != 'd') && (e != 'm') && (e != 'p')
1361 && (e != 'q') && (e != 'b') && (e != 'h')
1362 && (e != 'r') && (e != 'f') && (e != '?')
1363 && (e != 'u') && (e != 'c') && (e != 'y'));
1369 scr_printf("Again");
1372 scr_printf("Delete");
1384 scr_printf("Print");
1387 scr_printf("Quote");
1393 scr_printf("Header");
1396 scr_printf("Reply");
1402 scr_printf("URL's");
1405 scr_printf("mY next");
1408 scr_printf("? <help>");
1411 if (userflags & US_DISAPPEAR)
1412 scr_printf("\r%79s\r", "");
1419 scr_printf("Options available here:\n"
1420 " ? Help (prints this message)\n"
1421 " S Stop reading immediately\n"
1422 " A Again (repeats last message)\n"
1423 " N Next (continue with next message)\n"
1424 " Y My Next (continue with next message you authored)\n"
1425 " B Back (go back to previous message)\n");
1427 || (room_flags & QR_MAILBOX)) {
1428 scr_printf(" D Delete this message\n"
1429 " M Move message to another room\n");
1431 scr_printf(" C Copy message to another room\n");
1432 if (strlen(printcmd) > 0)
1433 scr_printf(" P Print this message\n");
1435 " Q Quote portions of this message for your next post\n"
1436 " H Headers (display message headers only)\n");
1438 scr_printf(" R Reply to this message\n");
1439 if (rc_allow_attachments)
1441 (" F (save attachments to a file)\n");
1442 if (strlen(rc_url_cmd) > 0)
1443 scr_printf(" U (list URL's for display)\n");
1448 dest = fopen(prtfile, "w");
1450 hold_color = enable_color;
1455 dest = fopen(temp2, "w");
1457 hold_color = enable_color;
1469 newprompt("Enter target room: ",
1470 targ, ROOMNAMELEN - 1);
1471 if (strlen(targ) > 0) {
1472 r = CtdlIPCMoveMessage((e == 'c' ? 1 : 0),
1473 msg_arr[a], targ, cmd);
1474 scr_printf("%s\n", cmd);
1480 if (r / 100 != 2) /* r will be init'ed, FIXME */
1481 goto RMSGREAD; /* the logic here sucks */
1484 newprompt("Which section? ", filename,
1485 ((sizeof filename) - 1));
1486 snprintf(cmd, sizeof cmd,
1487 "OPNA %ld|%s", msg_arr[a], filename);
1490 if (cmd[0] == '2') {
1491 extract(filename, &cmd[4], 2);
1492 download_to_local_disk(filename,
1493 extract_int(&cmd[4],
1496 scr_printf("%s\n", &cmd[4]);
1500 scr_printf("*** Delete this message? ");
1502 r = CtdlIPCDeleteMessage(msg_arr[a], cmd);
1503 scr_printf("%s\n", cmd);
1511 read_message(msg_arr[a], READ_HEADER, NULL);
1514 savedpos = num_msgs;
1515 entmsg(1, (DEFAULT_ENTRY == 46 ? 2 : 0));
1516 num_msgs = savedpos;
1522 { /* hack hack hack */
1523 /* find the next message by me, stay here if we find nothing */
1526 for (finda = a; ((finda < num_msgs) && (finda >= 0)); finda += rdir)
1528 /* This is repetitively dumb, but that's what computers are for.
1529 We have to load up messages until we find one by us */
1533 snprintf(buf, sizeof buf, "MSG0 %ld|1", msg_arr[finda]); /* read the header so we can get 'from=' */
1536 while (serv_gets(buf), strcmp(buf, "000"))
1538 if ((!strncasecmp(buf, "from=", 5)) && (finda != a)) /* Skip current message. */
1540 if (strcasecmp(buf+5, fullname) == 0)
1542 a = lasta; /* meesa current */
1547 // we are now in synch with the server
1550 lasta = finda; /* keep one behind or we skip on the reentrance to the for */
1554 } /* end for loop */
1555 } /* end read routine */
1561 * View and edit a system message
1563 void edit_system_message(char *which_message)
1569 snprintf(desc, sizeof desc, "system message '%s'", which_message);
1570 snprintf(read_cmd, sizeof read_cmd, "MESG %s", which_message);
1571 snprintf(write_cmd, sizeof write_cmd, "EMSG %s", which_message);
1572 do_edit(desc, read_cmd, "NOOP", write_cmd);
1579 * Verify the message base
1581 void check_message_base(void)
1586 ("Please read the documentation before running this command.\n"
1587 "Having done so, do you still want to check the message base? ");
1593 if (buf[0] != '1') {
1594 scr_printf("%s\n", &buf[4]);
1598 while (serv_gets(buf), strcmp(buf, "000")) {
1599 scr_printf("%s\n", buf);