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>
35 #include "citadel_ipc.h"
36 #include "citadel_decls.h"
47 #define MAXWORDBUF SIZ
48 #define NO_REPLY_TO "nobody ... xxxxxx"
51 char reply_subject[SIZ];
55 char text[MAXWORDBUF];
58 void sttybbs(int cmd);
59 int haschar(const char *st, int ch);
60 void getline(char *string, int lim);
61 int file_checksum(char *filename);
62 void progress(unsigned long curr, unsigned long cmax);
64 unsigned long *msg_arr = NULL;
67 char rc_alt_semantics;
68 extern char room_name[];
69 extern unsigned room_flags;
70 extern long highest_msg_read;
71 extern struct CtdlServInfo serv_info;
74 extern int screenwidth;
75 extern int screenheight;
76 extern long maxmsgnum;
79 extern char is_room_aide;
80 extern char fullname[];
82 extern unsigned userflags;
83 extern char sigcaught;
84 extern char editor_path[];
85 extern char printcmd[];
86 extern int rc_allow_attachments;
87 extern int rc_display_message_numbers;
88 extern int rc_force_mail_prompts;
89 extern int editor_pid;
90 extern CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
92 void ka_sigcatch(int signum)
95 signal(SIGALRM, ka_sigcatch);
96 CtdlIPCNoop(ipc_for_signal_handlers);
101 * server keep-alive version of wait() (needed for external editor)
103 pid_t ka_wait(int *kstatus)
108 signal(SIGALRM, ka_sigcatch);
112 } while (errno == EINTR);
113 signal(SIGALRM, SIG_IGN);
120 * version of system() that uses ka_wait()
122 int ka_system(char *shc)
131 perror("Cannot fork");
133 return ((pid_t) childpid);
137 execlp("/bin/sh", "sh", "-c", shc, NULL);
143 waitpid = ka_wait(&retcode);
144 } while (waitpid != childpid);
154 * add a newline to the buffer...
156 void add_newline(struct cittext *textlist)
161 while (ptr->next != NULL)
164 while (ptr->text[strlen(ptr->text) - 1] == 32)
165 ptr->text[strlen(ptr->text) - 1] = 0;
166 /* strcat(ptr->text,"\n"); */
168 ptr->next = (struct cittext *)
169 malloc(sizeof(struct cittext));
172 strcpy(ptr->text, "");
177 * add a word to the buffer...
179 void add_word(struct cittext *textlist, char *wordbuf)
184 while (ptr->next != NULL)
187 if (3 + strlen(ptr->text) + strlen(wordbuf) > screenwidth) {
188 ptr->next = (struct cittext *)
189 malloc(sizeof(struct cittext));
192 strcpy(ptr->text, "");
195 strcat(ptr->text, wordbuf);
196 strcat(ptr->text, " ");
201 * begin editing of an opened file pointed to by fp
203 void citedit(CtdlIPC *ipc, FILE * fp)
205 int a, prev, finished, b, last_space;
207 struct cittext *textlist = NULL;
209 char wordbuf[MAXWORDBUF];
211 /* first, load the text into the buffer */
213 textlist = (struct cittext *) malloc(sizeof(struct cittext));
214 textlist->next = NULL;
215 strcpy(textlist->text, "");
219 while (a = getc(fp), a >= 0) {
221 if ((a == 32) || (a == 9) || (a == 13) || (a == 10)) {
222 add_word(textlist, wordbuf);
224 if ((prev == 13) || (prev == 10)) {
225 add_word(textlist, "\n");
226 add_newline(textlist);
227 add_word(textlist, "");
230 wordbuf[strlen(wordbuf) + 1] = 0;
231 wordbuf[strlen(wordbuf)] = a;
233 if (strlen(wordbuf) + 3 > screenwidth) {
234 add_word(textlist, wordbuf);
242 prev = (appending ? 13 : (-1));
254 /******* new ***********/
255 if ((a > 32) && (a < 127) && (prev == 13)) {
256 add_word(textlist, "\n");
259 /***********************/
261 if ((a == 32) && (prev == 13)) {
262 add_word(textlist, "\n");
263 add_newline(textlist);
267 if (strlen(wordbuf) > 0) {
268 wordbuf[strlen(wordbuf) - 1] = 0;
273 } else if (a == 23) {
275 wordbuf[strlen(wordbuf) - 1] = 0;
279 } while (strlen(wordbuf) && wordbuf[strlen(wordbuf) - 1] != ' ');
280 } else if (a == 13) {
282 if (strlen(wordbuf) == 0)
285 for (b = 0; b < strlen(wordbuf); ++b)
286 if (wordbuf[b] == 32) {
294 add_word(textlist, wordbuf);
299 wordbuf[strlen(wordbuf) + 1] = 0;
300 wordbuf[strlen(wordbuf)] = a;
302 if ((strlen(wordbuf) + 3) > screenwidth) {
304 for (b = 0; b < strlen(wordbuf); ++b)
305 if (wordbuf[b] == 32)
307 if (last_space >= 0) {
308 for (b = 0; b < strlen(wordbuf); ++b)
309 if (wordbuf[b] == 32) {
317 for (b = 0; b < strlen(wordbuf); ++b) {
322 scr_printf("\n%s", wordbuf);
324 add_word(textlist, wordbuf);
330 } while (finished == 0);
333 /* write the buffer back to disk */
335 for (ptr = textlist; ptr != NULL; ptr = ptr->next) {
336 fprintf(fp, "%s", ptr->text);
340 ftruncate(fileno(fp), ftell(fp));
342 /* and deallocate the memory we used */
343 while (textlist != NULL) {
344 ptr = textlist->next;
350 /* Read a message from the server
352 int read_message(CtdlIPC *ipc,
353 long num, /* message number */
354 int pagin, /* 0 = normal read, 1 = read with pagination, 2 = header */
355 FILE *dest) /* Destination file, NULL for screen */
362 struct ctdlipcmessage *message = NULL;
363 int r; /* IPC response code */
364 char *converted_text = NULL;
369 strcpy(reply_to, NO_REPLY_TO);
370 strcpy(reply_subject, "");
372 r = CtdlIPCGetSingleMessage(ipc, num, (pagin == READ_HEADER ? 1 : 0),
373 (can_do_msg4 ? 4 : 0),
376 err_printf("*** msg #%ld: %d %s\n", num, r, buf);
379 checkpagin(lines_printed, pagin, screenheight);
385 fprintf(dest, "\n ");
389 lines_printed = checkpagin(lines_printed, pagin, screenheight);
393 if (pagin == 1 && !dest) {
397 /* View headers only */
399 pprintf("nhdr=%s\nfrom=%s\ntype=%d\nmsgn=%s\n",
400 message->nhdr ? "yes" : "no",
401 message->author, message->type,
403 if (strlen(message->subject)) {
404 pprintf("subj=%s\n", message->subject);
406 if (strlen(message->email)) {
407 pprintf("rfca=%s\n", message->email);
409 pprintf("hnod=%s\nroom=%s\nnode=%s\ntime=%s",
410 message->hnod, message->room,
412 asctime(localtime(&message->time)));
413 if (strlen(message->recipient)) {
414 pprintf("rcpt=%s\n", message->recipient);
416 if (message->attachments) {
419 for (ptr = message->attachments; ptr; ptr = ptr->next) {
420 pprintf("part=%s|%s|%s|%s|%s|%ld\n",
421 ptr->name, ptr->filename, ptr->number,
422 ptr->disposition, ptr->mimetype,
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 /* Set the reply-to address to an Internet e-mail address if possible
531 if (message->email != NULL) if (strlen(message->email) > 0) {
532 safestrncpy(reply_to, message->email, sizeof reply_to);
535 /* But if we can't do that, set it to a Citadel address.
537 if (!strcmp(reply_to, NO_REPLY_TO)) {
538 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
539 message->author, message->node);
544 lines_printed = checkpagin(lines_printed, pagin, screenheight);
547 if (message->subject != NULL) {
548 safestrncpy(reply_subject, message->subject,
549 sizeof reply_subject);
550 if (strlen(message->subject) > 0) {
552 fprintf(dest, "Subject: %s\n",
556 scr_printf("Subject: ");
558 scr_printf("%s\n", message->subject);
560 lines_printed = checkpagin(lines_printed,
561 pagin, screenheight);
566 if (pagin == 1 && !dest) {
570 /******* end of header output, start of message text output *******/
573 * Convert HTML to plain text, formatting for the actual width
574 * of the client screen.
576 if (!strcasecmp(message->content_type, "text/html")) {
577 converted_text = html_to_ascii(message->text, screenwidth, 0);
578 if (converted_text != NULL) {
580 message->text = converted_text;
585 /* Text/plain is a different type */
586 if (!strcasecmp(message->content_type, "text/plain")) {
593 if (format_type == 0) {
594 fr = fmout(screenwidth, NULL, message->text, dest,
595 ((pagin == 1) ? 1 : 0), screenheight, (-1), 1);
597 /* FIXME: renderer for text/plain */
601 msgtext = message->text;
603 while (lineptr = strtok(msgtext, "\n"), lineptr != NULL) {
606 if (sigcaught == 0) {
608 fprintf(dest, "%s\n", lineptr);
610 scr_printf("%s\n", lineptr);
611 lines_printed = lines_printed + 1 +
612 (strlen(lineptr) / screenwidth);
614 checkpagin(lines_printed, pagin,
627 lines_printed = checkpagin(lines_printed, pagin, screenheight);
630 /* Enumerate any attachments */
631 if ( (pagin == 1) && (can_do_msg4) && (message->attachments) ) {
634 for (ptr = message->attachments; ptr; ptr = ptr->next) {
635 if ( (!strcasecmp(ptr->disposition, "attachment"))
636 || (!strcasecmp(ptr->disposition, "inline"))) {
639 color(BRIGHT_MAGENTA);
640 scr_printf("%s", ptr->number);
644 scr_printf("%s", ptr->filename);
646 scr_printf(" (%s, %ld bytes)\n", ptr->mimetype, ptr->length);
655 if (pagin == 1 && !dest)
662 * replace string function for the built-in editor
664 void replace_string(char *filename, long int startpos)
673 int substitutions = 0;
676 scr_printf("Enter text to be replaced:\n: ");
677 getline(srch_str, (sizeof(srch_str)-1) );
678 if (strlen(srch_str) == 0)
681 scr_printf("Enter text to replace it with:\n: ");
682 getline(rplc_str, (sizeof(rplc_str)-1) );
684 fp = fopen(filename, "r+");
689 fseek(fp, startpos, 0);
691 while (a = getc(fp), a > 0) {
693 buf[strlen(buf) + 1] = 0;
694 buf[strlen(buf)] = a;
695 if (strlen(buf) >= strlen(srch_str)) {
696 ptr = (&buf[strlen(buf) - strlen(srch_str)]);
697 if (!strncmp(ptr, srch_str, strlen(srch_str))) {
698 strcpy(ptr, rplc_str);
702 if (strlen(buf) > 384) {
705 fwrite((char *) buf, 128, 1, fp);
706 strcpy(buf, &buf[128]);
713 fwrite((char *) buf, strlen(buf), 1, fp);
716 truncate(filename, wpos);
717 scr_printf("<R>eplace made %d substitution(s).\n\n", substitutions);
721 * Function to begin composing a new message
723 int client_make_message(CtdlIPC *ipc,
724 char *filename, /* temporary file name */
725 char *recipient, /* NULL if it's not mail */
726 int anon_type, /* see MES_ types in header file */
729 char *subject) /* buffer to store subject line */
739 if (strlen(editor_path) == 0) {
741 ("*** No editor available, using built-in editor\n");
745 fmt_date(datestr, sizeof datestr, time(NULL), 0);
748 if (room_flags & QR_ANONONLY && !recipient) {
749 snprintf(header, sizeof header, " ****");
752 snprintf(header, sizeof header,
753 " %s from %s", datestr, fullname);
754 if (strlen(recipient) > 0) {
755 size_t tmp = strlen(header);
756 snprintf(&header[tmp], sizeof header - tmp,
757 " to %s", recipient);
760 scr_printf("%s\n", header);
761 if (subject != NULL) if (strlen(subject) > 0) {
762 scr_printf("Subject: %s\n", subject);
768 scr_printf("(Press ctrl-d when finished)\n");
772 fp = fopen(filename, "r");
774 fmout(screenwidth, fp, NULL, NULL, 0, screenheight, 0, 0);
778 fp = fopen(filename, "w");
780 err_printf("*** Error opening temp file!\n"
782 filename, strerror(errno));
792 fp = fopen(filename, "r+");
794 err_printf("*** Error opening temp file!\n"
796 filename, strerror(errno));
804 fp = fopen(filename, "a");
806 err_printf("*** Error opening temp file!\n"
808 filename, strerror(errno));
828 e_ex_code = 1; /* start with a failed exit code */
830 cksum = file_checksum(filename);
833 if (editor_pid == 0) {
836 chmod(filename, 0600);
837 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", header);
839 execlp(editor_path, editor_path, filename, NULL);
845 b = ka_wait(&e_ex_code);
846 } while ((b != editor_pid) && (b >= 0));
853 MECR: if (mode == 2) {
854 if (file_checksum(filename) == cksum) {
855 err_printf("*** Aborted message.\n");
863 b = keymenu("Entry command (? for options)",
864 "<A>bort|<C>ontinue|<S>ave message|<P>rint formatted|"
866 "<R>eplace string|<H>old message");
875 scr_printf(" %s from %s", datestr, fullname);
876 if (strlen(recipient) > 0)
877 scr_printf(" to %s", recipient);
879 if (subject != NULL) if (strlen(subject) > 0) {
880 scr_printf("Subject: %s\n", subject);
882 fp = fopen(filename, "r");
884 fmout(screenwidth, fp, NULL, NULL,
885 ((userflags & US_PAGINATOR) ? 1 : 0),
893 replace_string(filename, 0L);
900 if (subject != NULL) {
901 newprompt("Subject: ", subject, 70);
908 MEABT: scr_printf("Are you sure? ");
912 MEABT2: unlink(filename);
917 * Transmit message text to the server.
919 * This loop also implements a "tick" counter that displays the progress, if
920 * we're sending something that will take a long time to transmit.
922 void transmit_message(CtdlIPC *ipc, FILE *fp)
929 fseek(fp, 0L, SEEK_END);
932 lasttick = time(NULL);
934 while (ch = getc(fp), (ch >= 0)) {
936 if (!strcmp(buf, "000"))
938 CtdlIPC_putline(ipc, buf);
944 if ((ch == 32) && (strlen(buf) > 200)) {
946 if (!strcmp(buf, "000"))
948 CtdlIPC_putline(ipc, buf);
951 if (strlen(buf) > 250) {
952 if (!strcmp(buf, "000"))
954 CtdlIPC_putline(ipc, buf);
959 if ((time(NULL) - lasttick) > 2L) {
960 scr_printf(" %3ld%% completed\r",
961 ((ftell(fp) * 100L) / msglen));
963 lasttick = time(NULL);
967 CtdlIPC_putline(ipc, buf);
973 * Make sure there's room in msg_arr[] for at least one more.
975 void check_msg_arr_size(void) {
976 if ((num_msgs + 1) > msg_arr_size) {
978 msg_arr = realloc(msg_arr,
979 ((sizeof(long)) * msg_arr_size) );
986 * entmsg() - edit and create a message
987 * returns 0 if message was saved
989 int entmsg(CtdlIPC *ipc,
990 int is_reply, /* nonzero if this was a <R>eply command */
1007 strcpy(subject, "");
1010 * First, check to see if we have permission to enter a message in
1011 * this room. The server will return an error code if we can't.
1013 snprintf(cmd, sizeof cmd, "ENT0 0||0|%d", mode);
1014 CtdlIPC_putline(ipc, cmd);
1015 CtdlIPC_getline(ipc, cmd);
1017 if ((strncmp(cmd, "570", 3)) && (strncmp(cmd, "200", 3))) {
1018 scr_printf("%s\n", &cmd[4]);
1022 /* Error code 570 is special. It means that we CAN enter a message
1023 * in this room, but a recipient needs to be specified.
1026 if (!strncmp(cmd, "570", 3))
1029 /* If the user is a dumbass, tell them how to type. */
1030 if ((userflags & US_EXPERT) == 0) {
1031 formout(ipc, "entermsg");
1034 /* Handle the selection of a recipient, if necessary. */
1036 if (need_recp == 1) {
1039 strcpy(buf, reply_to);
1041 scr_printf("Enter recipient: ");
1042 getline(buf, (SIZ-100) );
1043 if (strlen(buf) == 0)
1047 strcpy(buf, "sysop");
1051 if (strlen(reply_subject) > 0) {
1052 if (!strncasecmp(reply_subject,
1054 strcpy(subject, reply_subject);
1066 if (room_flags & QR_ANONOPT) {
1067 scr_printf("Anonymous (Y/N)? ");
1072 /* If it's mail, we've got to check the validity of the recipient... */
1073 if (strlen(buf) > 0) {
1074 snprintf(cmd, sizeof cmd, "ENT0 0|%s|%d|%d|%s", buf, b, mode, subject);
1075 CtdlIPC_putline(ipc, cmd);
1076 CtdlIPC_getline(ipc, cmd);
1077 if (cmd[0] != '2') {
1078 scr_printf("%s\n", &cmd[4]);
1083 /* Learn the number of the newest message in in the room, so we can
1084 * tell upon saving whether someone else has posted too.
1087 CtdlIPC_putline(ipc, "MSGS LAST|1");
1088 CtdlIPC_getline(ipc, cmd);
1089 if (cmd[0] != '1') {
1090 scr_printf("%s\n", &cmd[5]);
1092 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1093 check_msg_arr_size();
1094 msg_arr[num_msgs++] = atol(cmd);
1098 /* Now compose the message... */
1099 if (client_make_message(ipc, temp, buf, b, 0, c, subject) != 0) {
1103 /* Reopen the temp file that was created, so we can send it */
1104 fp = fopen(temp, "r");
1106 /* Yes, unlink it now, so it doesn't stick around if we crash */
1110 err_printf("*** Internal error while trying to save message!\n"
1112 temp, strerror(errno));
1116 /* Transmit message to the server */
1117 snprintf(cmd, sizeof cmd, "ENT0 1|%s|%d|%d|%s|", buf, b, mode, subject);
1118 CtdlIPC_putline(ipc, cmd);
1119 CtdlIPC_getline(ipc, cmd);
1120 if (cmd[0] != '4') {
1121 scr_printf("%s\n", &cmd[4]);
1125 transmit_message(ipc, fp);
1126 CtdlIPC_putline(ipc, "000");
1130 if (num_msgs >= 1) highmsg = msg_arr[num_msgs - 1];
1132 CtdlIPC_putline(ipc, "MSGS NEW");
1133 CtdlIPC_getline(ipc, cmd);
1134 if (cmd[0] != '1') {
1135 scr_printf("%s\n", &cmd[5]);
1137 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1138 check_msg_arr_size();
1139 msg_arr[num_msgs++] = atol(cmd);
1143 /* get new highest message number in room to set lrp for goto... */
1144 maxmsgnum = msg_arr[num_msgs - 1];
1146 /* now see if anyone else has posted in here */
1148 for (a = 0; a < num_msgs; ++a) {
1149 if (msg_arr[a] > highmsg) {
1154 /* In the Mail> room, this algorithm always counts one message
1155 * higher than in public rooms, so we decrement it by one.
1162 scr_printf("*** 1 additional message has been entered "
1163 "in this room by another user.\n");
1166 scr_printf("*** %d additional messages have been entered "
1167 "in this room by other users.\n", b);
1174 * Do editing on a quoted file
1176 void process_quote(void)
1178 FILE *qfile, *tfile;
1180 int line, qstart, qend;
1182 /* Unlink the second temp file as soon as it's opened, so it'll get
1183 * deleted even if the program dies
1185 qfile = fopen(temp2, "r");
1188 /* Display the quotable text with line numbers added */
1190 fgets(buf, 128, qfile);
1191 while (fgets(buf, 128, qfile) != NULL) {
1192 scr_printf("%2d %s", ++line, buf);
1194 scr_printf("Begin quoting at [ 1] : ");
1196 qstart = (buf[0] == 0) ? (1) : atoi(buf);
1197 scr_printf(" End quoting at [%d] : ", line);
1199 qend = (buf[0] == 0) ? (line) : atoi(buf);
1202 fgets(buf, 128, qfile);
1203 tfile = fopen(temp, "w");
1204 while (fgets(buf, 128, qfile) != NULL) {
1205 if ((++line >= qstart) && (line <= qend))
1206 fprintf(tfile, " >%s", buf);
1208 fprintf(tfile, " \n");
1217 * List the URL's which were embedded in the previous message
1219 void list_urls(CtdlIPC *ipc)
1224 if (num_urls == 0) {
1225 scr_printf("There were no URL's in the previous message.\n\n");
1229 for (i = 0; i < num_urls; ++i) {
1230 scr_printf("%3d %s\n", i + 1, urls[i]);
1233 if ((i = num_urls) != 1)
1234 i = intprompt("Display which one", 1, 1, num_urls);
1236 snprintf(cmd, sizeof cmd, rc_url_cmd, urls[i - 1]);
1242 * Read the messages in the current room
1244 void readmsgs(CtdlIPC *ipc,
1245 int c, /* 0=Read all 1=Read new 2=Read old 3=Read last q */
1246 int rdir, /* 1=Forward (-1)=Reverse */
1247 int q /* Number of msgs to read (if c==3) */
1249 int a, b, e, f, g, start;
1255 char prtfile[PATH_MAX];
1258 char targ[ROOMNAMELEN];
1259 char filename[PATH_MAX];
1260 char save_to[PATH_MAX];
1261 void *attachment = NULL; /* Downloaded attachment */
1262 FILE *dest = NULL; /* Alternate destination other than screen */
1263 int r; /* IPC response code */
1270 strcpy(prtfile, tmpnam(NULL));
1273 strcpy(cmd, "MSGS ");
1285 snprintf(&cmd[5], sizeof cmd - 5, "LAST|%d", q);
1288 CtdlIPC_putline(ipc, cmd);
1289 CtdlIPC_getline(ipc, cmd);
1290 if (cmd[0] != '1') {
1291 scr_printf("%s\n", &cmd[5]);
1293 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1294 check_msg_arr_size();
1295 msg_arr[num_msgs++] = atol(cmd);
1299 if (num_msgs == 0) {
1301 scr_printf("*** There are no ");
1302 if (c == 1) scr_printf("new ");
1303 if (c == 2) scr_printf("old ");
1304 scr_printf("messages in this room.\n");
1310 /* this loop cycles through each message... */
1311 start = ((rdir == 1) ? 0 : (num_msgs - 1));
1312 for (a = start; ((a < num_msgs) && (a >= 0)); a = a + rdir) {
1313 while (msg_arr[a] == 0L) {
1315 if ((a == num_msgs) || (a == (-1)))
1319 RAGAIN: pagin = ((arcflag == 0)
1321 && (userflags & US_PAGINATOR)) ? 1 : 0;
1323 /* If we're doing a quote, set the screenwidth to 72 */
1325 hold_sw = screenwidth;
1329 /* If printing or archiving, set the screenwidth to 80 */
1331 hold_sw = screenwidth;
1335 /* now read the message... */
1336 e = read_message(ipc, msg_arr[a], pagin, dest);
1338 /* ...and set the screenwidth back if we have to */
1339 if ((quotflag) || (arcflag)) {
1340 screenwidth = hold_sw;
1342 RMSGREAD: scr_flush();
1343 highest_msg_read = msg_arr[a];
1348 enable_color = hold_color;
1355 enable_color = hold_color;
1358 freopen(prtfile, "r", stdin);
1360 sttybbs(SB_RESTORE);
1361 ka_system(printcmd);
1362 sttybbs(SB_NO_INTR);
1370 } while ((g != f) && (g >= 0));
1371 scr_printf("Message printed.\n");
1373 if (rc_alt_semantics && c == 1) {
1376 r = CtdlIPCSetMessageSeen(ipc, msg_arr[a], 1, buf);
1380 if (((userflags & US_NOPROMPT) || (e == 2))
1381 && (((room_flags & QR_MAILBOX) == 0)
1382 || (rc_force_mail_prompts == 0))) {
1387 color(BRIGHT_WHITE);
1388 scr_printf("%d", num_msgs - a - 1);
1392 keyopt("<B>ack <A>gain <Q>uote <R>eply <N>ext <S>top m<Y> next ");
1393 if (rc_url_cmd[0] && num_urls)
1394 keyopt("<U>RLview ");
1395 keyopt("<?>help -> ");
1399 e = (inkey() & 127);
1401 /* return key same as <N> */ if (e == 10)
1403 /* space key same as <N> */ if (e == 32)
1405 /* del/move for aides only */
1407 && ((room_flags & QR_MAILBOX) ==
1409 if ((e == 'd') || (e == 'm'))
1412 /* print only if available */
1413 if ((e == 'p') && (strlen(printcmd) == 0))
1415 /* can't file if not allowed */
1417 && (rc_allow_attachments == 0))
1419 /* link only if browser avail*/
1421 && (strlen(rc_url_cmd) == 0))
1423 } while ((e != 'a') && (e != 'n') && (e != 's')
1424 && (e != 'd') && (e != 'm') && (e != 'p')
1425 && (e != 'q') && (e != 'b') && (e != 'h')
1426 && (e != 'r') && (e != 'f') && (e != '?')
1427 && (e != 'u') && (e != 'c') && (e != 'y'));
1433 scr_printf("Again");
1436 scr_printf("Delete");
1448 scr_printf("Print");
1451 scr_printf("Quote");
1457 scr_printf("Header");
1460 scr_printf("Reply");
1466 scr_printf("URL's");
1469 scr_printf("mY next");
1472 scr_printf("? <help>");
1475 if (userflags & US_DISAPPEAR)
1476 scr_printf("\r%79s\r", "");
1483 scr_printf("Options available here:\n"
1484 " ? Help (prints this message)\n"
1485 " S Stop reading immediately\n"
1486 " A Again (repeats last message)\n"
1487 " N Next (continue with next message)\n"
1488 " Y My Next (continue with next message you authored)\n"
1489 " B Back (go back to previous message)\n");
1491 || (room_flags & QR_MAILBOX)) {
1492 scr_printf(" D Delete this message\n"
1493 " M Move message to another room\n");
1495 scr_printf(" C Copy message to another room\n");
1496 if (strlen(printcmd) > 0)
1497 scr_printf(" P Print this message\n");
1499 " Q Quote portions of this message for your next post\n"
1500 " H Headers (display message headers only)\n");
1502 scr_printf(" R Reply to this message\n");
1503 if (rc_allow_attachments)
1505 (" F (save attachments to a file)\n");
1506 if (strlen(rc_url_cmd) > 0)
1507 scr_printf(" U (list URL's for display)\n");
1512 dest = fopen(prtfile, "w");
1514 hold_color = enable_color;
1519 dest = fopen(temp2, "w");
1521 hold_color = enable_color;
1533 newprompt("Enter target room: ",
1534 targ, ROOMNAMELEN - 1);
1535 if (strlen(targ) > 0) {
1536 r = CtdlIPCMoveMessage(ipc, (e == 'c' ? 1 : 0),
1537 msg_arr[a], targ, cmd);
1538 scr_printf("%s\n", cmd);
1544 if (r / 100 != 2) /* r will be init'ed, FIXME */
1545 goto RMSGREAD; /* the logic here sucks */
1548 newprompt("Which section? ", filename,
1549 ((sizeof filename) - 1));
1550 r = CtdlIPCAttachmentDownload(ipc, msg_arr[a],
1551 filename, &attachment, progress, cmd);
1552 extract(filename, cmd, 2);
1553 destination_directory(save_to, filename);
1554 r = CtdlIPCAttachmentDownload(ipc, msg_arr[a],
1555 filename, &attachment, progress, cmd);
1557 scr_printf("%s\n", cmd);
1559 save_buffer(attachment,
1560 extract_unsigned_long(cmd, 0),
1563 if (attachment) free(attachment);
1566 scr_printf("*** Delete this message? ");
1568 r = CtdlIPCDeleteMessage(ipc, msg_arr[a], cmd);
1569 scr_printf("%s\n", cmd);
1577 read_message(ipc, msg_arr[a], READ_HEADER, NULL);
1580 savedpos = num_msgs;
1581 entmsg(ipc, 1, (DEFAULT_ENTRY == 46 ? 2 : 0));
1582 num_msgs = savedpos;
1588 { /* hack hack hack */
1589 /* find the next message by me, stay here if we find nothing */
1592 for (finda = a; ((finda < num_msgs) && (finda >= 0)); finda += rdir)
1594 /* This is repetitively dumb, but that's what computers are for.
1595 We have to load up messages until we find one by us */
1599 snprintf(buf, sizeof buf, "MSG0 %ld|1", msg_arr[finda]); /* read the header so we can get 'from=' */
1600 CtdlIPC_putline(ipc, buf);
1601 CtdlIPC_getline(ipc, buf);
1602 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000"))
1604 if ((!strncasecmp(buf, "from=", 5)) && (finda != a)) /* Skip current message. */
1606 if (strcasecmp(buf+5, fullname) == 0)
1608 a = lasta; /* meesa current */
1613 // we are now in synch with the server
1616 lasta = finda; /* keep one behind or we skip on the reentrance to the for */
1620 } /* end for loop */
1621 } /* end read routine */
1627 * View and edit a system message
1629 void edit_system_message(CtdlIPC *ipc, char *which_message)
1633 char write_cmd[SIZ];
1635 snprintf(desc, sizeof desc, "system message '%s'", which_message);
1636 snprintf(read_cmd, sizeof read_cmd, "MESG %s", which_message);
1637 snprintf(write_cmd, sizeof write_cmd, "EMSG %s", which_message);
1638 do_edit(ipc, desc, read_cmd, "NOOP", write_cmd);
1645 * Verify the message base
1647 void check_message_base(CtdlIPC *ipc)
1652 ("Please read the documentation before running this command.\n"
1653 "Having done so, do you still want to check the message base? ");
1657 CtdlIPC_putline(ipc, "FSCK");
1658 CtdlIPC_getline(ipc, buf);
1659 if (buf[0] != '1') {
1660 scr_printf("%s\n", &buf[4]);
1664 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
1665 scr_printf("%s\n", buf);