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