]> code.citadel.org Git - citadel.git/blob - citadel/messages.c
* Added client and server side support for entering Subject lines in
[citadel.git] / citadel / messages.c
1 /*
2  * $Id$
3  *
4  * Citadel/UX message support routines
5  * see copyright.txt for copyright information
6  */
7
8 #include "sysdep.h"
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <sys/types.h>
12 #include <fcntl.h>
13 #include <stdio.h>
14 #include <ctype.h>
15 #include <string.h>
16 #include <signal.h>
17 #include <errno.h>
18 #include <limits.h>
19 #include <sys/wait.h>
20 #include <sys/stat.h>
21
22 #if TIME_WITH_SYS_TIME
23 # include <sys/time.h>
24 # include <time.h>
25 #else
26 # if HAVE_SYS_TIME_H
27 #  include <sys/time.h>
28 # else
29 #  include <time.h>
30 # endif
31 #endif
32
33 #include <stdarg.h>
34 #include "citadel.h"
35 #include "messages.h"
36 #include "commands.h"
37 #include "rooms.h"
38 #include "tools.h"
39 #ifndef HAVE_SNPRINTF
40 #include "snprintf.h"
41 #endif
42 #include "screen.h"
43
44 #define MAXWORDBUF SIZ
45 #define MAXMSGS 512
46
47 struct cittext {
48         struct cittext *next;
49         char text[MAXWORDBUF];
50 };
51
52 void sttybbs(int cmd);
53 int haschar(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);
57 int yesno(void);
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);
61
62 char reply_to[512];
63 long msg_arr[MAXMSGS];
64 int num_msgs;
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;
70 extern char temp[];
71 extern char temp2[];
72 extern int screenwidth;
73 extern int screenheight;
74 extern long maxmsgnum;
75 extern char is_mail;
76 extern char is_aide;
77 extern char is_room_aide;
78 extern char fullname[];
79 extern char axlevel;
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;
87
88 extern int editor_pid;
89
90 void ka_sigcatch(int signum)
91 {
92         char buf[SIZ];
93         alarm(S_KEEPALIVE);
94         signal(SIGALRM, ka_sigcatch);
95         serv_puts("NOOP");
96         serv_gets(buf);
97 }
98
99
100 /*
101  * server keep-alive version of wait() (needed for external editor)
102  */
103 pid_t ka_wait(int *kstatus)
104 {
105         pid_t p;
106
107         alarm(S_KEEPALIVE);
108         signal(SIGALRM, ka_sigcatch);
109         do {
110                 errno = 0;
111                 p = wait(kstatus);
112         } while (errno == EINTR);
113         signal(SIGALRM, SIG_IGN);
114         alarm(0);
115         return (p);
116 }
117
118
119 /*
120  * version of system() that uses ka_wait()
121  */
122 int ka_system(char *shc)
123 {
124         pid_t childpid;
125         pid_t waitpid;
126         int retcode;
127
128         childpid = fork();
129         if (childpid < 0) {
130                 color(BRIGHT_RED);
131                 perror("Cannot fork");
132                 color(DIM_WHITE);
133                 return ((pid_t) childpid);
134         }
135
136         if (childpid == 0) {
137                 execlp("/bin/sh", "sh", "-c", shc, NULL);
138                 exit(127);
139         }
140
141         if (childpid > 0) {
142                 do {
143                         waitpid = ka_wait(&retcode);
144                 } while (waitpid != childpid);
145                 return (retcode);
146         }
147
148         return (-1);
149 }
150
151
152
153 /*
154  * add a newline to the buffer...
155  */
156 void add_newline(struct cittext *textlist)
157 {
158         struct cittext *ptr;
159
160         ptr = textlist;
161         while (ptr->next != NULL)
162                 ptr = ptr->next;
163
164         while (ptr->text[strlen(ptr->text) - 1] == 32)
165                 ptr->text[strlen(ptr->text) - 1] = 0;
166         /* strcat(ptr->text,"\n"); */
167
168         ptr->next = (struct cittext *)
169             malloc(sizeof(struct cittext));
170         ptr = ptr->next;
171         ptr->next = NULL;
172         strcpy(ptr->text, "");
173 }
174
175
176 /*
177  * add a word to the buffer...
178  */
179 void add_word(struct cittext *textlist, char *wordbuf)
180 {
181         struct cittext *ptr;
182
183         ptr = textlist;
184         while (ptr->next != NULL)
185                 ptr = ptr->next;
186
187         if (3 + strlen(ptr->text) + strlen(wordbuf) > screenwidth) {
188                 ptr->next = (struct cittext *)
189                     malloc(sizeof(struct cittext));
190                 ptr = ptr->next;
191                 ptr->next = NULL;
192                 strcpy(ptr->text, "");
193         }
194
195         strcat(ptr->text, wordbuf);
196         strcat(ptr->text, " ");
197 }
198
199
200 /*
201  * begin editing of an opened file pointed to by fp
202  */
203 void citedit(FILE * fp)
204 {
205         int a, prev, finished, b, last_space;
206         int appending = 0;
207         struct cittext *textlist = NULL;
208         struct cittext *ptr;
209         char wordbuf[MAXWORDBUF];
210
211         /* first, load the text into the buffer */
212         fseek(fp, 0L, 0);
213         textlist = (struct cittext *) malloc(sizeof(struct cittext));
214         textlist->next = NULL;
215         strcpy(textlist->text, "");
216
217         strcpy(wordbuf, "");
218         prev = (-1);
219         while (a = getc(fp), a >= 0) {
220                 appending = 1;
221                 if ((a == 32) || (a == 9) || (a == 13) || (a == 10)) {
222                         add_word(textlist, wordbuf);
223                         strcpy(wordbuf, "");
224                         if ((prev == 13) || (prev == 10)) {
225                                 add_word(textlist, "\n");
226                                 add_newline(textlist);
227                                 add_word(textlist, "");
228                         }
229                 } else {
230                         wordbuf[strlen(wordbuf) + 1] = 0;
231                         wordbuf[strlen(wordbuf)] = a;
232                 }
233                 if (strlen(wordbuf) + 3 > screenwidth) {
234                         add_word(textlist, wordbuf);
235                         strcpy(wordbuf, "");
236                 }
237                 prev = a;
238         }
239
240         /* get text */
241         finished = 0;
242         prev = (appending ? 13 : (-1));
243         strcpy(wordbuf, "");
244         async_ka_start();
245         do {
246                 a = inkey();
247                 if (a == 10)
248                         a = 13;
249                 if (a == 9)
250                         a = 32;
251                 if (a == 127)
252                         a = 8;
253
254         /******* new ***********/
255                 if ((a > 32) && (a < 127) && (prev == 13)) {
256                         add_word(textlist, "\n");
257                         scr_printf(" ");
258                 }
259         /***********************/
260
261                 if ((a == 32) && (prev == 13)) {
262                         add_word(textlist, "\n");
263                         add_newline(textlist);
264                 }
265
266                 if (a == 8) {
267                         if (strlen(wordbuf) > 0) {
268                                 wordbuf[strlen(wordbuf) - 1] = 0;
269                                 scr_putc(8);
270                                 scr_putc(32);
271                                 scr_putc(8);
272                         }
273                 } else if (a == 13) {
274                         scr_printf("\n");
275                         if (strlen(wordbuf) == 0)
276                                 finished = 1;
277                         else {
278                                 for (b = 0; b < strlen(wordbuf); ++b)
279                                         if (wordbuf[b] == 32) {
280                                                 wordbuf[b] = 0;
281                                                 add_word(textlist,
282                                                          wordbuf);
283                                                 strcpy(wordbuf,
284                                                        &wordbuf[b + 1]);
285                                                 b = 0;
286                                         }
287                                 add_word(textlist, wordbuf);
288                                 strcpy(wordbuf, "");
289                         }
290                 } else {
291                         scr_putc(a);
292                         wordbuf[strlen(wordbuf) + 1] = 0;
293                         wordbuf[strlen(wordbuf)] = a;
294                 }
295                 if ((strlen(wordbuf) + 3) > screenwidth) {
296                         last_space = (-1);
297                         for (b = 0; b < strlen(wordbuf); ++b)
298                                 if (wordbuf[b] == 32)
299                                         last_space = b;
300                         if (last_space >= 0) {
301                                 for (b = 0; b < strlen(wordbuf); ++b)
302                                         if (wordbuf[b] == 32) {
303                                                 wordbuf[b] = 0;
304                                                 add_word(textlist,
305                                                          wordbuf);
306                                                 strcpy(wordbuf,
307                                                        &wordbuf[b + 1]);
308                                                 b = 0;
309                                         }
310                                 for (b = 0; b < strlen(wordbuf); ++b) {
311                                         scr_putc(8);
312                                         scr_putc(32);
313                                         scr_putc(8);
314                                 }
315                                 scr_printf("\n%s", wordbuf);
316                         } else {
317                                 add_word(textlist, wordbuf);
318                                 strcpy(wordbuf, "");
319                                 scr_printf("\n");
320                         }
321                 }
322                 prev = a;
323         } while (finished == 0);
324         async_ka_end();
325
326         /* write the buffer back to disk */
327         fseek(fp, 0L, 0);
328         for (ptr = textlist; ptr != NULL; ptr = ptr->next) {
329                 fprintf(fp, "%s", ptr->text);
330         }
331         putc(10, fp);
332         fflush(fp);
333         ftruncate(fileno(fp), ftell(fp));
334
335         /* and deallocate the memory we used */
336         while (textlist != NULL) {
337                 ptr = textlist->next;
338                 free(textlist);
339                 textlist = ptr;
340         }
341 }
342
343 /* Read a message from the server
344  */
345 int read_message(
346         long num,   /* message number */
347         char pagin, /* 0 = normal read, 1 = read with pagination, 2 = header */
348         FILE *dest) /* Destination file, NULL for screen */
349 {
350         char buf[SIZ];
351         char m_subject[SIZ];
352         char from[SIZ], node[SIZ], rfca[SIZ];
353         char now[SIZ];
354         int format_type = 0;
355         int fr = 0;
356         int nhdr = 0;
357
358         sigcaught = 0;
359         sttybbs(1);
360
361         sprintf(buf, "MSG0 %ld|%d", num, (pagin == READ_HEADER ? 1 : 0));
362         serv_puts(buf);
363         serv_gets(buf);
364         if (buf[0] != '1') {
365                 err_printf("*** msg #%ld: %s\n", num, buf);
366                 ++lines_printed;
367                 lines_printed =
368                     checkpagin(lines_printed, pagin, screenheight);
369                 sttybbs(0);
370                 return (0);
371         }
372
373         strcpy(m_subject, "");
374         strcpy(reply_to, "nobody ... xxxxx");
375         strcpy(from, "");
376         strcpy(node, "");
377         strcpy(rfca, "");
378
379         if (dest) {
380                 fprintf(dest, "\n ");
381         } else {
382                 scr_printf("\n");
383                 ++lines_printed;
384                 lines_printed = checkpagin(lines_printed, pagin, screenheight);
385                 scr_printf(" ");
386         }
387         if (pagin == 1 && !dest) {
388                 color(BRIGHT_CYAN);
389         }
390
391         if (pagin == 2) {
392                 while (serv_gets(buf), strcmp(buf, "000")) {
393                         if (buf[4] == '=') {
394                                 if (dest) {
395                                         fprintf(dest, "%s\n", buf);
396                                 } else {
397                                         scr_printf("%s\n", buf);
398                                         ++lines_printed;
399                                         lines_printed =
400                                                 checkpagin(lines_printed,
401                                                 pagin, screenheight);
402                                 }
403                         }
404                 }
405                 sttybbs(0);
406                 return (0);
407         }
408
409         while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
410                 if (!strncasecmp(buf, "nhdr=yes", 8))
411                         nhdr = 1;
412                 if (!strncasecmp(buf, "from=", 5)) {
413                         strcpy(from, &buf[5]);
414                 }
415                 if (nhdr == 1)
416                         buf[0] = '_';
417                 if (!strncasecmp(buf, "type=", 5))
418                         format_type = atoi(&buf[5]);
419                 if ((!strncasecmp(buf, "msgn=", 5))
420                     && (rc_display_message_numbers)) {
421                         if (dest) {
422                                 fprintf(dest, "[#%s] ", &buf[5]);
423                         } else {
424                                 color(DIM_WHITE);
425                                 scr_printf("[");
426                                 color(BRIGHT_WHITE);
427                                 scr_printf("#%s", &buf[5]);
428                                 color(DIM_WHITE);
429                                 scr_printf("] ");
430                         }
431                 }
432                 if (!strncasecmp(buf, "from=", 5)) {
433                         if (dest) {
434                                 fprintf(dest, "from %s ", &buf[5]);
435                         } else {
436                                 color(DIM_WHITE);
437                                 scr_printf("from ");
438                                 color(BRIGHT_CYAN);
439                                 scr_printf("%s ", &buf[5]);
440                         }
441                 }
442                 if (!strncasecmp(buf, "subj=", 5))
443                         strcpy(m_subject, &buf[5]);
444
445                 if (!strncasecmp(buf, "rfca=", 5)) {
446                         safestrncpy(rfca, &buf[5], sizeof(rfca) - 5);
447                         if (dest) {
448                                 fprintf(dest, "<%s> ", &buf[5]);
449                         } else {
450                                 color(DIM_WHITE);
451                                 scr_printf("<");
452                                 color(BRIGHT_BLUE);
453                                 scr_printf("%s", &buf[5]);
454                                 color(DIM_WHITE);
455                                 scr_printf("> ");
456                         }
457                 }
458                 if ((!strncasecmp(buf, "hnod=", 5))
459                     && (strcasecmp(&buf[5], serv_info.serv_humannode))
460                     && (strlen(rfca) == 0)) {
461                         if (dest) {
462                                 fprintf(dest, "(%s) ", &buf[5]);
463                         } else {
464                                 color(DIM_WHITE);
465                                 scr_printf("(");
466                                 color(BRIGHT_WHITE);
467                                 scr_printf("%s", &buf[5]);
468                                 color(DIM_WHITE);
469                                 scr_printf(") ");
470                         }
471                 }
472                 if ((!strncasecmp(buf, "room=", 5))
473                     && (strcasecmp(&buf[5], room_name))
474                     && (strlen(rfca) == 0)) {
475                         if (dest) {
476                                 fprintf(dest, "in %s> ", &buf[5]);
477                         } else {
478                                 color(DIM_WHITE);
479                                 scr_printf("in ");
480                                 color(BRIGHT_MAGENTA);
481                                 scr_printf("%s> ", &buf[5]);
482                         }
483                 }
484
485                 if (!strncasecmp(buf, "node=", 5)) {
486                         safestrncpy(node, &buf[5], sizeof(buf) - 5);
487                         if ((room_flags & QR_NETWORK)
488                             ||
489                             ((strcasecmp
490                               (&buf[5], serv_info.serv_nodename)
491                               &&
492                               (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
493                         {
494                                 if (strlen(rfca) == 0) {
495                                         if (dest) {
496                                                 fprintf(dest, "@%s ", &buf[5]);
497                                         } else {
498                                                 color(DIM_WHITE);
499                                                 scr_printf("@");
500                                                 color(BRIGHT_YELLOW);
501                                                 scr_printf("%s ", &buf[5]);
502                                         }
503                                 }
504                         }
505                 }
506
507                 if (!strncasecmp(buf, "rcpt=", 5)) {
508                         if (dest) {
509                                 fprintf(dest, "to %s ", &buf[5]);
510                         } else {
511                                 color(DIM_WHITE);
512                                 scr_printf("to ");
513                                 color(BRIGHT_CYAN);
514                                 scr_printf("%s ", &buf[5]);
515                         }
516                 }
517                 if (!strncasecmp(buf, "time=", 5)) {
518                         fmt_date(now, atol(&buf[5]), 0);
519                         if (dest) {
520                                 fprintf(dest, "%s ", now);
521                         } else {
522                                 scr_printf("%s ", now);
523                         }
524                 }
525         }
526
527         if (nhdr == 1) {
528                 if (!is_room_aide) {
529                         if (dest) {
530                                 fprintf(dest, " ****");
531                         } else {
532                                 scr_printf(" ****");
533                         }
534                 } else {
535                         if (dest) {
536                                 fprintf(dest, " %s", from);
537                         } else {
538                                 scr_printf(" %s", from);
539                         }
540                 }
541         }
542         if (dest) {
543                 fprintf(dest, "\n");
544         } else {
545                 scr_printf("\n");
546         }
547
548         if (strlen(rfca) > 0) {
549                 strcpy(reply_to, rfca);
550         } else {
551                 snprintf(reply_to, sizeof(reply_to), "%s @ %s", from,
552                          node);
553         }
554
555         if (pagin == 1 && !dest)
556                 color(BRIGHT_WHITE);
557         if (!dest) {
558                 ++lines_printed;
559                 lines_printed = checkpagin(lines_printed, pagin, screenheight);
560         }
561
562         if (strlen(m_subject) > 0) {
563                 if (dest) {
564                         fprintf(dest, "Subject: %s\n", m_subject);
565                 } else {
566                         scr_printf("Subject: %s\n", m_subject);
567                         ++lines_printed;
568                         lines_printed = checkpagin(lines_printed,
569                                         pagin, screenheight);
570                 }
571         }
572
573         if (format_type == 0) {
574                 fr = fmout(screenwidth, NULL, dest,
575                            ((pagin == 1) ? 1 : 0), screenheight, (-1), 1);
576         } else {
577                 while (serv_gets(buf), strcmp(buf, "000")) {
578                         if (sigcaught == 0) {
579                                 if (dest) {
580                                         fprintf(dest, "%s\n", buf);
581                                 } else {
582                                 scr_printf("%s\n", buf);
583                                         lines_printed = lines_printed + 1 +
584                                             (strlen(buf) / screenwidth);
585                                         lines_printed =
586                                             checkpagin(lines_printed, pagin,
587                                                        screenheight);
588                                 }
589                         }
590                 }
591                 fr = sigcaught;
592         }
593         if (dest) {
594                 fprintf(dest, "\n");
595         } else {
596                 scr_printf("\n");
597                 scr_flush();
598                 ++lines_printed;
599                 lines_printed = checkpagin(lines_printed, pagin, screenheight);
600         }
601
602         if (pagin == 1 && !dest)
603                 color(DIM_WHITE);
604         sttybbs(0);
605         return (fr);
606 }
607
608 /*
609  * replace string function for the built-in editor
610  */
611 void replace_string(char *filename, long int startpos)
612 {
613         char buf[512];
614         char srch_str[128];
615         char rplc_str[128];
616         FILE *fp;
617         int a;
618         long rpos, wpos;
619         char *ptr;
620         int substitutions = 0;
621         long msglen = 0L;
622
623         scr_printf("Enter text to be replaced:\n: ");
624         getline(srch_str, 128);
625         if (strlen(srch_str) == 0)
626                 return;
627
628         scr_printf("Enter text to replace it with:\n: ");
629         getline(rplc_str, 128);
630
631         fp = fopen(filename, "r+");
632         if (fp == NULL)
633                 return;
634
635         wpos = startpos;
636         fseek(fp, startpos, 0);
637         strcpy(buf, "");
638         while (a = getc(fp), a > 0) {
639                 ++msglen;
640                 buf[strlen(buf) + 1] = 0;
641                 buf[strlen(buf)] = a;
642                 if (strlen(buf) >= strlen(srch_str)) {
643                         ptr = (&buf[strlen(buf) - strlen(srch_str)]);
644                         if (!strncasecmp(ptr, srch_str, strlen(srch_str))) {
645                                 strcpy(ptr, rplc_str);
646                                 ++substitutions;
647                         }
648                 }
649                 if (strlen(buf) > 384) {
650                         rpos = ftell(fp);
651                         fseek(fp, wpos, 0);
652                         fwrite((char *) buf, 128, 1, fp);
653                         strcpy(buf, &buf[128]);
654                         wpos = ftell(fp);
655                         fseek(fp, rpos, 0);
656                 }
657         }
658         fseek(fp, wpos, 0);
659         if (strlen(buf) > 0)
660                 fwrite((char *) buf, strlen(buf), 1, fp);
661         wpos = ftell(fp);
662         fclose(fp);
663         truncate(filename, wpos);
664         scr_printf("<R>eplace made %d substitution(s).\n\n", substitutions);
665 }
666
667 /*
668  * Function to begin composing a new message
669  */
670 int client_make_message(char *filename, /* temporary file name */
671                 char *recipient,        /* NULL if it's not mail */
672                 int anon_type,          /* see MES_ types in header file */
673                 int format_type,
674                 int mode,
675                 char *subject)          /* buffer to store subject line */
676 {
677         FILE *fp;
678         int a, b, e_ex_code;
679         long beg;
680         char datestr[SIZ];
681         char header[SIZ];
682         int cksum = 0;
683
684         if (subject != NULL) strcpy(subject, "");
685
686         if (mode == 2)
687                 if (strlen(editor_path) == 0) {
688                         err_printf
689                             ("*** No editor available, using built-in editor\n");
690                         mode = 0;
691                 }
692
693         fmt_date(datestr, time(NULL), 0);
694         header[0] = 0;
695
696         if (room_flags & QR_ANONONLY && !recipient) {
697                 sprintf(&header[strlen(header)], " ****");
698         }
699         else {
700                 sprintf(&header[strlen(header)],
701                         " %s from %s", datestr, fullname);
702                 if (strlen(recipient) > 0) {
703                         sprintf(&header[strlen(header)],
704                                 " to %s", recipient);
705                 }
706         }
707         scr_printf("%s\n", header);
708
709         beg = 0L;
710
711         if (mode == 1) {
712                 scr_printf("(Press ctrl-d when finished)\n");
713         }
714
715         if (mode == 0) {
716                 fp = fopen(filename, "r");
717                 if (fp != NULL) {
718                         fmout(screenwidth, fp, NULL, 0, screenheight, 0, 0);
719                         beg = ftell(fp);
720                         fclose(fp);
721                 } else {
722                         fp = fopen(filename, "w");
723                         if (fp == NULL) {
724                                 err_printf("*** Error opening temp file!\n"
725                                         "    %s: %s\n",
726                                         filename, strerror(errno));
727                         return(1);
728                         }
729                         fclose(fp);
730                 }
731         }
732
733 ME1:    switch (mode) {
734
735         case 0:
736                 fp = fopen(filename, "r+");
737                 if (fp == NULL) {
738                         err_printf("*** Error opening temp file!\n"
739                                 "    %s: %s\n",
740                                 filename, strerror(errno));
741                         return(1);
742                 }
743                 citedit(fp);
744                 fclose(fp);
745                 goto MECR;
746
747         case 1:
748                 fp = fopen(filename, "a");
749                 if (fp == NULL) {
750                         err_printf("*** Error opening temp file!\n"
751                                 "    %s: %s\n",
752                                 filename, strerror(errno));
753                         return(1);
754                 }
755                 do {
756                         a = inkey();
757                         if (a == 255)
758                                 a = 32;
759                         if (a == 13)
760                                 a = 10;
761                         if (a != 4) {
762                                 putc(a, fp);
763                                 scr_putc(a);
764                         }
765                         if (a == 10)
766                                 scr_putc(10);
767                 } while (a != 4);
768                 fclose(fp);
769                 break;
770
771         case 2:
772                 e_ex_code = 1;  /* start with a failed exit code */
773                 editor_pid = fork();
774                 cksum = file_checksum(filename);
775                 if (editor_pid == 0) {
776                         chmod(filename, 0600);
777                         screen_reset();
778                         sttybbs(SB_RESTORE);
779                         setenv("WINDOW_TITLE", header, 1);
780                         execlp(editor_path, editor_path, filename, NULL);
781                         exit(1);
782                 }
783                 if (editor_pid > 0)
784                         do {
785                                 e_ex_code = 0;
786                                 b = ka_wait(&e_ex_code);
787                         } while ((b != editor_pid) && (b >= 0));
788                 editor_pid = (-1);
789                 sttybbs(0);
790                 screen_set();
791                 break;
792         }
793
794 MECR:   if (mode == 2) {
795                 if (file_checksum(filename) == cksum) {
796                         err_printf("*** Aborted message.\n");
797                         e_ex_code = 1;
798                 }
799                 if (e_ex_code == 0)
800                         goto MEFIN;
801                 goto MEABT2;
802         }
803
804         b = keymenu("Entry command (? for options)",
805                     "<A>bort|<C>ontinue|<S>ave message|<P>rint formatted|"
806                     "add s<U>bject|"
807                     "<R>eplace string|<H>old message");
808
809         if (b == 'a')
810                 goto MEABT;
811         if (b == 'c')
812                 goto ME1;
813         if (b == 's')
814                 goto MEFIN;
815         if (b == 'p') {
816                 scr_printf(" %s from %s", datestr, fullname);
817                 if (strlen(recipient) > 0)
818                         scr_printf(" to %s", recipient);
819                 scr_printf("\n");
820                 if (subject != NULL) if (strlen(subject) > 0) {
821                         scr_printf("Subject: %s\n", subject);
822                 }
823                 fp = fopen(filename, "r");
824                 if (fp != NULL) {
825                         fmout(screenwidth, fp, NULL,
826                               ((userflags & US_PAGINATOR) ? 1 : 0),
827                               screenheight, 0, 0);
828                         beg = ftell(fp);
829                         fclose(fp);
830                 }
831                 goto MECR;
832         }
833         if (b == 'r') {
834                 replace_string(filename, 0L);
835                 goto MECR;
836         }
837         if (b == 'h') {
838                 return (2);
839         }
840         if (b == 'u') {
841                 if (subject != NULL) {
842                         newprompt("Subject: ", subject, 70);
843                 }
844                 goto MECR;
845         }
846
847 MEFIN:  return (0);
848
849 MEABT:  scr_printf("Are you sure? ");
850         if (yesno() == 0) {
851                 goto ME1;
852         }
853 MEABT2: unlink(filename);
854         return (2);
855 }
856
857 /*
858  * Transmit message text to the server.
859  * 
860  * This loop also implements a "tick" counter that displays the progress, if
861  * we're sending something that will take a long time to transmit.
862  */
863 void transmit_message(FILE *fp)
864 {
865         char buf[SIZ];
866         int ch, a;
867         long msglen;
868         time_t lasttick;
869
870         fseek(fp, 0L, SEEK_END);
871         msglen = ftell(fp);
872         rewind(fp);
873         lasttick = time(NULL);
874         strcpy(buf, "");
875         while (ch = getc(fp), (ch >= 0)) {
876                 if (ch == 10) {
877                         if (!strcmp(buf, "000"))
878                                 strcpy(buf, ">000");
879                         serv_puts(buf);
880                         strcpy(buf, "");
881                 } else {
882                         a = strlen(buf);
883                         buf[a + 1] = 0;
884                         buf[a] = ch;
885                         if ((ch == 32) && (strlen(buf) > 200)) {
886                                 buf[a] = 0;
887                                 if (!strcmp(buf, "000"))
888                                         strcpy(buf, ">000");
889                                 serv_puts(buf);
890                                 strcpy(buf, "");
891                         }
892                         if (strlen(buf) > 250) {
893                                 if (!strcmp(buf, "000"))
894                                         strcpy(buf, ">000");
895                                 serv_puts(buf);
896                                 strcpy(buf, "");
897                         }
898                 }
899
900                 if ((time(NULL) - lasttick) > 2L) {
901                         scr_printf(" %3ld%% completed\r",
902                                ((ftell(fp) * 100L) / msglen));
903                         scr_flush();
904                         lasttick = time(NULL);
905                 }
906
907         }
908         serv_puts(buf);
909         scr_printf("                \r");
910         scr_flush();
911 }
912
913
914
915 /*
916  * entmsg()  -  edit and create a message
917  *              returns 0 if message was saved
918  */
919 int entmsg(int is_reply,        /* nonzero if this was a <R>eply command */
920                 int c)          /* */
921 {
922         char buf[300];
923         char cmd[SIZ];
924         int a, b;
925         int need_recp = 0;
926         int mode;
927         long highmsg;
928         FILE *fp;
929         char subject[SIZ];
930         
931         if (c > 0)
932                 mode = 1;
933         else
934                 mode = 0;
935
936         /*
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.
939          */
940         sprintf(cmd, "ENT0 0||0|%d", mode);
941         serv_puts(cmd);
942         serv_gets(cmd);
943
944         if ((strncmp(cmd, "570", 3)) && (strncmp(cmd, "200", 3))) {
945                 scr_printf("%s\n", &cmd[4]);
946                 return (1);
947         }
948
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.
951          */
952         need_recp = 0;
953         if (!strncmp(cmd, "570", 3))
954                 need_recp = 1;
955
956         /* If the user is a dumbass, tell them how to type. */
957         if ((userflags & US_EXPERT) == 0) {
958                 formout("entermsg");
959         }
960
961         /* Handle the selection of a recipient, if necessary. */
962         strcpy(buf, "");
963         if (need_recp == 1) {
964                 if (axlevel >= 2) {
965                         if (is_reply) {
966                                 strcpy(buf, reply_to);
967                         } else {
968                                 scr_printf("Enter recipient: ");
969                                 getline(buf, (SIZ-100) );
970                                 if (strlen(buf) == 0)
971                                         return (1);
972                         }
973                 } else
974                         strcpy(buf, "sysop");
975         }
976
977         b = 0;
978         if (room_flags & QR_ANONOPT) {
979                 scr_printf("Anonymous (Y/N)? ");
980                 if (yesno() == 1)
981                         b = 1;
982         }
983
984         /* If it's mail, we've got to check the validity of the recipient... */
985         if (strlen(buf) > 0) {
986                 sprintf(cmd, "ENT0 0|%s|%d|%d|%s", buf, b, mode, subject);
987                 serv_puts(cmd);
988                 serv_gets(cmd);
989                 if (cmd[0] != '2') {
990                         scr_printf("%s\n", &cmd[4]);
991                         return (1);
992                 }
993         }
994
995         /* Learn the number of the newest message in in the room, so we can
996          * tell upon saving whether someone else has posted too.
997          */
998         num_msgs = 0;
999         serv_puts("MSGS LAST|1");
1000         serv_gets(cmd);
1001         if (cmd[0] != '1') {
1002                 scr_printf("%s\n", &cmd[5]);
1003         } else {
1004                 while (serv_gets(cmd), strcmp(cmd, "000")) {
1005                         msg_arr[num_msgs++] = atol(cmd);
1006                 }
1007         }
1008
1009         /* Now compose the message... */
1010         if (client_make_message(temp, buf, b, 0, c, subject) != 0) {
1011                 return (2);
1012         }
1013
1014         /* Reopen the temp file that was created, so we can send it */
1015         fp = fopen(temp, "r");
1016
1017         /* Yes, unlink it now, so it doesn't stick around if we crash */
1018         unlink(temp);
1019
1020         if (fp == NULL) {
1021                 err_printf("*** Internal error while trying to save message!\n"
1022                         "    %s: %s\n",
1023                         temp, strerror(errno));
1024                 return(errno);
1025         }
1026
1027         /* Transmit message to the server */
1028         sprintf(cmd, "ENT0 1|%s|%d|%d|%s|", buf, b, mode, subject);
1029         serv_puts(cmd);
1030         serv_gets(cmd);
1031         if (cmd[0] != '4') {
1032                 scr_printf("%s\n", &cmd[4]);
1033                 return (1);
1034         }
1035
1036         transmit_message(fp);
1037         serv_puts("000");
1038
1039         fclose(fp);
1040
1041         highmsg = msg_arr[num_msgs - 1];
1042         num_msgs = 0;
1043         serv_puts("MSGS NEW");
1044         serv_gets(cmd);
1045         if (cmd[0] != '1') {
1046                 scr_printf("%s\n", &cmd[5]);
1047         } else {
1048                 while (serv_gets(cmd), strcmp(cmd, "000")) {
1049                         msg_arr[num_msgs++] = atol(cmd);
1050                 }
1051         }
1052
1053         /* get new highest message number in room to set lrp for goto... */
1054         maxmsgnum = msg_arr[num_msgs - 1];
1055
1056         /* now see if anyone else has posted in here */
1057         b = (-1);
1058         for (a = 0; a < num_msgs; ++a) {
1059                 if (msg_arr[a] > highmsg) {
1060                         ++b;
1061                 }
1062         }
1063
1064         /* In the Mail> room, this algorithm always counts one message
1065          * higher than in public rooms, so we decrement it by one.
1066          */
1067         if (need_recp) {
1068                 --b;
1069         }
1070
1071         if (b == 1) {
1072                 scr_printf("*** 1 additional message has been entered "
1073                         "in this room by another user.\n");
1074         }
1075         else if (b > 1) {
1076                 scr_printf("*** %d additional messages have been entered "
1077                         "in this room by other users.\n", b);
1078         }
1079
1080         return(0);
1081 }
1082
1083 /*
1084  * Do editing on a quoted file
1085  */
1086 void process_quote(void)
1087 {
1088         FILE *qfile, *tfile;
1089         char buf[128];
1090         int line, qstart, qend;
1091
1092         /* Unlink the second temp file as soon as it's opened, so it'll get
1093          * deleted even if the program dies
1094          */
1095         qfile = fopen(temp2, "r");
1096         unlink(temp2);
1097
1098         /* Display the quotable text with line numbers added */
1099         line = 0;
1100         fgets(buf, 128, qfile);
1101         while (fgets(buf, 128, qfile) != NULL) {
1102                 scr_printf("%2d %s", ++line, buf);
1103         }
1104         scr_printf("Begin quoting at [ 1] : ");
1105         getline(buf, 3);
1106         qstart = (buf[0] == 0) ? (1) : atoi(buf);
1107         scr_printf("  End quoting at [%d] : ", line);
1108         getline(buf, 3);
1109         qend = (buf[0] == 0) ? (line) : atoi(buf);
1110         rewind(qfile);
1111         line = 0;
1112         fgets(buf, 128, qfile);
1113         tfile = fopen(temp, "w");
1114         while (fgets(buf, 128, qfile) != NULL) {
1115                 if ((++line >= qstart) && (line <= qend))
1116                         fprintf(tfile, " >%s", buf);
1117         }
1118         fprintf(tfile, " \n");
1119         fclose(qfile);
1120         fclose(tfile);
1121         chmod(temp, 0666);
1122 }
1123
1124
1125
1126 /*
1127  * List the URL's which were embedded in the previous message
1128  */
1129 void list_urls()
1130 {
1131         int i;
1132         char cmd[SIZ];
1133
1134         if (num_urls == 0) {
1135                 scr_printf("There were no URL's in the previous message.\n\n");
1136                 return;
1137         }
1138
1139         for (i = 0; i < num_urls; ++i) {
1140                 scr_printf("%3d %s\n", i + 1, urls[i]);
1141         }
1142
1143         if ((i = num_urls) != 1)
1144                 i = intprompt("Display which one", 1, 1, num_urls);
1145
1146         sprintf(cmd, rc_url_cmd, urls[i - 1]);
1147         system(cmd);
1148         scr_printf("\n");
1149 }
1150
1151 /*
1152  * Read the messages in the current room
1153  */
1154 void readmsgs(
1155         int c,          /* 0=Read all  1=Read new  2=Read old 3=Read last q */
1156         int rdir,       /* 1=Forward (-1)=Reverse */
1157         int q           /* Number of msgs to read (if c==3) */
1158 ) {
1159         int a, b, e, f, g, start;
1160         int savedpos;
1161         int hold_sw = 0;
1162         char arcflag = 0;
1163         char quotflag = 0;
1164         int hold_color = 0;
1165         char prtfile[PATH_MAX];
1166         char pagin;
1167         char cmd[SIZ];
1168         char targ[ROOMNAMELEN];
1169         char filename[SIZ];
1170         FILE *dest = NULL;      /* Alternate destination other than screen */
1171
1172         if (c < 0)
1173                 b = (MAXMSGS - 1);
1174         else
1175                 b = 0;
1176
1177         strcpy(prtfile, tmpnam(NULL));
1178
1179         num_msgs = 0;
1180         strcpy(cmd, "MSGS ");
1181         switch (c) {
1182         case 0:
1183                 strcat(cmd, "ALL");
1184                 break;
1185         case 1:
1186                 strcat(cmd, "NEW");
1187                 break;
1188         case 2:
1189                 strcat(cmd, "OLD");
1190                 break;
1191         case 3:
1192                 sprintf(&cmd[strlen(cmd)], "LAST|%d", q);
1193                 break;
1194         }
1195         serv_puts(cmd);
1196         serv_gets(cmd);
1197         if (cmd[0] != '1') {
1198                 scr_printf("%s\n", &cmd[5]);
1199         } else {
1200                 while (serv_gets(cmd), strcmp(cmd, "000")) {
1201                         if (num_msgs == MAXMSGS) {
1202                                 memcpy(&msg_arr[0], &msg_arr[1],
1203                                        (sizeof(long) * (MAXMSGS - 1)));
1204                                 --num_msgs;
1205                         }
1206                         msg_arr[num_msgs++] = atol(cmd);
1207                 }
1208         }
1209
1210         if (num_msgs == 0) {
1211                 if (c == 3) return;
1212                 scr_printf("*** There are no ");
1213                 if (c == 1) scr_printf("new ");
1214                 if (c == 2) scr_printf("old ");
1215                 scr_printf("messages in this room.\n");
1216                 return;
1217         }
1218
1219         lines_printed = 0;
1220
1221         /* this loop cycles through each message... */
1222         start = ((rdir == 1) ? 0 : (num_msgs - 1));
1223         for (a = start; ((a < num_msgs) && (a >= 0)); a = a + rdir) {
1224                 while (msg_arr[a] == 0L) {
1225                         a = a + rdir;
1226                         if ((a == MAXMSGS) || (a == (-1)))
1227                                 return;
1228                 }
1229
1230 RAGAIN:         pagin = ((arcflag == 0)
1231                          && (quotflag == 0)
1232                          && (userflags & US_PAGINATOR)) ? 1 : 0;
1233
1234                 /* If we're doing a quote, set the screenwidth to 72 */
1235                 if (quotflag) {
1236                         hold_sw = screenwidth;
1237                         screenwidth = 72;
1238                 }
1239
1240                 /* If printing or archiving, set the screenwidth to 80 */
1241                 if (arcflag) {
1242                         hold_sw = screenwidth;
1243                         screenwidth = 80;
1244                 }
1245
1246                 /* now read the message... */
1247                 e = read_message(msg_arr[a], pagin, dest);
1248
1249                 /* ...and set the screenwidth back if we have to */
1250                 if ((quotflag) || (arcflag)) {
1251                         screenwidth = hold_sw;
1252                 }
1253 RMSGREAD:       scr_flush();
1254                 highest_msg_read = msg_arr[a];
1255                 if (quotflag) {
1256                         fclose(dest);
1257                         dest = NULL;
1258                         quotflag = 0;
1259                         enable_color = hold_color;
1260                         process_quote();
1261                 }
1262                 if (arcflag) {
1263                         fclose(dest);
1264                         dest = NULL;
1265                         arcflag = 0;
1266                         enable_color = hold_color;
1267                         f = fork();
1268                         if (f == 0) {
1269                                 freopen(prtfile, "r", stdin);
1270                                 screen_reset();
1271                                 sttybbs(SB_RESTORE);
1272                                 ka_system(printcmd);
1273                                 sttybbs(SB_NO_INTR);
1274                                 screen_set();
1275                                 unlink(prtfile);
1276                                 exit(0);
1277                         }
1278                         if (f > 0)
1279                                 do {
1280                                         g = wait(NULL);
1281                                 } while ((g != f) && (g >= 0));
1282                         scr_printf("Message printed.\n");
1283                 }
1284                 if (rc_alt_semantics && c == 1) {
1285                         char buf[SIZ];
1286
1287                         snprintf(buf, sizeof(buf), "SEEN %ld", msg_arr[a]);
1288                         serv_puts(buf);
1289                         serv_gets(buf); /* Don't need to check this? */
1290                 }
1291                 if (e == 3)
1292                         return;
1293                 if (((userflags & US_NOPROMPT) || (e == 2))
1294                     && (((room_flags & QR_MAILBOX) == 0)
1295                         || (rc_force_mail_prompts == 0))) {
1296                         e = 'n';
1297                 } else {
1298                         color(DIM_WHITE);
1299                         scr_printf("(");
1300                         color(BRIGHT_WHITE);
1301                         scr_printf("%d", num_msgs - a - 1);
1302                         color(DIM_WHITE);
1303                         scr_printf(") ");
1304
1305                         keyopt("<B>ack <A>gain <Q>uote <R>eply <N>ext <S>top m<Y> next ");
1306                         if (rc_url_cmd[0] && num_urls)
1307                                 keyopt("<U>RLview ");
1308                         keyopt("<?>help -> ");
1309
1310                         do {
1311                                 lines_printed = 2;
1312                                 e = (inkey() & 127);
1313                                 e = tolower(e);
1314 /* return key same as <N> */ if (e == 13)
1315                                         e = 'n';
1316 /* space key same as <N> */ if (e == 32)
1317                                         e = 'n';
1318 /* del/move for aides only */
1319                                     if ((!is_room_aide)
1320                                         && ((room_flags & QR_MAILBOX) ==
1321                                             0)) {
1322                                         if ((e == 'd') || (e == 'm'))
1323                                                 e = 0;
1324                                 }
1325 /* print only if available */
1326                                 if ((e == 'p') && (strlen(printcmd) == 0))
1327                                         e = 0;
1328 /* can't file if not allowed */
1329                                     if ((e == 'f')
1330                                         && (rc_allow_attachments == 0))
1331                                         e = 0;
1332 /* link only if browser avail*/
1333                                     if ((e == 'u')
1334                                         && (strlen(rc_url_cmd) == 0))
1335                                         e = 0;
1336                         } while ((e != 'a') && (e != 'n') && (e != 's')
1337                                  && (e != 'd') && (e != 'm') && (e != 'p')
1338                                  && (e != 'q') && (e != 'b') && (e != 'h')
1339                                  && (e != 'r') && (e != 'f') && (e != '?')
1340                                  && (e != 'u') && (e != 'c') && (e != 'y'));
1341                         switch (e) {
1342                         case 's':
1343                                 scr_printf("Stop");
1344                                 break;
1345                         case 'a':
1346                                 scr_printf("Again");
1347                                 break;
1348                         case 'd':
1349                                 scr_printf("Delete");
1350                                 break;
1351                         case 'm':
1352                                 scr_printf("Move");
1353                                 break;
1354                         case 'c':
1355                                 scr_printf("Copy");
1356                                 break;
1357                         case 'n':
1358                                 scr_printf("Next");
1359                                 break;
1360                         case 'p':
1361                                 scr_printf("Print");
1362                                 break;
1363                         case 'q':
1364                                 scr_printf("Quote");
1365                                 break;
1366                         case 'b':
1367                                 scr_printf("Back");
1368                                 break;
1369                         case 'h':
1370                                 scr_printf("Header");
1371                                 break;
1372                         case 'r':
1373                                 scr_printf("Reply");
1374                                 break;
1375                         case 'f':
1376                                 scr_printf("File");
1377                                 break;
1378                         case 'u':
1379                                 scr_printf("URL's");
1380                                 break;
1381                         case 'y':
1382                                 scr_printf("mY next");
1383                                 break;
1384                         case '?':
1385                                 scr_printf("? <help>");
1386                                 break;
1387                         }
1388                         if (userflags & US_DISAPPEAR)
1389                                 scr_printf("\r%79s\r", "");
1390                         else
1391                                 scr_printf("\n");
1392                         scr_flush();
1393                 }
1394                 switch (e) {
1395                 case '?':
1396                         scr_printf("Options available here:\n"
1397                                 " ?  Help (prints this message)\n"
1398                                 " S  Stop reading immediately\n"
1399                                 " A  Again (repeats last message)\n"
1400                                 " N  Next (continue with next message)\n"
1401                                 " Y  My Next (continue with next message you authored)\n"
1402                                 " B  Back (go back to previous message)\n");
1403                         if ((is_room_aide)
1404                             || (room_flags & QR_MAILBOX)) {
1405                                 scr_printf(" D  Delete this message\n"
1406                                         " M  Move message to another room\n");
1407                         }
1408                         scr_printf(" C  Copy message to another room\n");
1409                         if (strlen(printcmd) > 0)
1410                                 scr_printf(" P  Print this message\n");
1411                         scr_printf(
1412                                 " Q  Quote portions of this message for your next post\n"
1413                                 " H  Headers (display message headers only)\n");
1414                         if (is_mail)
1415                                 scr_printf(" R  Reply to this message\n");
1416                         if (rc_allow_attachments)
1417                                 scr_printf
1418                                     (" F  (save attachments to a file)\n");
1419                         if (strlen(rc_url_cmd) > 0)
1420                                 scr_printf(" U  (list URL's for display)\n");
1421                         scr_printf("\n");
1422                         goto RMSGREAD;
1423                 case 'p':
1424                         scr_flush();
1425                         dest = fopen(prtfile, "w");
1426                         arcflag = 1;
1427                         hold_color = enable_color;
1428                         enable_color = 0;
1429                         goto RAGAIN;
1430                 case 'q':
1431                         scr_flush();
1432                         dest = fopen(temp2, "w");
1433                         quotflag = 1;
1434                         hold_color = enable_color;
1435                         enable_color = 0;
1436                         goto RAGAIN;
1437                 case 's':
1438                         return;
1439                 case 'a':
1440                         goto RAGAIN;
1441                 case 'b':
1442                         a = a - (rdir * 2);
1443                         break;
1444                 case 'm':
1445                 case 'c':
1446                         newprompt("Enter target room: ",
1447                                   targ, ROOMNAMELEN - 1);
1448                         if (strlen(targ) > 0) {
1449                                 sprintf(cmd, "MOVE %ld|%s|%d",
1450                                         msg_arr[a], targ,
1451                                         (e == 'c' ? 1 : 0));
1452                                 serv_puts(cmd);
1453                                 serv_gets(cmd);
1454                                 scr_printf("%s\n", &cmd[4]);
1455                                 if (cmd[0] == '2')
1456                                         msg_arr[a] = 0L;
1457                         } else {
1458                                 goto RMSGREAD;
1459                         }
1460                         if (cmd[0] != '2')
1461                                 goto RMSGREAD;
1462                         break;
1463                 case 'f':
1464                         newprompt("Which section? ", filename,
1465                                   ((sizeof filename) - 1));
1466                         snprintf(cmd, sizeof cmd,
1467                                  "OPNA %ld|%s", msg_arr[a], filename);
1468                         serv_puts(cmd);
1469                         serv_gets(cmd);
1470                         if (cmd[0] == '2') {
1471                                 extract(filename, &cmd[4], 2);
1472                                 download_to_local_disk(filename,
1473                                                        extract_int(&cmd[4],
1474                                                                    0));
1475                         } else {
1476                                 scr_printf("%s\n", &cmd[4]);
1477                         }
1478                         goto RMSGREAD;
1479                 case 'd':
1480                         scr_printf("*** Delete this message? ");
1481                         if (yesno() == 1) {
1482                                 sprintf(cmd, "DELE %ld", msg_arr[a]);
1483                                 serv_puts(cmd);
1484                                 serv_gets(cmd);
1485                                 scr_printf("%s\n", &cmd[4]);
1486                                 if (cmd[0] == '2')
1487                                         msg_arr[a] = 0L;
1488                         } else {
1489                                 goto RMSGREAD;
1490                         }
1491                         break;
1492                 case 'h':
1493                         read_message(msg_arr[a], READ_HEADER, NULL);
1494                         goto RMSGREAD;
1495                 case 'r':
1496                         savedpos = num_msgs;
1497                         entmsg(1, (DEFAULT_ENTRY == 46 ? 2 : 0));
1498                         num_msgs = savedpos;
1499                         goto RMSGREAD;
1500                 case 'u':
1501                         list_urls();
1502                         goto RMSGREAD;
1503             case 'y':
1504           { /* hack hack hack */
1505             /* find the next message by me, stay here if we find nothing */
1506             int finda;
1507             int lasta = a;
1508             for (finda = a; ((finda < num_msgs) && (finda >= 0)); finda += rdir)
1509               {
1510                 /* this is repetitivly dumb, but that's what computers are for.
1511                    We have to load up messages until we find one by us */
1512                 char buf[SIZ];
1513                 int founda = 0;
1514                 
1515                 sprintf(buf, "MSG0 %ld|%d", msg_arr[finda], 1); /* read the header so we can get 'from=' */
1516                 serv_puts(buf);
1517                 serv_gets(buf);
1518                 while (serv_gets(buf), strcmp(buf, "000")) 
1519                   {
1520                         if ((!strncasecmp(buf, "from=", 5)) && (finda != a)) /* Skip current message. */
1521                       { 
1522                         if (strcasecmp(buf+5, fullname) == 0)
1523                           {
1524                             a = lasta; /* meesa current */
1525                             founda = 1;
1526                           }
1527                           }
1528                   }
1529                     // we are now in synch with the server
1530                 if (founda)
1531                   break; /* for */
1532                 lasta = finda; /* keep one behind or we skip on the reentrance to the for */
1533               } /* for */
1534           } /* case 'y' */
1535       } /* switch */
1536         }                       /* end for loop */
1537 }                               /* end read routine */
1538
1539
1540
1541
1542 /*
1543  * View and edit a system message
1544  */
1545 void edit_system_message(char *which_message)
1546 {
1547         char desc[64];
1548         char read_cmd[64];
1549         char write_cmd[64];
1550
1551         sprintf(desc, "system message '%s'", which_message);
1552         sprintf(read_cmd, "MESG %s", which_message);
1553         sprintf(write_cmd, "EMSG %s", which_message);
1554         do_edit(desc, read_cmd, "NOOP", write_cmd);
1555 }
1556
1557
1558
1559
1560 /*
1561  * Verify the message base
1562  */
1563 void check_message_base(void)
1564 {
1565         char buf[SIZ];
1566
1567         scr_printf
1568             ("Please read the documentation before running this command.\n"
1569             "Having done so, do you still want to check the message base? ");
1570         if (yesno() == 0)
1571                 return;
1572
1573         serv_puts("FSCK");
1574         serv_gets(buf);
1575         if (buf[0] != '1') {
1576                 scr_printf("%s\n", &buf[4]);
1577                 return;
1578         }
1579
1580         while (serv_gets(buf), strcmp(buf, "000")) {
1581                 scr_printf("%s\n", buf);
1582         }
1583 }