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 do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd);
63 void progress(long int curr, long int cmax);
68 char rc_alt_semantics;
69 extern char room_name[];
70 extern unsigned room_flags;
71 extern long highest_msg_read;
72 extern struct CtdlServInfo serv_info;
75 extern int screenwidth;
76 extern int screenheight;
77 extern long maxmsgnum;
80 extern char is_room_aide;
81 extern char fullname[];
83 extern unsigned userflags;
84 extern char sigcaught;
85 extern char editor_path[];
86 extern char printcmd[];
87 extern int rc_allow_attachments;
88 extern int rc_display_message_numbers;
89 extern int rc_force_mail_prompts;
90 extern int editor_pid;
91 extern CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
93 void ka_sigcatch(int signum)
96 signal(SIGALRM, ka_sigcatch);
97 CtdlIPCNoop(ipc_for_signal_handlers);
102 * server keep-alive version of wait() (needed for external editor)
104 pid_t ka_wait(int *kstatus)
109 signal(SIGALRM, ka_sigcatch);
113 } while (errno == EINTR);
114 signal(SIGALRM, SIG_IGN);
121 * version of system() that uses ka_wait()
123 int ka_system(char *shc)
132 perror("Cannot fork");
134 return ((pid_t) childpid);
138 execlp("/bin/sh", "sh", "-c", shc, NULL);
144 waitpid = ka_wait(&retcode);
145 } while (waitpid != childpid);
155 * add a newline to the buffer...
157 void add_newline(struct cittext *textlist)
162 while (ptr->next != NULL)
165 while (ptr->text[strlen(ptr->text) - 1] == 32)
166 ptr->text[strlen(ptr->text) - 1] = 0;
167 /* strcat(ptr->text,"\n"); */
169 ptr->next = (struct cittext *)
170 malloc(sizeof(struct cittext));
173 strcpy(ptr->text, "");
178 * add a word to the buffer...
180 void add_word(struct cittext *textlist, char *wordbuf)
185 while (ptr->next != NULL)
188 if (3 + strlen(ptr->text) + strlen(wordbuf) > screenwidth) {
189 ptr->next = (struct cittext *)
190 malloc(sizeof(struct cittext));
193 strcpy(ptr->text, "");
196 strcat(ptr->text, wordbuf);
197 strcat(ptr->text, " ");
202 * begin editing of an opened file pointed to by fp
204 void citedit(CtdlIPC *ipc, FILE * fp)
206 int a, prev, finished, b, last_space;
208 struct cittext *textlist = NULL;
210 char wordbuf[MAXWORDBUF];
212 /* first, load the text into the buffer */
214 textlist = (struct cittext *) malloc(sizeof(struct cittext));
215 textlist->next = NULL;
216 strcpy(textlist->text, "");
220 while (a = getc(fp), a >= 0) {
222 if ((a == 32) || (a == 9) || (a == 13) || (a == 10)) {
223 add_word(textlist, wordbuf);
225 if ((prev == 13) || (prev == 10)) {
226 add_word(textlist, "\n");
227 add_newline(textlist);
228 add_word(textlist, "");
231 wordbuf[strlen(wordbuf) + 1] = 0;
232 wordbuf[strlen(wordbuf)] = a;
234 if (strlen(wordbuf) + 3 > screenwidth) {
235 add_word(textlist, wordbuf);
243 prev = (appending ? 13 : (-1));
255 /******* new ***********/
256 if ((a > 32) && (a < 127) && (prev == 13)) {
257 add_word(textlist, "\n");
260 /***********************/
262 if ((a == 32) && (prev == 13)) {
263 add_word(textlist, "\n");
264 add_newline(textlist);
268 if (strlen(wordbuf) > 0) {
269 wordbuf[strlen(wordbuf) - 1] = 0;
274 } else if (a == 23) {
276 wordbuf[strlen(wordbuf) - 1] = 0;
280 } while (strlen(wordbuf) && wordbuf[strlen(wordbuf) - 1] != ' ');
281 } else if (a == 13) {
283 if (strlen(wordbuf) == 0)
286 for (b = 0; b < strlen(wordbuf); ++b)
287 if (wordbuf[b] == 32) {
295 add_word(textlist, wordbuf);
300 wordbuf[strlen(wordbuf) + 1] = 0;
301 wordbuf[strlen(wordbuf)] = a;
303 if ((strlen(wordbuf) + 3) > screenwidth) {
305 for (b = 0; b < strlen(wordbuf); ++b)
306 if (wordbuf[b] == 32)
308 if (last_space >= 0) {
309 for (b = 0; b < strlen(wordbuf); ++b)
310 if (wordbuf[b] == 32) {
318 for (b = 0; b < strlen(wordbuf); ++b) {
323 scr_printf("\n%s", wordbuf);
325 add_word(textlist, wordbuf);
331 } while (finished == 0);
334 /* write the buffer back to disk */
336 for (ptr = textlist; ptr != NULL; ptr = ptr->next) {
337 fprintf(fp, "%s", ptr->text);
341 ftruncate(fileno(fp), ftell(fp));
343 /* and deallocate the memory we used */
344 while (textlist != NULL) {
345 ptr = textlist->next;
351 /* Read a message from the server
353 int read_message(CtdlIPC *ipc,
354 long num, /* message number */
355 char pagin, /* 0 = normal read, 1 = read with pagination, 2 = header */
356 FILE *dest) /* Destination file, NULL for screen */
363 struct ctdlipcmessage *message = NULL;
364 int r; /* IPC response code */
365 char *converted_text = NULL;
370 strcpy(reply_to, NO_REPLY_TO);
371 strcpy(reply_subject, "");
373 r = CtdlIPCGetSingleMessage(ipc, num, (pagin == READ_HEADER ? 1 : 0),
374 (can_do_msg4 ? 4 : 0),
377 err_printf("*** msg #%ld: %d %s\n", num, r, buf);
380 checkpagin(lines_printed, pagin, screenheight);
386 fprintf(dest, "\n ");
390 lines_printed = checkpagin(lines_printed, pagin, screenheight);
393 if (pagin == 1 && !dest) {
397 /* View headers only */
399 sprintf(buf, "nhdr=%s\nfrom=%s\ntype=%d\nmsgn=%s\n",
400 message->nhdr ? "yes" : "no",
401 message->author, message->type,
403 /* FIXME output buf */
404 if (strlen(message->subject)) {
405 sprintf(buf, "subj=%s\n", message->subject);
406 /* FIXME: output buf */
408 if (strlen(message->email)) {
409 sprintf(buf, "rfca=%s\n", message->email);
410 /* FIXME: output buf */
412 sprintf(buf, "hnod=%s\nroom=%s\nnode=%s\ntime=%s",
413 message->hnod, message->room,
415 asctime(localtime(&message->time)));
416 if (strlen(message->recipient)) {
417 sprintf(buf, "rcpt=%s\n", message->recipient);
418 /* FIXME: output buf */
420 if (message->attachments) {
423 for (ptr = message->attachments; ptr; ptr = ptr->next) {
424 sprintf(buf, "part=%s|%s|%s|%s|%s|%ld\n",
425 ptr->name, ptr->filename, ptr->number,
426 ptr->disposition, ptr->mimetype,
428 /* FIXME: output buf */
435 if (rc_display_message_numbers) {
437 fprintf(dest, "[#%s] ", message->msgid);
442 scr_printf("#%s", message->msgid);
447 if (nhdr == 1 && !is_room_aide) {
449 fprintf(dest, " ****");
454 fmt_date(now, sizeof now, message->time, 0);
456 fprintf(dest, "%s from %s ", now, message->author);
457 if (strlen(message->email)) {
458 fprintf(dest, "<%s> ", message->email);
462 scr_printf("%s ", now);
466 scr_printf("%s ", message->author);
467 if (strlen(message->email)) {
471 scr_printf("%s", message->email);
476 if (strlen(message->node)) {
477 if ((room_flags & QR_NETWORK)
478 || ((strcasecmp(message->node, serv_info.serv_nodename)
479 && (strcasecmp(message->node, serv_info.serv_fqdn))))) {
480 if (strlen(message->email) == 0) {
482 fprintf(dest, "@%s ", message->node);
486 color(BRIGHT_YELLOW);
487 scr_printf("%s ", message->node);
492 if (strcasecmp(message->hnod, serv_info.serv_humannode)
493 && (strlen(message->hnod)) && (!strlen(message->email))) {
495 fprintf(dest, "(%s) ", message->hnod);
500 scr_printf("%s", message->hnod);
505 if (strcasecmp(message->room, room_name) && (strlen(message->email) == 0)) {
507 fprintf(dest, "in %s> ", message->room);
511 color(BRIGHT_MAGENTA);
512 scr_printf("%s> ", message->room);
515 if (strlen(message->recipient)) {
517 fprintf(dest, "to %s ", message->recipient);
522 scr_printf("%s ", message->recipient);
533 /* Set the reply-to address to an Internet e-mail address if possible
535 if (message->email != NULL) if (strlen(message->email) > 0) {
536 safestrncpy(reply_to, message->email, sizeof reply_to);
539 /* But if we can't do that, set it to a Citadel address.
541 if (!strcmp(reply_to, NO_REPLY_TO)) {
542 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
543 message->author, message->node);
546 if (pagin == 1 && !dest)
550 lines_printed = checkpagin(lines_printed, pagin, screenheight);
553 if (message->subject != NULL) {
554 safestrncpy(reply_subject, message->subject,
555 sizeof reply_subject);
556 if (strlen(message->subject) > 0) {
558 fprintf(dest, "Subject: %s\n",
561 scr_printf("Subject: %s\n", message->subject);
563 lines_printed = checkpagin(lines_printed,
564 pagin, screenheight);
569 /******* end of header output, start of message text output *******/
572 * Convert HTML to plain text, formatting for the actual width
573 * of the client screen.
575 if (!strcasecmp(message->content_type, "text/html")) {
576 converted_text = html_to_ascii(message->text, screenwidth, 0);
577 if (converted_text != NULL) {
579 message->text = converted_text;
587 if (format_type == 0) {
588 fr = fmout(screenwidth, NULL, message->text, dest,
589 ((pagin == 1) ? 1 : 0), screenheight, (-1), 1);
594 msgtext = message->text;
596 while (lineptr = strtok(msgtext, "\n"), lineptr != NULL) {
599 if (sigcaught == 0) {
601 fprintf(dest, "%s\n", lineptr);
603 scr_printf("%s\n", lineptr);
604 lines_printed = lines_printed + 1 +
605 (strlen(lineptr) / screenwidth);
607 checkpagin(lines_printed, pagin,
620 lines_printed = checkpagin(lines_printed, pagin, screenheight);
623 /* Enumerate any attachments */
624 if ( (pagin == 1) && (can_do_msg4) && (message->attachments) ) {
627 for (ptr = message->attachments; ptr; ptr = ptr->next) {
628 if ( (!strcasecmp(ptr->disposition, "attachment"))
629 || (!strcasecmp(ptr->disposition, "inline"))) {
632 color(BRIGHT_MAGENTA);
633 scr_printf("%s", ptr->number);
637 scr_printf("%s", ptr->filename);
639 scr_printf(" (%s, %ld bytes)\n", ptr->mimetype, ptr->length);
648 if (pagin == 1 && !dest)
655 * replace string function for the built-in editor
657 void replace_string(char *filename, long int startpos)
666 int substitutions = 0;
669 scr_printf("Enter text to be replaced:\n: ");
670 getline(srch_str, (sizeof(srch_str)-1) );
671 if (strlen(srch_str) == 0)
674 scr_printf("Enter text to replace it with:\n: ");
675 getline(rplc_str, (sizeof(rplc_str)-1) );
677 fp = fopen(filename, "r+");
682 fseek(fp, startpos, 0);
684 while (a = getc(fp), a > 0) {
686 buf[strlen(buf) + 1] = 0;
687 buf[strlen(buf)] = a;
688 if (strlen(buf) >= strlen(srch_str)) {
689 ptr = (&buf[strlen(buf) - strlen(srch_str)]);
690 if (!strncmp(ptr, srch_str, strlen(srch_str))) {
691 strcpy(ptr, rplc_str);
695 if (strlen(buf) > 384) {
698 fwrite((char *) buf, 128, 1, fp);
699 strcpy(buf, &buf[128]);
706 fwrite((char *) buf, strlen(buf), 1, fp);
709 truncate(filename, wpos);
710 scr_printf("<R>eplace made %d substitution(s).\n\n", substitutions);
714 * Function to begin composing a new message
716 int client_make_message(CtdlIPC *ipc,
717 char *filename, /* temporary file name */
718 char *recipient, /* NULL if it's not mail */
719 int anon_type, /* see MES_ types in header file */
722 char *subject) /* buffer to store subject line */
732 if (strlen(editor_path) == 0) {
734 ("*** No editor available, using built-in editor\n");
738 fmt_date(datestr, sizeof datestr, time(NULL), 0);
741 if (room_flags & QR_ANONONLY && !recipient) {
742 snprintf(header, sizeof header, " ****");
745 snprintf(header, sizeof header,
746 " %s from %s", datestr, fullname);
747 if (strlen(recipient) > 0) {
748 size_t tmp = strlen(header);
749 snprintf(&header[tmp], sizeof header - tmp,
750 " to %s", recipient);
753 scr_printf("%s\n", header);
754 if (subject != NULL) if (strlen(subject) > 0) {
755 scr_printf("Subject: %s\n", subject);
761 scr_printf("(Press ctrl-d when finished)\n");
765 fp = fopen(filename, "r");
767 fmout(screenwidth, fp, NULL, NULL, 0, screenheight, 0, 0);
771 fp = fopen(filename, "w");
773 err_printf("*** Error opening temp file!\n"
775 filename, strerror(errno));
785 fp = fopen(filename, "r+");
787 err_printf("*** Error opening temp file!\n"
789 filename, strerror(errno));
797 fp = fopen(filename, "a");
799 err_printf("*** Error opening temp file!\n"
801 filename, strerror(errno));
821 e_ex_code = 1; /* start with a failed exit code */
823 cksum = file_checksum(filename);
824 if (editor_pid == 0) {
827 chmod(filename, 0600);
830 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", header);
832 execlp(editor_path, editor_path, filename, NULL);
838 b = ka_wait(&e_ex_code);
839 } while ((b != editor_pid) && (b >= 0));
846 MECR: if (mode == 2) {
847 if (file_checksum(filename) == cksum) {
848 err_printf("*** Aborted message.\n");
856 b = keymenu("Entry command (? for options)",
857 "<A>bort|<C>ontinue|<S>ave message|<P>rint formatted|"
859 "<R>eplace string|<H>old message");
868 scr_printf(" %s from %s", datestr, fullname);
869 if (strlen(recipient) > 0)
870 scr_printf(" to %s", recipient);
872 if (subject != NULL) if (strlen(subject) > 0) {
873 scr_printf("Subject: %s\n", subject);
875 fp = fopen(filename, "r");
877 fmout(screenwidth, fp, NULL, NULL,
878 ((userflags & US_PAGINATOR) ? 1 : 0),
886 replace_string(filename, 0L);
893 if (subject != NULL) {
894 newprompt("Subject: ", subject, 70);
901 MEABT: scr_printf("Are you sure? ");
905 MEABT2: unlink(filename);
910 * Transmit message text to the server.
912 * This loop also implements a "tick" counter that displays the progress, if
913 * we're sending something that will take a long time to transmit.
915 void transmit_message(CtdlIPC *ipc, FILE *fp)
922 fseek(fp, 0L, SEEK_END);
925 lasttick = time(NULL);
927 while (ch = getc(fp), (ch >= 0)) {
929 if (!strcmp(buf, "000"))
931 CtdlIPC_putline(ipc, buf);
937 if ((ch == 32) && (strlen(buf) > 200)) {
939 if (!strcmp(buf, "000"))
941 CtdlIPC_putline(ipc, buf);
944 if (strlen(buf) > 250) {
945 if (!strcmp(buf, "000"))
947 CtdlIPC_putline(ipc, buf);
952 if ((time(NULL) - lasttick) > 2L) {
953 scr_printf(" %3ld%% completed\r",
954 ((ftell(fp) * 100L) / msglen));
956 lasttick = time(NULL);
960 CtdlIPC_putline(ipc, buf);
966 * Make sure there's room in msg_arr[] for at least one more.
968 void check_msg_arr_size(void) {
969 if ((num_msgs + 1) > msg_arr_size) {
971 msg_arr = realloc(msg_arr,
972 ((sizeof(long)) * msg_arr_size) );
979 * entmsg() - edit and create a message
980 * returns 0 if message was saved
982 int entmsg(CtdlIPC *ipc,
983 int is_reply, /* nonzero if this was a <R>eply command */
1000 strcpy(subject, "");
1003 * First, check to see if we have permission to enter a message in
1004 * this room. The server will return an error code if we can't.
1006 snprintf(cmd, sizeof cmd, "ENT0 0||0|%d", mode);
1007 CtdlIPC_putline(ipc, cmd);
1008 CtdlIPC_getline(ipc, cmd);
1010 if ((strncmp(cmd, "570", 3)) && (strncmp(cmd, "200", 3))) {
1011 scr_printf("%s\n", &cmd[4]);
1015 /* Error code 570 is special. It means that we CAN enter a message
1016 * in this room, but a recipient needs to be specified.
1019 if (!strncmp(cmd, "570", 3))
1022 /* If the user is a dumbass, tell them how to type. */
1023 if ((userflags & US_EXPERT) == 0) {
1024 formout(ipc, "entermsg");
1027 /* Handle the selection of a recipient, if necessary. */
1029 if (need_recp == 1) {
1032 strcpy(buf, reply_to);
1034 scr_printf("Enter recipient: ");
1035 getline(buf, (SIZ-100) );
1036 if (strlen(buf) == 0)
1040 strcpy(buf, "sysop");
1044 if (strlen(reply_subject) > 0) {
1045 if (!strncasecmp(reply_subject,
1047 strcpy(subject, reply_subject);
1059 if (room_flags & QR_ANONOPT) {
1060 scr_printf("Anonymous (Y/N)? ");
1065 /* If it's mail, we've got to check the validity of the recipient... */
1066 if (strlen(buf) > 0) {
1067 snprintf(cmd, sizeof cmd, "ENT0 0|%s|%d|%d|%s", buf, b, mode, subject);
1068 CtdlIPC_putline(ipc, cmd);
1069 CtdlIPC_getline(ipc, cmd);
1070 if (cmd[0] != '2') {
1071 scr_printf("%s\n", &cmd[4]);
1076 /* Learn the number of the newest message in in the room, so we can
1077 * tell upon saving whether someone else has posted too.
1080 CtdlIPC_putline(ipc, "MSGS LAST|1");
1081 CtdlIPC_getline(ipc, cmd);
1082 if (cmd[0] != '1') {
1083 scr_printf("%s\n", &cmd[5]);
1085 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1086 check_msg_arr_size();
1087 msg_arr[num_msgs++] = atol(cmd);
1091 /* Now compose the message... */
1092 if (client_make_message(ipc, temp, buf, b, 0, c, subject) != 0) {
1096 /* Reopen the temp file that was created, so we can send it */
1097 fp = fopen(temp, "r");
1099 /* Yes, unlink it now, so it doesn't stick around if we crash */
1103 err_printf("*** Internal error while trying to save message!\n"
1105 temp, strerror(errno));
1109 /* Transmit message to the server */
1110 snprintf(cmd, sizeof cmd, "ENT0 1|%s|%d|%d|%s|", buf, b, mode, subject);
1111 CtdlIPC_putline(ipc, cmd);
1112 CtdlIPC_getline(ipc, cmd);
1113 if (cmd[0] != '4') {
1114 scr_printf("%s\n", &cmd[4]);
1118 transmit_message(ipc, fp);
1119 CtdlIPC_putline(ipc, "000");
1123 if (num_msgs >= 1) highmsg = msg_arr[num_msgs - 1];
1125 CtdlIPC_putline(ipc, "MSGS NEW");
1126 CtdlIPC_getline(ipc, cmd);
1127 if (cmd[0] != '1') {
1128 scr_printf("%s\n", &cmd[5]);
1130 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1131 check_msg_arr_size();
1132 msg_arr[num_msgs++] = atol(cmd);
1136 /* get new highest message number in room to set lrp for goto... */
1137 maxmsgnum = msg_arr[num_msgs - 1];
1139 /* now see if anyone else has posted in here */
1141 for (a = 0; a < num_msgs; ++a) {
1142 if (msg_arr[a] > highmsg) {
1147 /* In the Mail> room, this algorithm always counts one message
1148 * higher than in public rooms, so we decrement it by one.
1155 scr_printf("*** 1 additional message has been entered "
1156 "in this room by another user.\n");
1159 scr_printf("*** %d additional messages have been entered "
1160 "in this room by other users.\n", b);
1167 * Do editing on a quoted file
1169 void process_quote(void)
1171 FILE *qfile, *tfile;
1173 int line, qstart, qend;
1175 /* Unlink the second temp file as soon as it's opened, so it'll get
1176 * deleted even if the program dies
1178 qfile = fopen(temp2, "r");
1181 /* Display the quotable text with line numbers added */
1183 fgets(buf, 128, qfile);
1184 while (fgets(buf, 128, qfile) != NULL) {
1185 scr_printf("%2d %s", ++line, buf);
1187 scr_printf("Begin quoting at [ 1] : ");
1189 qstart = (buf[0] == 0) ? (1) : atoi(buf);
1190 scr_printf(" End quoting at [%d] : ", line);
1192 qend = (buf[0] == 0) ? (line) : atoi(buf);
1195 fgets(buf, 128, qfile);
1196 tfile = fopen(temp, "w");
1197 while (fgets(buf, 128, qfile) != NULL) {
1198 if ((++line >= qstart) && (line <= qend))
1199 fprintf(tfile, " >%s", buf);
1201 fprintf(tfile, " \n");
1210 * List the URL's which were embedded in the previous message
1212 void list_urls(CtdlIPC *ipc)
1217 if (num_urls == 0) {
1218 scr_printf("There were no URL's in the previous message.\n\n");
1222 for (i = 0; i < num_urls; ++i) {
1223 scr_printf("%3d %s\n", i + 1, urls[i]);
1226 if ((i = num_urls) != 1)
1227 i = intprompt("Display which one", 1, 1, num_urls);
1229 snprintf(cmd, sizeof cmd, rc_url_cmd, urls[i - 1]);
1235 * Read the messages in the current room
1237 void readmsgs(CtdlIPC *ipc,
1238 int c, /* 0=Read all 1=Read new 2=Read old 3=Read last q */
1239 int rdir, /* 1=Forward (-1)=Reverse */
1240 int q /* Number of msgs to read (if c==3) */
1242 int a, b, e, f, g, start;
1248 char prtfile[PATH_MAX];
1251 char targ[ROOMNAMELEN];
1252 char filename[PATH_MAX];
1253 char save_to[PATH_MAX];
1254 void *attachment = NULL; /* Downloaded attachment */
1255 FILE *dest = NULL; /* Alternate destination other than screen */
1256 int r; /* IPC response code */
1263 strcpy(prtfile, tmpnam(NULL));
1266 strcpy(cmd, "MSGS ");
1278 snprintf(&cmd[5], sizeof cmd - 5, "LAST|%d", q);
1281 CtdlIPC_putline(ipc, cmd);
1282 CtdlIPC_getline(ipc, cmd);
1283 if (cmd[0] != '1') {
1284 scr_printf("%s\n", &cmd[5]);
1286 while (CtdlIPC_getline(ipc, cmd), strcmp(cmd, "000")) {
1287 check_msg_arr_size();
1288 msg_arr[num_msgs++] = atol(cmd);
1292 if (num_msgs == 0) {
1294 scr_printf("*** There are no ");
1295 if (c == 1) scr_printf("new ");
1296 if (c == 2) scr_printf("old ");
1297 scr_printf("messages in this room.\n");
1303 /* this loop cycles through each message... */
1304 start = ((rdir == 1) ? 0 : (num_msgs - 1));
1305 for (a = start; ((a < num_msgs) && (a >= 0)); a = a + rdir) {
1306 while (msg_arr[a] == 0L) {
1308 if ((a == num_msgs) || (a == (-1)))
1312 RAGAIN: pagin = ((arcflag == 0)
1314 && (userflags & US_PAGINATOR)) ? 1 : 0;
1316 /* If we're doing a quote, set the screenwidth to 72 */
1318 hold_sw = screenwidth;
1322 /* If printing or archiving, set the screenwidth to 80 */
1324 hold_sw = screenwidth;
1328 /* now read the message... */
1329 e = read_message(ipc, msg_arr[a], pagin, dest);
1331 /* ...and set the screenwidth back if we have to */
1332 if ((quotflag) || (arcflag)) {
1333 screenwidth = hold_sw;
1335 RMSGREAD: scr_flush();
1336 highest_msg_read = msg_arr[a];
1341 enable_color = hold_color;
1348 enable_color = hold_color;
1351 freopen(prtfile, "r", stdin);
1353 sttybbs(SB_RESTORE);
1354 ka_system(printcmd);
1355 sttybbs(SB_NO_INTR);
1363 } while ((g != f) && (g >= 0));
1364 scr_printf("Message printed.\n");
1366 if (rc_alt_semantics && c == 1) {
1369 r = CtdlIPCSetMessageSeen(ipc, msg_arr[a], 1, buf);
1373 if (((userflags & US_NOPROMPT) || (e == 2))
1374 && (((room_flags & QR_MAILBOX) == 0)
1375 || (rc_force_mail_prompts == 0))) {
1380 color(BRIGHT_WHITE);
1381 scr_printf("%d", num_msgs - a - 1);
1385 keyopt("<B>ack <A>gain <Q>uote <R>eply <N>ext <S>top m<Y> next ");
1386 if (rc_url_cmd[0] && num_urls)
1387 keyopt("<U>RLview ");
1388 keyopt("<?>help -> ");
1392 e = (inkey() & 127);
1394 /* return key same as <N> */ if (e == 10)
1396 /* space key same as <N> */ if (e == 32)
1398 /* del/move for aides only */
1400 && ((room_flags & QR_MAILBOX) ==
1402 if ((e == 'd') || (e == 'm'))
1405 /* print only if available */
1406 if ((e == 'p') && (strlen(printcmd) == 0))
1408 /* can't file if not allowed */
1410 && (rc_allow_attachments == 0))
1412 /* link only if browser avail*/
1414 && (strlen(rc_url_cmd) == 0))
1416 } while ((e != 'a') && (e != 'n') && (e != 's')
1417 && (e != 'd') && (e != 'm') && (e != 'p')
1418 && (e != 'q') && (e != 'b') && (e != 'h')
1419 && (e != 'r') && (e != 'f') && (e != '?')
1420 && (e != 'u') && (e != 'c') && (e != 'y'));
1426 scr_printf("Again");
1429 scr_printf("Delete");
1441 scr_printf("Print");
1444 scr_printf("Quote");
1450 scr_printf("Header");
1453 scr_printf("Reply");
1459 scr_printf("URL's");
1462 scr_printf("mY next");
1465 scr_printf("? <help>");
1468 if (userflags & US_DISAPPEAR)
1469 scr_printf("\r%79s\r", "");
1476 scr_printf("Options available here:\n"
1477 " ? Help (prints this message)\n"
1478 " S Stop reading immediately\n"
1479 " A Again (repeats last message)\n"
1480 " N Next (continue with next message)\n"
1481 " Y My Next (continue with next message you authored)\n"
1482 " B Back (go back to previous message)\n");
1484 || (room_flags & QR_MAILBOX)) {
1485 scr_printf(" D Delete this message\n"
1486 " M Move message to another room\n");
1488 scr_printf(" C Copy message to another room\n");
1489 if (strlen(printcmd) > 0)
1490 scr_printf(" P Print this message\n");
1492 " Q Quote portions of this message for your next post\n"
1493 " H Headers (display message headers only)\n");
1495 scr_printf(" R Reply to this message\n");
1496 if (rc_allow_attachments)
1498 (" F (save attachments to a file)\n");
1499 if (strlen(rc_url_cmd) > 0)
1500 scr_printf(" U (list URL's for display)\n");
1505 dest = fopen(prtfile, "w");
1507 hold_color = enable_color;
1512 dest = fopen(temp2, "w");
1514 hold_color = enable_color;
1526 newprompt("Enter target room: ",
1527 targ, ROOMNAMELEN - 1);
1528 if (strlen(targ) > 0) {
1529 r = CtdlIPCMoveMessage(ipc, (e == 'c' ? 1 : 0),
1530 msg_arr[a], targ, cmd);
1531 scr_printf("%s\n", cmd);
1537 if (r / 100 != 2) /* r will be init'ed, FIXME */
1538 goto RMSGREAD; /* the logic here sucks */
1541 newprompt("Which section? ", filename,
1542 ((sizeof filename) - 1));
1543 r = CtdlIPCAttachmentDownload(ipc, msg_arr[a],
1544 filename, &attachment, progress, cmd);
1545 extract(filename, cmd, 2);
1546 destination_directory(save_to, filename);
1547 r = CtdlIPCAttachmentDownload(ipc, msg_arr[a],
1548 filename, &attachment, progress, cmd);
1550 scr_printf("%s\n", cmd);
1552 save_buffer(attachment,
1553 extract_long(cmd, 0),
1556 if (attachment) free(attachment);
1559 scr_printf("*** Delete this message? ");
1561 r = CtdlIPCDeleteMessage(ipc, msg_arr[a], cmd);
1562 scr_printf("%s\n", cmd);
1570 read_message(ipc, msg_arr[a], READ_HEADER, NULL);
1573 savedpos = num_msgs;
1574 entmsg(ipc, 1, (DEFAULT_ENTRY == 46 ? 2 : 0));
1575 num_msgs = savedpos;
1581 { /* hack hack hack */
1582 /* find the next message by me, stay here if we find nothing */
1585 for (finda = a; ((finda < num_msgs) && (finda >= 0)); finda += rdir)
1587 /* This is repetitively dumb, but that's what computers are for.
1588 We have to load up messages until we find one by us */
1592 snprintf(buf, sizeof buf, "MSG0 %ld|1", msg_arr[finda]); /* read the header so we can get 'from=' */
1593 CtdlIPC_putline(ipc, buf);
1594 CtdlIPC_getline(ipc, buf);
1595 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000"))
1597 if ((!strncasecmp(buf, "from=", 5)) && (finda != a)) /* Skip current message. */
1599 if (strcasecmp(buf+5, fullname) == 0)
1601 a = lasta; /* meesa current */
1606 // we are now in synch with the server
1609 lasta = finda; /* keep one behind or we skip on the reentrance to the for */
1613 } /* end for loop */
1614 } /* end read routine */
1620 * View and edit a system message
1622 void edit_system_message(char *which_message)
1628 snprintf(desc, sizeof desc, "system message '%s'", which_message);
1629 snprintf(read_cmd, sizeof read_cmd, "MESG %s", which_message);
1630 snprintf(write_cmd, sizeof write_cmd, "EMSG %s", which_message);
1631 do_edit(desc, read_cmd, "NOOP", write_cmd);
1638 * Verify the message base
1640 void check_message_base(CtdlIPC *ipc)
1645 ("Please read the documentation before running this command.\n"
1646 "Having done so, do you still want to check the message base? ");
1650 CtdlIPC_putline(ipc, "FSCK");
1651 CtdlIPC_getline(ipc, buf);
1652 if (buf[0] != '1') {
1653 scr_printf("%s\n", &buf[4]);
1657 while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000")) {
1658 scr_printf("%s\n", buf);