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_decls.h"
41 #include "citadel_ipc.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 int checkpagin(int lp, int pagin, int height);
61 void getline(char *string, int lim);
62 void formout(char *name);
64 void newprompt(char *prompt, char *str, int len);
65 int file_checksum(char *filename);
66 void do_edit(char *desc, char *read_cmd, char *check_cmd, char *write_cmd);
71 char rc_alt_semantics;
72 extern char room_name[];
73 extern unsigned room_flags;
74 extern long highest_msg_read;
75 extern struct CtdlServInfo serv_info;
78 extern int screenwidth;
79 extern int screenheight;
80 extern long maxmsgnum;
83 extern char is_room_aide;
84 extern char fullname[];
86 extern unsigned userflags;
87 extern char sigcaught;
88 extern char editor_path[];
89 extern char printcmd[];
90 extern int rc_allow_attachments;
91 extern int rc_display_message_numbers;
92 extern int rc_force_mail_prompts;
94 extern int editor_pid;
96 void ka_sigcatch(int signum)
99 signal(SIGALRM, ka_sigcatch);
105 * server keep-alive version of wait() (needed for external editor)
107 pid_t ka_wait(int *kstatus)
112 signal(SIGALRM, ka_sigcatch);
116 } while (errno == EINTR);
117 signal(SIGALRM, SIG_IGN);
124 * version of system() that uses ka_wait()
126 int ka_system(char *shc)
135 perror("Cannot fork");
137 return ((pid_t) childpid);
141 execlp("/bin/sh", "sh", "-c", shc, NULL);
147 waitpid = ka_wait(&retcode);
148 } while (waitpid != childpid);
158 * add a newline to the buffer...
160 void add_newline(struct cittext *textlist)
165 while (ptr->next != NULL)
168 while (ptr->text[strlen(ptr->text) - 1] == 32)
169 ptr->text[strlen(ptr->text) - 1] = 0;
170 /* strcat(ptr->text,"\n"); */
172 ptr->next = (struct cittext *)
173 malloc(sizeof(struct cittext));
176 strcpy(ptr->text, "");
181 * add a word to the buffer...
183 void add_word(struct cittext *textlist, char *wordbuf)
188 while (ptr->next != NULL)
191 if (3 + strlen(ptr->text) + strlen(wordbuf) > screenwidth) {
192 ptr->next = (struct cittext *)
193 malloc(sizeof(struct cittext));
196 strcpy(ptr->text, "");
199 strcat(ptr->text, wordbuf);
200 strcat(ptr->text, " ");
205 * begin editing of an opened file pointed to by fp
207 void citedit(FILE * fp)
209 int a, prev, finished, b, last_space;
211 struct cittext *textlist = NULL;
213 char wordbuf[MAXWORDBUF];
215 /* first, load the text into the buffer */
217 textlist = (struct cittext *) malloc(sizeof(struct cittext));
218 textlist->next = NULL;
219 strcpy(textlist->text, "");
223 while (a = getc(fp), a >= 0) {
225 if ((a == 32) || (a == 9) || (a == 13) || (a == 10)) {
226 add_word(textlist, wordbuf);
228 if ((prev == 13) || (prev == 10)) {
229 add_word(textlist, "\n");
230 add_newline(textlist);
231 add_word(textlist, "");
234 wordbuf[strlen(wordbuf) + 1] = 0;
235 wordbuf[strlen(wordbuf)] = a;
237 if (strlen(wordbuf) + 3 > screenwidth) {
238 add_word(textlist, wordbuf);
246 prev = (appending ? 13 : (-1));
258 /******* new ***********/
259 if ((a > 32) && (a < 127) && (prev == 13)) {
260 add_word(textlist, "\n");
263 /***********************/
265 if ((a == 32) && (prev == 13)) {
266 add_word(textlist, "\n");
267 add_newline(textlist);
271 if (strlen(wordbuf) > 0) {
272 wordbuf[strlen(wordbuf) - 1] = 0;
277 } else if (a == 23) {
279 wordbuf[strlen(wordbuf) - 1] = 0;
283 } while (strlen(wordbuf) && wordbuf[strlen(wordbuf) - 1] != ' ');
284 } else if (a == 13) {
286 if (strlen(wordbuf) == 0)
289 for (b = 0; b < strlen(wordbuf); ++b)
290 if (wordbuf[b] == 32) {
298 add_word(textlist, wordbuf);
303 wordbuf[strlen(wordbuf) + 1] = 0;
304 wordbuf[strlen(wordbuf)] = a;
306 if ((strlen(wordbuf) + 3) > screenwidth) {
308 for (b = 0; b < strlen(wordbuf); ++b)
309 if (wordbuf[b] == 32)
311 if (last_space >= 0) {
312 for (b = 0; b < strlen(wordbuf); ++b)
313 if (wordbuf[b] == 32) {
321 for (b = 0; b < strlen(wordbuf); ++b) {
326 scr_printf("\n%s", wordbuf);
328 add_word(textlist, wordbuf);
334 } while (finished == 0);
337 /* write the buffer back to disk */
339 for (ptr = textlist; ptr != NULL; ptr = ptr->next) {
340 fprintf(fp, "%s", ptr->text);
344 ftruncate(fileno(fp), ftell(fp));
346 /* and deallocate the memory we used */
347 while (textlist != NULL) {
348 ptr = textlist->next;
354 /* Read a message from the server
357 long num, /* message number */
358 char pagin, /* 0 = normal read, 1 = read with pagination, 2 = header */
359 FILE *dest) /* Destination file, NULL for screen */
366 struct ctdlipcmessage *message = NULL;
367 int r; /* IPC response code */
368 char *converted_text = NULL;
373 strcpy(reply_to, NO_REPLY_TO);
374 strcpy(reply_subject, "");
376 r = CtdlIPCGetSingleMessage(num, (pagin == READ_HEADER ? 1 : 0),
377 (can_do_msg4 ? 4 : 0),
380 err_printf("*** msg #%ld: %d %s\n", num, r, buf);
383 checkpagin(lines_printed, pagin, screenheight);
389 fprintf(dest, "\n ");
393 lines_printed = checkpagin(lines_printed, pagin, screenheight);
396 if (pagin == 1 && !dest) {
400 /* View headers only */
402 sprintf(buf, "nhdr=%s\nfrom=%s\ntype=%d\nmsgn=%s\n",
403 message->nhdr ? "yes" : "no",
404 message->author, message->type,
406 /* FIXME output buf */
407 if (strlen(message->subject)) {
408 sprintf(buf, "subj=%s\n", message->subject);
409 /* FIXME: output buf */
411 if (strlen(message->email)) {
412 sprintf(buf, "rfca=%s\n", message->email);
413 /* FIXME: output buf */
415 sprintf(buf, "hnod=%s\nroom=%s\nnode=%s\ntime=%s",
416 message->hnod, message->room,
418 asctime(localtime(&message->time)));
419 if (strlen(message->recipient)) {
420 sprintf(buf, "rcpt=%s\n", message->recipient);
421 /* FIXME: output buf */
423 if (message->attachments) {
426 for (ptr = message->attachments; ptr; ptr = ptr->next) {
427 sprintf(buf, "part=%s|%s|%s|%s|%s|%ld\n",
428 ptr->name, ptr->filename, ptr->number,
429 ptr->disposition, ptr->mimetype,
431 /* FIXME: output buf */
438 if (rc_display_message_numbers) {
440 fprintf(dest, "[#%s] ", message->msgid);
445 scr_printf("#%s", message->msgid);
450 if (nhdr == 1 && !is_room_aide) {
452 fprintf(dest, " ****");
457 fmt_date(now, sizeof now, message->time, 0);
459 fprintf(dest, "%s from %s ", now, message->author);
460 if (strlen(message->email)) {
461 fprintf(dest, "<%s> ", message->email);
465 scr_printf("%s ", now);
469 scr_printf("%s ", message->author);
470 if (strlen(message->email)) {
474 scr_printf("%s", message->email);
479 if (strlen(message->node)) {
480 if ((room_flags & QR_NETWORK)
481 || ((strcasecmp(message->node, serv_info.serv_nodename)
482 && (strcasecmp(message->node, serv_info.serv_fqdn))))) {
483 if (strlen(message->email) == 0) {
485 fprintf(dest, "@%s ", message->node);
489 color(BRIGHT_YELLOW);
490 scr_printf("%s ", message->node);
495 if (strcasecmp(message->hnod, serv_info.serv_humannode)
496 && (strlen(message->hnod)) && (!strlen(message->email))) {
498 fprintf(dest, "(%s) ", message->hnod);
503 scr_printf("%s", message->hnod);
508 if (strcasecmp(message->room, room_name) && (strlen(message->email) == 0)) {
510 fprintf(dest, "in %s> ", message->room);
514 color(BRIGHT_MAGENTA);
515 scr_printf("%s> ", message->room);
518 if (strlen(message->recipient)) {
520 fprintf(dest, "to %s ", message->recipient);
525 scr_printf("%s ", message->recipient);
536 /* Set the reply-to address to an Internet e-mail address if possible
538 if (message->email != NULL) if (strlen(message->email) > 0) {
539 safestrncpy(reply_to, message->email, sizeof reply_to);
542 /* But if we can't do that, set it to a Citadel address.
544 if (!strcmp(reply_to, NO_REPLY_TO)) {
545 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
546 message->author, message->node);
549 if (pagin == 1 && !dest)
553 lines_printed = checkpagin(lines_printed, pagin, screenheight);
556 if (message->subject != NULL) {
557 safestrncpy(reply_subject, message->subject,
558 sizeof reply_subject);
559 if (strlen(message->subject) > 0) {
561 fprintf(dest, "Subject: %s\n",
564 scr_printf("Subject: %s\n", message->subject);
566 lines_printed = checkpagin(lines_printed,
567 pagin, screenheight);
572 /******* end of header output, start of message text output *******/
575 * Convert HTML to plain text, formatting for the actual width
576 * of the client screen.
578 if (!strcasecmp(message->content_type, "text/html")) {
579 converted_text = html_to_ascii(message->text, screenwidth, 0);
580 if (converted_text != NULL) {
582 message->text = converted_text;
590 if (format_type == 0) {
591 fr = fmout(screenwidth, NULL, message->text, dest,
592 ((pagin == 1) ? 1 : 0), screenheight, (-1), 1);
596 for (i = 0; i < num_tokens(message->text, '\n'); i++) {
597 if (sigcaught == 0) {
598 extract_token(buf, message->text, i, '\n');
600 fprintf(dest, "%s\n", buf);
602 scr_printf("%s\n", buf);
603 lines_printed = lines_printed + 1 +
604 (strlen(buf) / screenwidth);
606 checkpagin(lines_printed, pagin,
619 lines_printed = checkpagin(lines_printed, pagin, screenheight);
624 if (pagin == 1 && !dest)
631 * replace string function for the built-in editor
633 void replace_string(char *filename, long int startpos)
642 int substitutions = 0;
645 scr_printf("Enter text to be replaced:\n: ");
646 getline(srch_str, (sizeof(srch_str)-1) );
647 if (strlen(srch_str) == 0)
650 scr_printf("Enter text to replace it with:\n: ");
651 getline(rplc_str, (sizeof(rplc_str)-1) );
653 fp = fopen(filename, "r+");
658 fseek(fp, startpos, 0);
660 while (a = getc(fp), a > 0) {
662 buf[strlen(buf) + 1] = 0;
663 buf[strlen(buf)] = a;
664 if (strlen(buf) >= strlen(srch_str)) {
665 ptr = (&buf[strlen(buf) - strlen(srch_str)]);
666 if (!strncmp(ptr, srch_str, strlen(srch_str))) {
667 strcpy(ptr, rplc_str);
671 if (strlen(buf) > 384) {
674 fwrite((char *) buf, 128, 1, fp);
675 strcpy(buf, &buf[128]);
682 fwrite((char *) buf, strlen(buf), 1, fp);
685 truncate(filename, wpos);
686 scr_printf("<R>eplace made %d substitution(s).\n\n", substitutions);
690 * Function to begin composing a new message
692 int client_make_message(char *filename, /* temporary file name */
693 char *recipient, /* NULL if it's not mail */
694 int anon_type, /* see MES_ types in header file */
697 char *subject) /* buffer to store subject line */
707 if (strlen(editor_path) == 0) {
709 ("*** No editor available, using built-in editor\n");
713 fmt_date(datestr, sizeof datestr, time(NULL), 0);
716 if (room_flags & QR_ANONONLY && !recipient) {
717 snprintf(header, sizeof header, " ****");
720 snprintf(header, sizeof header,
721 " %s from %s", datestr, fullname);
722 if (strlen(recipient) > 0) {
723 size_t tmp = strlen(header);
724 snprintf(&header[tmp], sizeof header - tmp,
725 " to %s", recipient);
728 scr_printf("%s\n", header);
729 if (subject != NULL) if (strlen(subject) > 0) {
730 scr_printf("Subject: %s\n", subject);
736 scr_printf("(Press ctrl-d when finished)\n");
740 fp = fopen(filename, "r");
742 fmout(screenwidth, fp, NULL, NULL, 0, screenheight, 0, 0);
746 fp = fopen(filename, "w");
748 err_printf("*** Error opening temp file!\n"
750 filename, strerror(errno));
760 fp = fopen(filename, "r+");
762 err_printf("*** Error opening temp file!\n"
764 filename, strerror(errno));
772 fp = fopen(filename, "a");
774 err_printf("*** Error opening temp file!\n"
776 filename, strerror(errno));
796 e_ex_code = 1; /* start with a failed exit code */
798 cksum = file_checksum(filename);
799 if (editor_pid == 0) {
802 chmod(filename, 0600);
805 snprintf(tmp, sizeof tmp, "WINDOW_TITLE=%s", header);
807 execlp(editor_path, editor_path, filename, NULL);
813 b = ka_wait(&e_ex_code);
814 } while ((b != editor_pid) && (b >= 0));
821 MECR: if (mode == 2) {
822 if (file_checksum(filename) == cksum) {
823 err_printf("*** Aborted message.\n");
831 b = keymenu("Entry command (? for options)",
832 "<A>bort|<C>ontinue|<S>ave message|<P>rint formatted|"
834 "<R>eplace string|<H>old message");
843 scr_printf(" %s from %s", datestr, fullname);
844 if (strlen(recipient) > 0)
845 scr_printf(" to %s", recipient);
847 if (subject != NULL) if (strlen(subject) > 0) {
848 scr_printf("Subject: %s\n", subject);
850 fp = fopen(filename, "r");
852 fmout(screenwidth, fp, NULL, NULL,
853 ((userflags & US_PAGINATOR) ? 1 : 0),
861 replace_string(filename, 0L);
868 if (subject != NULL) {
869 newprompt("Subject: ", subject, 70);
876 MEABT: scr_printf("Are you sure? ");
880 MEABT2: unlink(filename);
885 * Transmit message text to the server.
887 * This loop also implements a "tick" counter that displays the progress, if
888 * we're sending something that will take a long time to transmit.
890 void transmit_message(FILE *fp)
897 fseek(fp, 0L, SEEK_END);
900 lasttick = time(NULL);
902 while (ch = getc(fp), (ch >= 0)) {
904 if (!strcmp(buf, "000"))
912 if ((ch == 32) && (strlen(buf) > 200)) {
914 if (!strcmp(buf, "000"))
919 if (strlen(buf) > 250) {
920 if (!strcmp(buf, "000"))
927 if ((time(NULL) - lasttick) > 2L) {
928 scr_printf(" %3ld%% completed\r",
929 ((ftell(fp) * 100L) / msglen));
931 lasttick = time(NULL);
941 * Make sure there's room in msg_arr[] for at least one more.
943 void check_msg_arr_size(void) {
944 if ((num_msgs + 1) > msg_arr_size) {
946 msg_arr = realloc(msg_arr,
947 ((sizeof(long)) * msg_arr_size) );
954 * entmsg() - edit and create a message
955 * returns 0 if message was saved
957 int entmsg(int is_reply, /* nonzero if this was a <R>eply command */
977 * First, check to see if we have permission to enter a message in
978 * this room. The server will return an error code if we can't.
980 snprintf(cmd, sizeof cmd, "ENT0 0||0|%d", mode);
984 if ((strncmp(cmd, "570", 3)) && (strncmp(cmd, "200", 3))) {
985 scr_printf("%s\n", &cmd[4]);
989 /* Error code 570 is special. It means that we CAN enter a message
990 * in this room, but a recipient needs to be specified.
993 if (!strncmp(cmd, "570", 3))
996 /* If the user is a dumbass, tell them how to type. */
997 if ((userflags & US_EXPERT) == 0) {
1001 /* Handle the selection of a recipient, if necessary. */
1003 if (need_recp == 1) {
1006 strcpy(buf, reply_to);
1008 scr_printf("Enter recipient: ");
1009 getline(buf, (SIZ-100) );
1010 if (strlen(buf) == 0)
1014 strcpy(buf, "sysop");
1018 if (strlen(reply_subject) > 0) {
1019 if (!strncasecmp(reply_subject,
1021 strcpy(subject, reply_subject);
1033 if (room_flags & QR_ANONOPT) {
1034 scr_printf("Anonymous (Y/N)? ");
1039 /* If it's mail, we've got to check the validity of the recipient... */
1040 if (strlen(buf) > 0) {
1041 snprintf(cmd, sizeof cmd, "ENT0 0|%s|%d|%d|%s", buf, b, mode, subject);
1044 if (cmd[0] != '2') {
1045 scr_printf("%s\n", &cmd[4]);
1050 /* Learn the number of the newest message in in the room, so we can
1051 * tell upon saving whether someone else has posted too.
1054 serv_puts("MSGS LAST|1");
1056 if (cmd[0] != '1') {
1057 scr_printf("%s\n", &cmd[5]);
1059 while (serv_gets(cmd), strcmp(cmd, "000")) {
1060 check_msg_arr_size();
1061 msg_arr[num_msgs++] = atol(cmd);
1065 /* Now compose the message... */
1066 if (client_make_message(temp, buf, b, 0, c, subject) != 0) {
1070 /* Reopen the temp file that was created, so we can send it */
1071 fp = fopen(temp, "r");
1073 /* Yes, unlink it now, so it doesn't stick around if we crash */
1077 err_printf("*** Internal error while trying to save message!\n"
1079 temp, strerror(errno));
1083 /* Transmit message to the server */
1084 snprintf(cmd, sizeof cmd, "ENT0 1|%s|%d|%d|%s|", buf, b, mode, subject);
1087 if (cmd[0] != '4') {
1088 scr_printf("%s\n", &cmd[4]);
1092 transmit_message(fp);
1097 if (num_msgs >= 1) highmsg = msg_arr[num_msgs - 1];
1099 serv_puts("MSGS NEW");
1101 if (cmd[0] != '1') {
1102 scr_printf("%s\n", &cmd[5]);
1104 while (serv_gets(cmd), strcmp(cmd, "000")) {
1105 check_msg_arr_size();
1106 msg_arr[num_msgs++] = atol(cmd);
1110 /* get new highest message number in room to set lrp for goto... */
1111 maxmsgnum = msg_arr[num_msgs - 1];
1113 /* now see if anyone else has posted in here */
1115 for (a = 0; a < num_msgs; ++a) {
1116 if (msg_arr[a] > highmsg) {
1121 /* In the Mail> room, this algorithm always counts one message
1122 * higher than in public rooms, so we decrement it by one.
1129 scr_printf("*** 1 additional message has been entered "
1130 "in this room by another user.\n");
1133 scr_printf("*** %d additional messages have been entered "
1134 "in this room by other users.\n", b);
1141 * Do editing on a quoted file
1143 void process_quote(void)
1145 FILE *qfile, *tfile;
1147 int line, qstart, qend;
1149 /* Unlink the second temp file as soon as it's opened, so it'll get
1150 * deleted even if the program dies
1152 qfile = fopen(temp2, "r");
1155 /* Display the quotable text with line numbers added */
1157 fgets(buf, 128, qfile);
1158 while (fgets(buf, 128, qfile) != NULL) {
1159 scr_printf("%2d %s", ++line, buf);
1161 scr_printf("Begin quoting at [ 1] : ");
1163 qstart = (buf[0] == 0) ? (1) : atoi(buf);
1164 scr_printf(" End quoting at [%d] : ", line);
1166 qend = (buf[0] == 0) ? (line) : atoi(buf);
1169 fgets(buf, 128, qfile);
1170 tfile = fopen(temp, "w");
1171 while (fgets(buf, 128, qfile) != NULL) {
1172 if ((++line >= qstart) && (line <= qend))
1173 fprintf(tfile, " >%s", buf);
1175 fprintf(tfile, " \n");
1184 * List the URL's which were embedded in the previous message
1191 if (num_urls == 0) {
1192 scr_printf("There were no URL's in the previous message.\n\n");
1196 for (i = 0; i < num_urls; ++i) {
1197 scr_printf("%3d %s\n", i + 1, urls[i]);
1200 if ((i = num_urls) != 1)
1201 i = intprompt("Display which one", 1, 1, num_urls);
1203 snprintf(cmd, sizeof cmd, rc_url_cmd, urls[i - 1]);
1209 * Read the messages in the current room
1212 int c, /* 0=Read all 1=Read new 2=Read old 3=Read last q */
1213 int rdir, /* 1=Forward (-1)=Reverse */
1214 int q /* Number of msgs to read (if c==3) */
1216 int a, b, e, f, g, start;
1222 char prtfile[PATH_MAX];
1225 char targ[ROOMNAMELEN];
1227 FILE *dest = NULL; /* Alternate destination other than screen */
1228 int r; /* IPC response code */
1235 strcpy(prtfile, tmpnam(NULL));
1238 strcpy(cmd, "MSGS ");
1250 snprintf(&cmd[5], sizeof cmd - 5, "LAST|%d", q);
1255 if (cmd[0] != '1') {
1256 scr_printf("%s\n", &cmd[5]);
1258 while (serv_gets(cmd), strcmp(cmd, "000")) {
1259 check_msg_arr_size();
1260 msg_arr[num_msgs++] = atol(cmd);
1264 if (num_msgs == 0) {
1266 scr_printf("*** There are no ");
1267 if (c == 1) scr_printf("new ");
1268 if (c == 2) scr_printf("old ");
1269 scr_printf("messages in this room.\n");
1275 /* this loop cycles through each message... */
1276 start = ((rdir == 1) ? 0 : (num_msgs - 1));
1277 for (a = start; ((a < num_msgs) && (a >= 0)); a = a + rdir) {
1278 while (msg_arr[a] == 0L) {
1280 if ((a == num_msgs) || (a == (-1)))
1284 RAGAIN: pagin = ((arcflag == 0)
1286 && (userflags & US_PAGINATOR)) ? 1 : 0;
1288 /* If we're doing a quote, set the screenwidth to 72 */
1290 hold_sw = screenwidth;
1294 /* If printing or archiving, set the screenwidth to 80 */
1296 hold_sw = screenwidth;
1300 /* now read the message... */
1301 e = read_message(msg_arr[a], pagin, dest);
1303 /* ...and set the screenwidth back if we have to */
1304 if ((quotflag) || (arcflag)) {
1305 screenwidth = hold_sw;
1307 RMSGREAD: scr_flush();
1308 highest_msg_read = msg_arr[a];
1313 enable_color = hold_color;
1320 enable_color = hold_color;
1323 freopen(prtfile, "r", stdin);
1325 sttybbs(SB_RESTORE);
1326 ka_system(printcmd);
1327 sttybbs(SB_NO_INTR);
1335 } while ((g != f) && (g >= 0));
1336 scr_printf("Message printed.\n");
1338 if (rc_alt_semantics && c == 1) {
1341 r = CtdlIPCSetMessageSeen(msg_arr[a], 1, buf);
1345 if (((userflags & US_NOPROMPT) || (e == 2))
1346 && (((room_flags & QR_MAILBOX) == 0)
1347 || (rc_force_mail_prompts == 0))) {
1352 color(BRIGHT_WHITE);
1353 scr_printf("%d", num_msgs - a - 1);
1357 keyopt("<B>ack <A>gain <Q>uote <R>eply <N>ext <S>top m<Y> next ");
1358 if (rc_url_cmd[0] && num_urls)
1359 keyopt("<U>RLview ");
1360 keyopt("<?>help -> ");
1364 e = (inkey() & 127);
1366 /* return key same as <N> */ if (e == 10)
1368 /* space key same as <N> */ if (e == 32)
1370 /* del/move for aides only */
1372 && ((room_flags & QR_MAILBOX) ==
1374 if ((e == 'd') || (e == 'm'))
1377 /* print only if available */
1378 if ((e == 'p') && (strlen(printcmd) == 0))
1380 /* can't file if not allowed */
1382 && (rc_allow_attachments == 0))
1384 /* link only if browser avail*/
1386 && (strlen(rc_url_cmd) == 0))
1388 } while ((e != 'a') && (e != 'n') && (e != 's')
1389 && (e != 'd') && (e != 'm') && (e != 'p')
1390 && (e != 'q') && (e != 'b') && (e != 'h')
1391 && (e != 'r') && (e != 'f') && (e != '?')
1392 && (e != 'u') && (e != 'c') && (e != 'y'));
1398 scr_printf("Again");
1401 scr_printf("Delete");
1413 scr_printf("Print");
1416 scr_printf("Quote");
1422 scr_printf("Header");
1425 scr_printf("Reply");
1431 scr_printf("URL's");
1434 scr_printf("mY next");
1437 scr_printf("? <help>");
1440 if (userflags & US_DISAPPEAR)
1441 scr_printf("\r%79s\r", "");
1448 scr_printf("Options available here:\n"
1449 " ? Help (prints this message)\n"
1450 " S Stop reading immediately\n"
1451 " A Again (repeats last message)\n"
1452 " N Next (continue with next message)\n"
1453 " Y My Next (continue with next message you authored)\n"
1454 " B Back (go back to previous message)\n");
1456 || (room_flags & QR_MAILBOX)) {
1457 scr_printf(" D Delete this message\n"
1458 " M Move message to another room\n");
1460 scr_printf(" C Copy message to another room\n");
1461 if (strlen(printcmd) > 0)
1462 scr_printf(" P Print this message\n");
1464 " Q Quote portions of this message for your next post\n"
1465 " H Headers (display message headers only)\n");
1467 scr_printf(" R Reply to this message\n");
1468 if (rc_allow_attachments)
1470 (" F (save attachments to a file)\n");
1471 if (strlen(rc_url_cmd) > 0)
1472 scr_printf(" U (list URL's for display)\n");
1477 dest = fopen(prtfile, "w");
1479 hold_color = enable_color;
1484 dest = fopen(temp2, "w");
1486 hold_color = enable_color;
1498 newprompt("Enter target room: ",
1499 targ, ROOMNAMELEN - 1);
1500 if (strlen(targ) > 0) {
1501 r = CtdlIPCMoveMessage((e == 'c' ? 1 : 0),
1502 msg_arr[a], targ, cmd);
1503 scr_printf("%s\n", cmd);
1509 if (r / 100 != 2) /* r will be init'ed, FIXME */
1510 goto RMSGREAD; /* the logic here sucks */
1513 newprompt("Which section? ", filename,
1514 ((sizeof filename) - 1));
1515 snprintf(cmd, sizeof cmd,
1516 "OPNA %ld|%s", msg_arr[a], filename);
1519 if (cmd[0] == '2') {
1520 extract(filename, &cmd[4], 2);
1521 download_to_local_disk(filename,
1522 extract_int(&cmd[4],
1525 scr_printf("%s\n", &cmd[4]);
1529 scr_printf("*** Delete this message? ");
1531 r = CtdlIPCDeleteMessage(msg_arr[a], cmd);
1532 scr_printf("%s\n", cmd);
1540 read_message(msg_arr[a], READ_HEADER, NULL);
1543 savedpos = num_msgs;
1544 entmsg(1, (DEFAULT_ENTRY == 46 ? 2 : 0));
1545 num_msgs = savedpos;
1551 { /* hack hack hack */
1552 /* find the next message by me, stay here if we find nothing */
1555 for (finda = a; ((finda < num_msgs) && (finda >= 0)); finda += rdir)
1557 /* This is repetitively dumb, but that's what computers are for.
1558 We have to load up messages until we find one by us */
1562 snprintf(buf, sizeof buf, "MSG0 %ld|1", msg_arr[finda]); /* read the header so we can get 'from=' */
1565 while (serv_gets(buf), strcmp(buf, "000"))
1567 if ((!strncasecmp(buf, "from=", 5)) && (finda != a)) /* Skip current message. */
1569 if (strcasecmp(buf+5, fullname) == 0)
1571 a = lasta; /* meesa current */
1576 // we are now in synch with the server
1579 lasta = finda; /* keep one behind or we skip on the reentrance to the for */
1583 } /* end for loop */
1584 } /* end read routine */
1590 * View and edit a system message
1592 void edit_system_message(char *which_message)
1598 snprintf(desc, sizeof desc, "system message '%s'", which_message);
1599 snprintf(read_cmd, sizeof read_cmd, "MESG %s", which_message);
1600 snprintf(write_cmd, sizeof write_cmd, "EMSG %s", which_message);
1601 do_edit(desc, read_cmd, "NOOP", write_cmd);
1608 * Verify the message base
1610 void check_message_base(void)
1615 ("Please read the documentation before running this command.\n"
1616 "Having done so, do you still want to check the message base? ");
1622 if (buf[0] != '1') {
1623 scr_printf("%s\n", &buf[4]);
1627 while (serv_gets(buf), strcmp(buf, "000")) {
1628 scr_printf("%s\n", buf);