]> code.citadel.org Git - citadel.git/blob - webcit/messages.c
* view
[citadel.git] / webcit / messages.c
1 /*
2  * $Id$
3  *
4  * Functions which deal with the fetching and displaying of messages.
5  *
6  */
7
8 #include <ctype.h>
9 #include <stdlib.h>
10 #include <unistd.h>
11 #include <stdio.h>
12 #include <fcntl.h>
13 #include <signal.h>
14 #include <sys/types.h>
15 #include <sys/wait.h>
16 #include <sys/socket.h>
17 #include <limits.h>
18 #include <netinet/in.h>
19 #include <netdb.h>
20 #include <string.h>
21 #include <pwd.h>
22 #include <errno.h>
23 #include <stdarg.h>
24 #include <pthread.h>
25 #include <signal.h>
26 #include "webcit.h"
27 #include "vcard.h"
28
29
30 /*
31  * Look for URL's embedded in a buffer and make them linkable.  We use a
32  * target window in order to keep the BBS session in its own window.
33  */
34 void url(buf)
35 char buf[];
36 {
37
38         int pos;
39         int start, end;
40         char ench;
41         char urlbuf[SIZ];
42         char outbuf[1024];
43
44         start = (-1);
45         end = strlen(buf);
46         ench = 0;
47
48         for (pos = 0; pos < strlen(buf); ++pos) {
49                 if (!strncasecmp(&buf[pos], "http://", 7))
50                         start = pos;
51                 if (!strncasecmp(&buf[pos], "ftp://", 6))
52                         start = pos;
53         }
54
55         if (start < 0)
56                 return;
57
58         if ((start > 0) && (buf[start - 1] == '<'))
59                 ench = '>';
60         if ((start > 0) && (buf[start - 1] == '['))
61                 ench = ']';
62         if ((start > 0) && (buf[start - 1] == '('))
63                 ench = ')';
64         if ((start > 0) && (buf[start - 1] == '{'))
65                 ench = '}';
66
67         for (pos = strlen(buf); pos > start; --pos) {
68                 if ((buf[pos] == ' ') || (buf[pos] == ench))
69                         end = pos;
70         }
71
72         strncpy(urlbuf, &buf[start], end - start);
73         urlbuf[end - start] = 0;
74
75
76         strncpy(outbuf, buf, start);
77         sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
78                 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
79         strcat(outbuf, &buf[end]);
80         if ( strlen(outbuf) < 250 )
81                 strcpy(buf, outbuf);
82 }
83
84
85
86
87 /*
88  * Experimental output type of thing
89  */
90 void display_vcard(char *vcard_source) {
91         int i, j;
92         struct vCard *v;
93         char buf[SIZ];
94
95         v = vcard_load(vcard_source);
96         if (v == NULL) return;
97
98         wprintf("<TABLE bgcolor=#888888>");
99         if (v->numprops) for (i=0; i<(v->numprops); ++i) {
100                 if (!strcasecmp(v->prop[i].name, "n")) {
101                         wprintf("<TR BGCOLOR=#AAAAAA>"
102                         "<TD BGCOLOR=#FFFFFF>"
103                         "<IMG VALIGN=CENTER SRC=\"/static/vcard.gif\"></TD>"
104                         "<TD><FONT SIZE=+1><B>");
105                         escputs(v->prop[i].value);
106                         wprintf("</B></FONT></TD></TR>\n");
107                 }
108                 else if (!strcasecmp(v->prop[i].name, "email;internet")) {
109                         wprintf("<TR><TD>Internet e-mail:</TD>"
110                                 "<TD><A HREF=\"mailto:");
111                         urlescputs(v->prop[i].value);
112                         wprintf("\">");
113                         escputs(v->prop[i].value);
114                         wprintf("</A></TD></TR>\n");
115                 }
116                 else if (!strcasecmp(v->prop[i].name, "adr")) {
117                         wprintf("<TR><TD>Address:</TD><TD>");
118                         for (j=0; j<num_tokens(v->prop[i].value, ';'); ++j) {
119                                 extract_token(buf, v->prop[i].value, j, ';');
120                                 if (strlen(buf) > 0) {
121                                         escputs(buf);
122                                         wprintf("<BR>");
123                                 }
124                         }
125                         wprintf("</TD></TR>\n");
126                 }
127                 else if (!strncasecmp(v->prop[i].name, "tel;", 4)) {
128                         wprintf("<TR><TD>%s telephone:</TD><TD>",
129                                 &v->prop[i].name[4]);
130                         for (j=0; j<num_tokens(v->prop[i].value, ';'); ++j) {
131                                 extract_token(buf, v->prop[i].value, j, ';');
132                                 if (strlen(buf) > 0) {
133                                         escputs(buf);
134                                         wprintf("<BR>");
135                                 }
136                         }
137                         wprintf("</TD></TR>\n");
138                 }
139                 else {
140                         wprintf("<TR><TD>");
141                         escputs(v->prop[i].name);
142                         wprintf("</TD><TD>");
143                         escputs(v->prop[i].value);
144                         wprintf("</TD></TR>\n");
145                 }
146         }
147
148         wprintf("</TABLE>\n");
149
150         vcard_free(v);
151 }
152
153
154
155
156
157
158 void read_message(long msgnum, int is_summary) {
159         char buf[SIZ];
160         char mime_partnum[SIZ];
161         char mime_filename[SIZ];
162         char mime_content_type[SIZ];
163         char mime_disposition[SIZ];
164         int mime_length;
165         char *mime_http = NULL;
166         char m_subject[SIZ];
167         char from[SIZ];
168         char node[SIZ];
169         char rfca[SIZ];
170         char reply_to[512];
171         char now[SIZ];
172         int format_type = 0;
173         int nhdr = 0;
174         int bq = 0;
175         char vcard_partnum[SIZ];
176         char *vcard_source = NULL;
177
178         strcpy(from, "");
179         strcpy(node, "");
180         strcpy(rfca, "");
181         strcpy(reply_to, "");
182         strcpy(vcard_partnum, "");
183
184         sprintf(buf, "MSG0 %ld", msgnum);
185         serv_puts(buf);
186         serv_gets(buf);
187         if (buf[0] != '1') {
188                 wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
189                 return;
190         }
191         wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 CELLPADDING=1 BGCOLOR=CCCCCC><TR><TD>\n");
192         wprintf("<FONT ");
193         if (!is_summary) wprintf("SIZE=+1 ");
194         wprintf("COLOR=\"000000\"> ");
195         strcpy(m_subject, "");
196
197         while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
198                 if (!strncasecmp(buf, "nhdr=yes", 8))
199                         nhdr = 1;
200                 if (nhdr == 1)
201                         buf[0] = '_';
202                 if (!strncasecmp(buf, "type=", 5))
203                         format_type = atoi(&buf[5]);
204                 if (!strncasecmp(buf, "from=", 5)) {
205                         strcpy(from, &buf[5]);
206                         wprintf("from <A HREF=\"/showuser&who=");
207                         urlescputs(from);
208                         wprintf("\">");
209                         escputs(from);
210                         wprintf("</A> ");
211                 }
212                 if (!strncasecmp(buf, "subj=", 5))
213                         strcpy(m_subject, &buf[5]);
214                 if ((!strncasecmp(buf, "hnod=", 5))
215                     && (strcasecmp(&buf[5], serv_info.serv_humannode)))
216                         wprintf("(%s) ", &buf[5]);
217                 if ((!strncasecmp(buf, "room=", 5))
218                     && (strcasecmp(&buf[5], WC->wc_roomname)))
219                         wprintf("in %s> ", &buf[5]);
220                 if (!strncasecmp(buf, "rfca=", 5)) {
221                         strcpy(rfca, &buf[5]);
222                         wprintf("&lt;");
223                         escputs(rfca);
224                         wprintf("&gt; ");
225                 }
226
227                 if (!strncasecmp(buf, "node=", 5)) {
228                         if ( ((WC->room_flags & QR_NETWORK)
229                         || ((strcasecmp(&buf[5], serv_info.serv_nodename)
230                         && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
231                         && (strlen(rfca)==0)
232                         ) {
233                                 wprintf("@%s ", &buf[5]);
234                         }
235                 }
236                 if (!strncasecmp(buf, "rcpt=", 5))
237                         wprintf("to %s ", &buf[5]);
238                 if (!strncasecmp(buf, "time=", 5)) {
239                         fmt_date(now, atol(&buf[5]));
240                         wprintf("%s ", now);
241                 }
242
243                 if (!strncasecmp(buf, "part=", 5)) {
244                         extract(mime_filename, &buf[5], 1);
245                         extract(mime_partnum, &buf[5], 2);
246                         extract(mime_disposition, &buf[5], 3);
247                         extract(mime_content_type, &buf[5], 4);
248                         mime_length = extract_int(&buf[5], 5);
249
250                         if (!strcasecmp(mime_disposition, "attachment")) {
251                                 if (mime_http == NULL) {
252                                         mime_http = malloc(512);
253                                         strcpy(mime_http, "");
254                                 }
255                                 else {
256                                         mime_http = realloc(mime_http,
257                                                 strlen(mime_http) + 512);
258                                 }
259                                 sprintf(&mime_http[strlen(mime_http)],
260                                         "<A HREF=\"/output_mimepart?"
261                                         "msgnum=%ld&partnum=%s\" "
262                                         "TARGET=\"wc.%ld.%s\">"
263                                         "<IMG SRC=\"/static/attachment.gif\" "
264                                         "BORDER=0 ALIGN=MIDDLE>\n"
265                                         "Part %s: %s (%s, %d bytes)</A><BR>\n",
266                                         msgnum, mime_partnum,
267                                         msgnum, mime_partnum,
268                                         mime_partnum, mime_filename,
269                                         mime_content_type, mime_length);
270                         }
271
272                         if ((!strcasecmp(mime_disposition, "inline"))
273                            && (!strncasecmp(mime_content_type, "image/", 6)) ){
274                                 if (mime_http == NULL) {
275                                         mime_http = malloc(512);
276                                         strcpy(mime_http, "");
277                                 }
278                                 else {
279                                         mime_http = realloc(mime_http,
280                                                 strlen(mime_http) + 512);
281                                 }
282                                 sprintf(&mime_http[strlen(mime_http)],
283                                         "<IMG SRC=\"/output_mimepart?"
284                                         "msgnum=%ld&partnum=%s\">",
285                                         msgnum, mime_partnum);
286                         }
287
288                         if (!strcasecmp(mime_content_type, "text/x-vcard")) {
289                                 strcpy(vcard_partnum, mime_partnum);
290                         }
291
292                 }
293
294         }
295
296
297         /* Generate a reply-to address */
298         if (strlen(rfca) > 0) {
299                 strcpy(reply_to, rfca);
300         }
301         else {
302                 if (strlen(node) > 0) {
303                         snprintf(reply_to, sizeof(reply_to), "%s @ %s",
304                                 from, node);
305                 }
306                 else {
307                         snprintf(reply_to, sizeof(reply_to), "%s", from);
308                 }
309         }
310
311         if (nhdr == 1)
312                 wprintf("****");
313         wprintf("</FONT></TD>");
314
315         /* begin right-hand toolbar */
316         wprintf("<TD ALIGN=RIGHT>\n"
317                 "<TABLE BORDER=0><TR>\n");
318
319         if (is_summary) {
320                 wprintf("<TD BGCOLOR=\"AAAADD\">"
321                         "<A HREF=\"/readfwd?startmsg=%ld", msgnum);
322                 wprintf("&maxmsgs=1&summary=0\">Read</A>"
323                         "</TD>\n", msgnum);
324         }
325
326         wprintf("<TD BGCOLOR=\"AAAADD\">"
327                 "<A HREF=\"/display_enter?recp=");
328         urlescputs(reply_to);
329         wprintf("\"><FONT SIZE=-1>Reply</FONT></A>"
330                 "</TD>\n", msgnum);
331
332         if (WC->is_room_aide) {
333                 wprintf("<TD BGCOLOR=\"AAAADD\">"
334                         "<A HREF=\"/confirm_move_msg"
335                         "&msgid=%ld"
336                         "\"><FONT SIZE=-1>Move</FONT></A>"
337                         "</TD>\n", msgnum);
338
339                 wprintf("<TD BGCOLOR=\"AAAADD\">"
340                         "<A HREF=\"/delete_msg"
341                         "&msgid=%ld\""
342                         "onClick=\"return confirm('Delete this message?');\""
343                         "><FONT SIZE=-1>Del</FONT></A>"
344                         "</TD>\n", msgnum);
345         }
346
347         wprintf("</TR></TABLE>\n"
348                 "</TD>\n");
349
350         /* end right-hand toolbar */
351
352
353         if (strlen(m_subject) > 0) {
354                 wprintf("<TR><TD><FONT COLOR=\"0000FF\">"
355                         "Subject: %s</FONT>"
356                         "</TD><TD>&nbsp;</TD></TR>\n", m_subject);
357         }
358
359         wprintf("</TR></TABLE>\n");
360
361         if (is_summary) {
362                 while (serv_gets(buf), strcmp(buf, "000")) ;
363                 return;
364         }
365
366         if (format_type == 0) {
367                 fmout(NULL);
368         } else {
369                 while (serv_gets(buf), strcmp(buf, "000")) {
370                         while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
371                                 buf[strlen(buf) - 1] = 0;
372                         if ((bq == 0) &&
373                             ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
374                                 wprintf("<FONT COLOR=\"000044\"><I>");
375                                 bq = 1;
376                         } else if ((bq == 1) &&
377                                    (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
378                                 wprintf("</FONT></I>");
379                                 bq = 0;
380                         }
381                         wprintf("<TT>");
382                         url(buf);
383                         escputs(buf);
384                         wprintf("</TT><BR>\n");
385                 }
386         }
387         wprintf("</I><BR>");
388
389         if (mime_http != NULL) {
390                 wprintf("%s", mime_http);
391                 free(mime_http);
392         }
393
394         if (strlen(vcard_partnum) > 0) {
395                 vcard_source = load_mimepart(msgnum, vcard_partnum);
396                 if (vcard_source != NULL) {
397
398                         /* If it's my vCard I can edit it */
399                         if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
400                            || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))) {
401                                 wprintf("<A HREF=\"/edit_vcard?"
402                                         "msgnum=%ld&partnum=%s\">",
403                                         msgnum, vcard_partnum);
404                                 wprintf("(edit)</A>");
405                         }
406
407                         /* In all cases, display it */
408                         display_vcard(vcard_source);
409                         free(vcard_source);
410                 }
411         }
412
413 }
414
415
416
417 /* 
418  * load message pointers from the server
419  */
420 int load_msg_ptrs(servcmd)
421 char *servcmd;
422 {
423         char buf[SIZ];
424         int nummsgs;
425
426         nummsgs = 0;
427         serv_puts(servcmd);
428         serv_gets(buf);
429         if (buf[0] != '1') {
430                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
431                 return (nummsgs);
432         }
433         while (serv_gets(buf), strcmp(buf, "000")) {
434                 WC->msgarr[nummsgs] = atol(buf);
435                 ++nummsgs;
436         }
437         return (nummsgs);
438 }
439
440
441 /*
442  * command loop for reading messages
443  */
444 void readloop(char *oper)
445 {
446         char cmd[SIZ];
447         int a, b;
448         int nummsgs;
449         long startmsg;
450         int maxmsgs;
451         int num_displayed = 0;
452         int is_summary = 0;
453         int remaining_messages;
454         int lo, hi;
455         int lowest_displayed = 0;
456         int highest_displayed = 0;
457         long pn_previous = 0L;
458         long pn_current = 0L;
459         long pn_next = 0L;
460
461         startmsg = atol(bstr("startmsg"));
462         maxmsgs = atoi(bstr("maxmsgs"));
463         is_summary = atoi(bstr("summary"));
464         if (maxmsgs == 0) maxmsgs = 20;
465
466         /* FIXME put in the correct constant #defs */
467         if ((is_summary == 0) && (WC->wc_view == 1)) is_summary = 1;
468
469         output_headers(1);
470
471         if (!strcmp(oper, "readnew")) {
472                 strcpy(cmd, "MSGS NEW");
473         } else if (!strcmp(oper, "readold")) {
474                 strcpy(cmd, "MSGS OLD");
475         } else {
476                 strcpy(cmd, "MSGS ALL");
477         }
478
479         nummsgs = load_msg_ptrs(cmd);
480         if (nummsgs == 0) {
481                 if (!strcmp(oper, "readnew")) {
482                         wprintf("<EM>No new messages in this room.</EM>\n");
483                 } else if (!strcmp(oper, "readold")) {
484                         wprintf("<EM>No old messages in this room.</EM>\n");
485                 } else {
486                         wprintf("<EM>This room is empty.</EM>\n");
487                 }
488                 goto DONE;
489         }
490
491         if (startmsg == 0L) startmsg = WC->msgarr[0];
492         remaining_messages = 0;
493
494         for (a = 0; a < nummsgs; ++a) {
495                 if (WC->msgarr[a] >= startmsg) {
496                         ++remaining_messages;
497                 }
498         }
499
500         for (a = 0; a < nummsgs; ++a) {
501                 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
502
503                         /* Learn which msgs "Prev" & "Next" buttons go to */
504                         pn_current = WC->msgarr[a];
505                         if (a > 0) pn_previous = WC->msgarr[a-1];
506                         if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
507
508                         /* Display the message */
509                         read_message(WC->msgarr[a], is_summary);
510                         if (lowest_displayed == 0) lowest_displayed = a;
511                         highest_displayed = a;
512                         if (is_summary) wprintf("<BR>");
513
514                         ++num_displayed;
515                         --remaining_messages;
516                 }
517         }
518
519         /* Bump these because although we're thinking in zero base, the user
520          * is a drooling idiot and is thinking in one base.
521          */
522         ++lowest_displayed;
523         ++highest_displayed;
524
525         /* If we're only looking at one message, do a prev/next thing */
526         if (num_displayed == 1) {
527
528                 wprintf("<CENTER>"
529                         "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=DDDDDD><TR><TD>"
530                         "Reading #%d of %d messages.</TD>\n"
531                         "<TD ALIGN=RIGHT><FONT SIZE=+1>",
532                         lowest_displayed, nummsgs);
533
534                         if (pn_previous > 0L) {
535                                 wprintf("<A HREF=\"/%s"
536                                         "?startmsg=%ld"
537                                         "&maxmsgs=1"
538                                         "&summary=0\">"
539                                         "Previous</A> \n",
540                                                 oper,
541                                                 pn_previous );
542                         }
543
544                         if (pn_next > 0L) {
545                                 wprintf("<A HREF=\"/%s"
546                                         "?startmsg=%ld"
547                                         "&maxmsgs=1"
548                                         "&summary=0\">"
549                                         "Next</A> \n",
550                                                 oper,
551                                                 pn_next );
552                         }
553
554                 wprintf("<A HREF=\"/%s?startmsg=%ld"
555                         "&maxmsgs=999999&summary=1\">"
556                         "Summary"
557                         "</A>",
558                         oper,
559                         WC->msgarr[0]);
560
561                 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
562         }
563
564
565         /*
566          * If we're not currently looking at ALL requested
567          * messages, then display the selector bar
568          */
569         /* if (num_displayed < nummsgs) { */
570         if (num_displayed > 1) {
571
572                 wprintf("<CENTER>"
573                         "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=DDDDDD><TR><TD>"
574                         "Reading #%d-%d of %d messages.</TD>\n"
575                         "<TD ALIGN=RIGHT><FONT SIZE=+1>",
576                         lowest_displayed, highest_displayed, nummsgs);
577
578                 for (b=0; b<nummsgs; b = b + maxmsgs) {
579                 lo = b+1;
580                 hi = b+maxmsgs+1;
581                 if (hi > nummsgs) hi = nummsgs;
582                         if (WC->msgarr[b] != startmsg) {
583                                 wprintf("<A HREF=\"/%s"
584                                         "?startmsg=%ld"
585                                         "&maxmsgs=%d"
586                                         "&summary=%d\">"
587                                         "%d-%d</A> \n",
588                                                 oper,
589                                                 WC->msgarr[b],
590                                                 maxmsgs,
591                                                 is_summary,
592                                                 lo, hi);
593                         }
594                         else {
595                                 wprintf("%d-%d \n", lo, hi);
596                         }
597
598                 }
599                 wprintf("<A HREF=\"/%s?startmsg=%ld"
600                         "&maxmsgs=999999&summary=%d\">"
601                         "ALL"
602                         "</A> ",
603                         oper,
604                         WC->msgarr[0], is_summary);
605
606                 wprintf("<A HREF=\"/%s?startmsg=%ld"
607                         "&maxmsgs=999999&summary=1\">"
608                         "Summary"
609                         "</A>",
610                         oper,
611                         WC->msgarr[0]);
612
613                 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
614         }
615
616 DONE:   wDumpContent(1);
617 }
618
619
620
621
622 /*
623  * Post message (or don't post message)
624  *
625  * Note regarding the "dont_post" variable:
626  * A random value (actually, it's just a timestamp) is inserted as a hidden
627  * field called "postseq" when the display_enter page is generated.  This
628  * value is checked when posting, using the static variable dont_post.  If a
629  * user attempts to post twice using the same dont_post value, the message is
630  * discarded.  This prevents the accidental double-saving of the same message
631  * if the user happens to click the browser "back" button.
632  */
633 void post_message(void)
634 {
635         char buf[SIZ];
636         static long dont_post = (-1L);
637
638         output_headers(1);
639
640         wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
641         strcpy(buf, bstr("sc"));
642         if (strcasecmp(buf, "Save message")) {
643                 wprintf("Cancelled.  Message was not posted.<BR>\n");
644         } else if (atol(bstr("postseq")) == dont_post) {
645                 wprintf("Automatically cancelled because you have already "
646                         "saved this message.<BR>\n");
647         } else {
648                 sprintf(buf, "ENT0 1|%s|0|0|%s",
649                         bstr("recp"),
650                         bstr("subject") );
651                 serv_puts(buf);
652                 serv_gets(buf);
653                 if (buf[0] == '4') {
654                         text_to_server(bstr("msgtext"));
655                         serv_puts("000");
656                         wprintf("Message has been posted.<BR>\n");
657                         dont_post = atol(bstr("postseq"));
658                 } else {
659                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
660                 }
661         }
662
663         wDumpContent(1);
664 }
665
666
667
668
669 /*
670  * display the message entry screen
671  */
672 void display_enter(void)
673 {
674         char buf[SIZ];
675         long now;
676         struct tm *tm;
677
678         output_headers(1);
679
680         wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
681
682         sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
683         serv_puts(buf);
684         serv_gets(buf);
685
686         if (!strncmp(buf, "570", 3)) {
687                 if (strlen(bstr("recp")) > 0) {
688                         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
689                 }
690                 do_template("prompt_for_recipient.html");
691                 goto DONE;
692         }
693         if (buf[0] != '2') {
694                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
695                 goto DONE;
696         }
697
698         now = time(NULL);
699         tm = (struct tm *) localtime(&now);
700         strcpy(buf, (char *) asctime(tm));
701         buf[strlen(buf) - 1] = 0;
702         strcpy(&buf[16], &buf[19]);
703         wprintf("</CENTER><FONT COLOR=\"440000\">\n"
704                 "<IMG SRC=\"static/enter.gif\" ALIGN=MIDDLE ALT=\" \" "
705                 "onLoad=\"document.enterform.msgtext.focus();\" >");
706         wprintf("<B> %s ", &buf[4]);
707         wprintf("from %s ", WC->wc_username);
708         if (strlen(bstr("recp")) > 0)
709                 wprintf("to %s ", bstr("recp"));
710         wprintf("in %s&gt; ", WC->wc_roomname);
711         wprintf("</B></FONT><BR><CENTER>\n");
712
713         wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\" "
714                 "NAME=\"enterform\">\n");
715         wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
716                 bstr("recp"));
717         wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
718                 now);
719         wprintf("<FONT SIZE=-1>Subject (optional):</FONT>"
720                 "<INPUT TYPE=\"text\" NAME=\"subject\" MAXLENGTH=70>"
721                 "&nbsp;&nbsp;&nbsp;"
722                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
723                 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
724
725         wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
726                 "WIDTH=80></TEXTAREA><P>\n");
727
728         wprintf("</FORM></CENTER>\n");
729 DONE:   wDumpContent(1);
730         wprintf("</FONT>");
731 }
732
733
734
735
736
737
738
739
740 void delete_msg(void)
741 {
742         long msgid;
743         char buf[SIZ];
744
745         msgid = atol(bstr("msgid"));
746
747         output_headers(1);
748
749         sprintf(buf, "DELE %ld", msgid);
750         serv_puts(buf);
751         serv_gets(buf);
752         wprintf("<EM>%s</EM><BR>\n", &buf[4]);
753
754         wDumpContent(1);
755 }
756
757
758
759
760 /*
761  * Confirm move of a message
762  */
763 void confirm_move_msg(void)
764 {
765         long msgid;
766         char buf[SIZ];
767         char targ[SIZ];
768
769         msgid = atol(bstr("msgid"));
770
771         output_headers(1);
772
773         wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
774         wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
775         wprintf("<B>Confirm move of message</B>\n");
776         wprintf("</FONT></TD></TR></TABLE>\n");
777
778         wprintf("<CENTER>");
779
780         wprintf("Please select the room to which you would like this message moved:<BR>\n");
781
782         wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
783         wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
784                 bstr("msgid"));
785
786
787         wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
788         serv_puts("LKRA");
789         serv_gets(buf);
790         if (buf[0] == '1') {
791                 while (serv_gets(buf), strcmp(buf, "000")) {
792                         extract(targ, buf, 0);
793                         wprintf("<OPTION>");
794                         escputs(targ);
795                         wprintf("\n");
796                 }
797         }
798         wprintf("</SELECT>\n");
799         wprintf("<BR>\n");
800
801         wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
802         wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
803         wprintf("</FORM></CENTER>\n");
804
805         wprintf("</CENTER>\n");
806         wDumpContent(1);
807 }
808
809
810
811 void move_msg(void)
812 {
813         long msgid;
814         char buf[SIZ];
815
816         msgid = atol(bstr("msgid"));
817
818         output_headers(1);
819
820         if (!strcasecmp(bstr("yesno"), "Move")) {
821                 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
822                 serv_puts(buf);
823                 serv_gets(buf);
824                 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
825         } else {
826                 wprintf("<EM>Message not deleted.</EM><BR>\n");
827         }
828
829         wDumpContent(1);
830 }
831
832
833