4 * Functions which deal with the fetching and displaying of messages.
14 #include <sys/types.h>
16 #include <sys/socket.h>
18 #include <netinet/in.h>
28 #include "webserver.h"
32 * Look for URL's embedded in a buffer and make them linkable. We use a
33 * target window in order to keep the BBS session in its own window.
49 for (pos = 0; pos < strlen(buf); ++pos) {
50 if (!strncasecmp(&buf[pos], "http://", 7))
52 if (!strncasecmp(&buf[pos], "ftp://", 6))
59 if ((start > 0) && (buf[start - 1] == '<'))
61 if ((start > 0) && (buf[start - 1] == '['))
63 if ((start > 0) && (buf[start - 1] == '('))
65 if ((start > 0) && (buf[start - 1] == '{'))
68 for (pos = strlen(buf); pos > start; --pos) {
69 if ((buf[pos] == ' ') || (buf[pos] == ench))
73 strncpy(urlbuf, &buf[start], end - start);
74 urlbuf[end - start] = 0;
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 )
85 /* display_vcard() calls this after parsing the textual vCard into
86 * our 'struct vCard' data object.
88 * Set 'full' to nonzero to display the full card, otherwise it will only
89 * show a summary line.
91 void display_parsed_vcard(struct vCard *v, int full) {
98 name = vcard_get_prop(v, "n", 1, 0, 0);
110 wprintf("<TABLE bgcolor=#888888>");
111 if (v->numprops) for (i=0; i<(v->numprops); ++i) {
112 if (!strcasecmp(v->prop[i].name, "n")) {
113 wprintf("<TR BGCOLOR=\"#AAAAAA\">"
114 "<TD BGCOLOR=\"#FFFFFF\">"
115 "<IMG ALIGN=CENTER SRC=\"/static/vcard.gif\"></TD>"
116 "<TD><FONT SIZE=+1><B>");
117 escputs(v->prop[i].value);
118 wprintf("</B></FONT></TD></TR>\n");
120 else if (!strcasecmp(v->prop[i].name, "email;internet")) {
121 wprintf("<TR><TD>Internet e-mail:</TD>"
122 "<TD><A HREF=\"mailto:");
123 urlescputs(v->prop[i].value);
125 escputs(v->prop[i].value);
126 wprintf("</A></TD></TR>\n");
128 else if (!strcasecmp(v->prop[i].name, "adr")) {
129 wprintf("<TR><TD>Address:</TD><TD>");
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) {
137 wprintf("</TD></TR>\n");
139 else if (!strncasecmp(v->prop[i].name, "tel;", 4)) {
140 wprintf("<TR><TD>%s telephone:</TD><TD>",
141 &v->prop[i].name[4]);
142 for (j=0; j<num_tokens(v->prop[i].value, ';'); ++j) {
143 extract_token(buf, v->prop[i].value, j, ';');
144 if (strlen(buf) > 0) {
149 wprintf("</TD></TR>\n");
153 escputs(v->prop[i].name);
154 wprintf("</TD><TD>");
155 escputs(v->prop[i].value);
156 wprintf("</TD></TR>\n");
159 wprintf("</TABLE>\n");
165 * Display a textual vCard
166 * (Converts to a vCard object and then calls the actual display function)
167 * Set 'full' to nonzero to display the whole card instead of a one-liner
169 void display_vcard(char *vcard_source, char alpha, int full) {
175 v = vcard_load(vcard_source);
176 if (v == NULL) return;
178 name = vcard_get_prop(v, "n", 1, 0, 0);
185 || ((isalpha(alpha)) && (tolower(alpha) == tolower(this_alpha)) )
186 || ((!isalpha(alpha)) && (!isalpha(this_alpha))) ) {
188 display_parsed_vcard(v, full);
199 * I wanna SEE that message!
201 void read_message(long msgnum) {
203 char mime_partnum[SIZ];
204 char mime_filename[SIZ];
205 char mime_content_type[SIZ];
206 char mime_disposition[SIZ];
218 char vcard_partnum[SIZ];
219 char cal_partnum[SIZ];
220 char *part_source = NULL;
225 strcpy(reply_to, "");
226 strcpy(vcard_partnum, "");
227 strcpy(cal_partnum, "");
228 strcpy(mime_http, "");
230 serv_printf("MSG4 %ld", msgnum);
233 wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
237 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 "
238 "CELLPADDING=1 BGCOLOR=\"#CCCCCC\"><TR><TD>\n");
240 wprintf("<SPAN CLASS=\"message_header\">");
241 strcpy(m_subject, "");
243 while (serv_gets(buf), strcasecmp(buf, "text")) {
244 if (!strcmp(buf, "000")) {
245 wprintf("<I>unexpected end of message</I><BR><BR>\n");
246 wprintf("</SPAN>\n");
249 if (!strncasecmp(buf, "nhdr=yes", 8))
253 if (!strncasecmp(buf, "type=", 5))
254 format_type = atoi(&buf[5]);
255 if (!strncasecmp(buf, "from=", 5)) {
256 strcpy(from, &buf[5]);
257 wprintf("from <A HREF=\"/showuser&who=");
263 if (!strncasecmp(buf, "subj=", 5))
264 strcpy(m_subject, &buf[5]);
265 if ((!strncasecmp(buf, "hnod=", 5))
266 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
267 wprintf("(%s) ", &buf[5]);
268 if ((!strncasecmp(buf, "room=", 5))
269 && (strcasecmp(&buf[5], WC->wc_roomname))
270 && (strlen(&buf[5])>0) )
271 wprintf("in %s> ", &buf[5]);
272 if (!strncasecmp(buf, "rfca=", 5)) {
273 strcpy(rfca, &buf[5]);
279 if (!strncasecmp(buf, "node=", 5)) {
280 strcpy(node, &buf[5]);
281 if ( ((WC->room_flags & QR_NETWORK)
282 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
283 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
286 wprintf("@%s ", &buf[5]);
289 if (!strncasecmp(buf, "rcpt=", 5))
290 wprintf("to %s ", &buf[5]);
291 if (!strncasecmp(buf, "time=", 5)) {
292 fmt_date(now, atol(&buf[5]));
296 if (!strncasecmp(buf, "part=", 5)) {
297 extract(mime_filename, &buf[5], 1);
298 extract(mime_partnum, &buf[5], 2);
299 extract(mime_disposition, &buf[5], 3);
300 extract(mime_content_type, &buf[5], 4);
301 mime_length = extract_int(&buf[5], 5);
303 if (!strcasecmp(mime_disposition, "attachment")) {
304 snprintf(&mime_http[strlen(mime_http)],
305 (sizeof(mime_http) - strlen(mime_http) - 1),
306 "<A HREF=\"/output_mimepart?"
307 "msgnum=%ld&partnum=%s\" "
308 "TARGET=\"wc.%ld.%s\">"
309 "<IMG SRC=\"/static/attachment.gif\" "
310 "BORDER=0 ALIGN=MIDDLE>\n"
311 "Part %s: %s (%s, %d bytes)</A><BR>\n",
312 msgnum, mime_partnum,
313 msgnum, mime_partnum,
314 mime_partnum, mime_filename,
315 mime_content_type, mime_length);
318 if ((!strcasecmp(mime_disposition, "inline"))
319 && (!strncasecmp(mime_content_type, "image/", 6)) ){
320 snprintf(&mime_http[strlen(mime_http)],
321 (sizeof(mime_http) - strlen(mime_http) - 1),
322 "<IMG SRC=\"/output_mimepart?"
323 "msgnum=%ld&partnum=%s\">",
324 msgnum, mime_partnum);
327 /*** begin handler prep ***/
328 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
329 strcpy(vcard_partnum, mime_partnum);
332 if (!strcasecmp(mime_content_type, "text/calendar")) {
333 strcpy(cal_partnum, mime_partnum);
336 /*** end handler prep ***/
342 /* Generate a reply-to address */
343 if (strlen(rfca) > 0) {
344 strcpy(reply_to, rfca);
347 if ( (strlen(node) > 0)
348 && (strcasecmp(node, serv_info.serv_nodename))
349 && (strcasecmp(node, serv_info.serv_humannode)) ) {
350 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
354 snprintf(reply_to, sizeof(reply_to), "%s", from);
362 wprintf("</SPAN></TD>");
364 wprintf("<TD ALIGN=RIGHT>\n"
365 "<TABLE BORDER=0><TR>\n");
367 /*** "Read" button is now superfluous
369 ***wprintf("<TD BGCOLOR=\"#AAAADD\">"
370 *** "<A HREF=\"/readfwd?startmsg=%ld", msgnum);
371 ***wprintf("&maxmsgs=1&summary=0\">Read</A>"
372 *** "</TD>\n", msgnum);
375 wprintf("<TD BGCOLOR=\"#AAAADD\">"
376 "<A HREF=\"/display_enter?recp=");
377 urlescputs(reply_to);
378 wprintf("\"><FONT SIZE=-1>Reply</FONT></A>"
381 if (WC->is_room_aide) {
382 wprintf("<TD BGCOLOR=\"#AAAADD\">"
383 "<A HREF=\"/confirm_move_msg"
385 "\"><FONT SIZE=-1>Move</FONT></A>"
388 wprintf("<TD BGCOLOR=\"#AAAADD\">"
389 "<A HREF=\"/delete_msg"
391 "onClick=\"return confirm('Delete this message?');\""
392 "><FONT SIZE=-1>Del</FONT></A>"
396 wprintf("</TR></TABLE>\n"
399 if (strlen(m_subject) > 0) {
401 "<SPAN CLASS=\"message_subject\">"
404 "</TD><TD> </TD></TR>\n", m_subject);
407 wprintf("</TR></TABLE>\n");
410 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
411 "CELLPADDING=0 CELLSPACING=0><TR><TD>");
414 * Learn the content type
416 strcpy(mime_content_type, "text/plain");
417 while (serv_gets(buf), (strlen(buf) > 0)) {
418 if (!strcmp(buf, "000")) {
419 wprintf("<I>unexpected end of message</I><BR><BR>\n");
422 if (!strncasecmp(buf, "Content-type: ", 14)) {
423 safestrncpy(mime_content_type, &buf[14],
424 sizeof(mime_content_type));
428 /* Messages in legacy Citadel variformat get handled thusly... */
429 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
430 fmout(NULL, "JUSTIFY");
433 /* Boring old 80-column fixed format text gets handled this way... */
434 else if (!strcasecmp(mime_content_type, "text/plain")) {
435 while (serv_gets(buf), strcmp(buf, "000")) {
436 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
437 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
438 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
439 buf[strlen(buf) - 1] = 0;
441 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
442 wprintf("<SPAN CLASS=\"pull_quote\">");
444 } else if ((bq == 1) &&
445 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
452 wprintf("</TT><BR>\n");
457 else /* HTML is fun, but we've got to strip it first */
458 if (!strcasecmp(mime_content_type, "text/html")) {
462 /* Unknown weirdness */
464 wprintf("I don't know how to display %s<BR>\n",
466 while (serv_gets(buf), strcmp(buf, "000")) { }
470 /* Afterwards, offer links to download attachments 'n' such */
471 if (strlen(mime_http) > 0) {
472 wprintf("%s", mime_http);
475 /* Handler for vCard parts */
476 if (strlen(vcard_partnum) > 0) {
477 part_source = load_mimepart(msgnum, vcard_partnum);
478 if (part_source != NULL) {
480 /* If it's my vCard I can edit it */
481 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
482 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))) {
483 wprintf("<A HREF=\"/edit_vcard?"
484 "msgnum=%ld&partnum=%s\">",
485 msgnum, vcard_partnum);
486 wprintf("(edit)</A>");
489 /* In all cases, display the full card */
490 display_vcard(part_source, 0, 1);
494 /* Handler for calendar parts */
495 if (strlen(cal_partnum) > 0) {
496 part_source = load_mimepart(msgnum, cal_partnum);
497 if (part_source != NULL) {
498 cal_process_attachment(part_source,
499 msgnum, cal_partnum);
509 wprintf("</TD></TR></TABLE>\n");
513 void summarize_message(long msgnum) {
524 memset(&summ, 0, sizeof(summ));
525 strcpy(summ.subj, "(no subject)");
527 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
530 if (buf[0] != '1') return;
532 while (serv_gets(buf), strcmp(buf, "000")) {
533 if (!strncasecmp(buf, "from=", 5)) {
534 strcpy(summ.from, &buf[5]);
536 if (!strncasecmp(buf, "subj=", 5)) {
537 strcpy(summ.subj, &buf[5]);
539 if (!strncasecmp(buf, "rfca=", 5)) {
540 strcat(summ.from, " <");
541 strcat(summ.from, &buf[5]);
542 strcat(summ.from, ">");
545 if (!strncasecmp(buf, "node=", 5)) {
546 if ( ((WC->room_flags & QR_NETWORK)
547 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
548 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
550 strcat(summ.from, " @ ");
551 strcat(summ.from, &buf[5]);
555 if (!strncasecmp(buf, "rcpt=", 5)) {
556 strcpy(summ.to, &buf[5]);
559 if (!strncasecmp(buf, "time=", 5)) {
560 fmt_date(summ.date, atol(&buf[5]));
564 wprintf("<TD><A HREF=\"/readfwd?startmsg=%ld"
565 "&maxmsgs=1&summary=0\">",
568 wprintf("</A></TD><TD>");
570 wprintf(" </TD><TD>");
574 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
582 void display_addressbook(long msgnum, char alpha) {
584 char mime_partnum[SIZ];
585 char mime_filename[SIZ];
586 char mime_content_type[SIZ];
587 char mime_disposition[SIZ];
589 char vcard_partnum[SIZ];
590 char *vcard_source = NULL;
600 memset(&summ, 0, sizeof(summ));
601 strcpy(summ.subj, "(no subject)");
603 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
606 if (buf[0] != '1') return;
608 while (serv_gets(buf), strcmp(buf, "000")) {
609 if (!strncasecmp(buf, "part=", 5)) {
610 extract(mime_filename, &buf[5], 1);
611 extract(mime_partnum, &buf[5], 2);
612 extract(mime_disposition, &buf[5], 3);
613 extract(mime_content_type, &buf[5], 4);
614 mime_length = extract_int(&buf[5], 5);
616 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
617 strcpy(vcard_partnum, mime_partnum);
623 if (strlen(vcard_partnum) > 0) {
624 vcard_source = load_mimepart(msgnum, vcard_partnum);
625 if (vcard_source != NULL) {
627 /* Display the summary line */
628 display_vcard(vcard_source, alpha, 0);
630 /* If it's my vCard I can edit it */
631 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
632 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))) {
633 wprintf("<A HREF=\"/edit_vcard?"
634 "msgnum=%ld&partnum=%s\">",
635 msgnum, vcard_partnum);
636 wprintf("(edit)</A>");
648 * load message pointers from the server
650 int load_msg_ptrs(char *servcmd)
659 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
662 while (serv_gets(buf), strcmp(buf, "000")) {
663 WC->msgarr[nummsgs] = atol(buf);
664 /* FIXME check for overflow */
672 * command loop for reading messages
674 void readloop(char *oper)
682 int num_displayed = 0;
684 int is_addressbook = 0;
687 int remaining_messages;
689 int lowest_displayed = (-1);
690 int highest_displayed = 0;
691 long pn_previous = 0L;
692 long pn_current = 0L;
697 startmsg = atol(bstr("startmsg"));
698 maxmsgs = atoi(bstr("maxmsgs"));
699 is_summary = atoi(bstr("summary"));
700 if (maxmsgs == 0) maxmsgs = 20;
704 if (!strcmp(oper, "readnew")) {
705 strcpy(cmd, "MSGS NEW");
706 } else if (!strcmp(oper, "readold")) {
707 strcpy(cmd, "MSGS OLD");
709 strcpy(cmd, "MSGS ALL");
712 /* FIXME put in the correct constant #defs */
713 if ((WC->wc_view == 1) && (maxmsgs > 1)) {
715 strcpy(cmd, "MSGS ALL");
718 if ((WC->wc_view == 2) && (maxmsgs > 1)) {
720 strcpy(cmd, "MSGS ALL");
722 if (bstr("alpha") == NULL) {
726 strcpy(buf, bstr("alpha"));
730 for (i='A'; i<='Z'; ++i) {
731 if (i == alpha) wprintf("<FONT SIZE=+2>"
734 wprintf("<A HREF=\"/readfwd?alpha=%c\">"
739 if (!isalpha(alpha)) wprintf("<FONT SIZE=+2>(other)</FONT>\n");
740 else wprintf("<A HREF=\"/readfwd?alpha=1\">(other)</A>\n");
741 wprintf("<HR width=100%%>\n");
743 if (WC->wc_view == 3) { /* calendar */
745 strcpy(cmd, "MSGS ALL");
748 if (WC->wc_view == 4) { /* tasks */
750 strcpy(cmd, "MSGS ALL");
755 nummsgs = load_msg_ptrs(cmd);
758 if ((!is_tasks) && (!is_calendar)) {
759 if (!strcmp(oper, "readnew")) {
760 wprintf("<EM>No new messages in this room.</EM>\n");
761 } else if (!strcmp(oper, "readold")) {
762 wprintf("<EM>No old messages in this room.</EM>\n");
764 wprintf("<EM>This room is empty.</EM>\n");
771 if (startmsg == 0L) startmsg = WC->msgarr[0];
772 remaining_messages = 0;
774 for (a = 0; a < nummsgs; ++a) {
775 if (WC->msgarr[a] >= startmsg) {
776 ++remaining_messages;
781 wprintf("<FORM METHOD=\"POST\" ACTION=\"/do_stuff_to_msgs\">\n"
782 "<TABLE border=0 cellspacing=0 "
783 "cellpadding=0 width=100%%>\n"
785 "<TD><I>Subject</I></TD>"
786 "<TD><I>Sender</I></TD>"
787 "<TD><I>Date</I></TD>"
793 if (is_addressbook) {
794 wprintf("<TABLE border=0 cellspacing=0 "
795 "cellpadding=0 width=100%%>\n"
799 for (a = 0; a < nummsgs; ++a) {
800 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
802 /* Learn which msgs "Prev" & "Next" buttons go to */
803 pn_current = WC->msgarr[a];
804 if (a > 0) pn_previous = WC->msgarr[a-1];
805 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
807 /* If a tabular view, set up the line */
808 if ( (is_summary) || (is_addressbook) ) {
810 wprintf("<TR BGCOLOR=\"#%s\">",
811 (bg ? "DDDDDD" : "FFFFFF")
815 /* Display the message */
817 summarize_message(WC->msgarr[a]);
819 else if (is_addressbook) {
820 display_addressbook(WC->msgarr[a], alpha);
822 else if (is_calendar) {
823 display_calendar(WC->msgarr[a]);
826 display_task(WC->msgarr[a]);
829 read_message(WC->msgarr[a]);
832 /* If a tabular view, finish the line */
833 if ( (is_summary) || (is_addressbook) ) {
837 if (lowest_displayed < 0) lowest_displayed = a;
838 highest_displayed = a;
841 --remaining_messages;
846 wprintf("</TABLE>\n");
849 if (is_addressbook) {
850 wprintf("</TABLE>\n");
857 /* Bump these because although we're thinking in zero base, the user
858 * is a drooling idiot and is thinking in one base.
863 /* If we're only looking at one message, do a prev/next thing */
864 if (num_displayed == 1) {
865 if ((!is_tasks) && (!is_calendar)) {
868 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=\"#DDDDDD\"><TR><TD>"
869 "Reading #%d of %d messages.</TD>\n"
870 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
871 lowest_displayed, nummsgs);
874 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" "
875 "VALUE=\"Delete selected\">\n");
878 if (pn_previous > 0L) {
879 wprintf("<A HREF=\"/%s"
889 wprintf("<A HREF=\"/%s"
898 wprintf("<A HREF=\"/%s?startmsg=%ld"
899 "&maxmsgs=999999&summary=1\">"
905 wprintf("</TD></TR></TABLE></CENTER>\n");
911 * If we're not currently looking at ALL requested
912 * messages, then display the selector bar
914 if (num_displayed > 1) {
915 if ((!is_tasks) && (!is_calendar)) {
917 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=\"#DDDDDD\"><TR><TD>"
918 "Reading #%d-%d of %d messages.</TD>\n"
919 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
920 lowest_displayed, highest_displayed, nummsgs);
923 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" "
924 "VALUE=\"Delete selected\">\n");
928 for (b=0; b<nummsgs; b = b + maxmsgs) {
931 if (hi > nummsgs) hi = nummsgs;
932 if (WC->msgarr[b] != startmsg) {
933 wprintf("<A HREF=\"/%s"
945 wprintf("%d-%d \n", lo, hi);
949 wprintf("<A HREF=\"/%s?startmsg=%ld"
950 "&maxmsgs=999999&summary=%d\">"
954 WC->msgarr[0], is_summary);
956 wprintf("<A HREF=\"/%s?startmsg=%ld"
957 "&maxmsgs=999999&summary=1\">"
963 wprintf("</TD></TR></TABLE></CENTER>\n");
966 if (is_summary) wprintf("</FORM>\n");
970 wprintf("<A HREF=\"/display_edit_task?msgnum=0\">"
976 do_calendar_view(); /* Render the calendar */
984 * Back end for post_message() ... this is where the actual message
985 * gets transmitted to the server.
987 void post_mime_to_server(void) {
989 int is_multipart = 0;
991 struct wc_attachment *att;
993 size_t encoded_length;
995 /* If there are attachments, we have to do multipart/mixed */
996 if (WC->first_attachment != NULL) {
1001 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
1002 serv_info.serv_fqdn,
1007 /* Remember, serv_printf() appends an extra newline */
1008 serv_printf("Content-type: multipart/mixed; "
1009 "boundary=\"%s\"\n", boundary);
1010 serv_printf("This is a multipart message in MIME format.\n");
1011 serv_printf("--%s", boundary);
1014 serv_puts("Content-type: text/html");
1016 text_to_server(bstr("msgtext"), 1);
1020 /* Add in the attachments */
1021 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1023 encoded_length = ((att->length * 150) / 100);
1024 encoded = malloc(encoded_length);
1025 if (encoded == NULL) break;
1026 CtdlEncodeBase64(encoded, att->data, att->length);
1028 serv_printf("--%s", boundary);
1029 serv_printf("Content-type: %s", att->content_type);
1030 serv_printf("Content-disposition: attachment; "
1031 "filename=\"%s\"", att->filename);
1032 serv_puts("Content-transfer-encoding: base64");
1034 serv_write(encoded, strlen(encoded));
1039 serv_printf("--%s--", boundary);
1047 * Post message (or don't post message)
1049 * Note regarding the "dont_post" variable:
1050 * A random value (actually, it's just a timestamp) is inserted as a hidden
1051 * field called "postseq" when the display_enter page is generated. This
1052 * value is checked when posting, using the static variable dont_post. If a
1053 * user attempts to post twice using the same dont_post value, the message is
1054 * discarded. This prevents the accidental double-saving of the same message
1055 * if the user happens to click the browser "back" button.
1057 void post_message(void)
1060 static long dont_post = (-1L);
1061 struct wc_attachment *att;
1063 if (WC->upload_length > 0) {
1065 att = malloc(sizeof(struct wc_attachment));
1066 memset(att, 0, sizeof(struct wc_attachment));
1067 att->next = WC->first_attachment;
1068 WC->first_attachment = att;
1069 att->length = WC->upload_length;
1070 strcpy(att->content_type, WC->upload_content_type);
1071 strcpy(att->filename, WC->upload_filename);
1073 /* Netscape sends a simple filename, which is what we want,
1074 * but Satan's browser sends an entire pathname. Reduce
1075 * the path to just a filename if we need to.
1077 while (num_tokens(att->filename, '/') > 1) {
1078 remove_token(att->filename, 0, '/');
1080 while (num_tokens(att->filename, '\\') > 1) {
1081 remove_token(att->filename, 0, '\\');
1084 /* Transfer control of this memory from the upload struct
1085 * to the attachment struct.
1087 att->data = WC->upload;
1088 WC->upload_length = 0;
1094 if (strcasecmp(bstr("sc"), "Save message")) {
1095 sprintf(WC->ImportantMessage,
1096 "Cancelled. Message was not posted.");
1097 } else if (atol(bstr("postseq")) == dont_post) {
1098 sprintf(WC->ImportantMessage,
1099 "Automatically cancelled because you have already "
1100 "saved this message.");
1102 sprintf(buf, "ENT0 1|%s|0|4|%s",
1107 if (buf[0] == '4') {
1108 post_mime_to_server();
1109 sprintf(WC->ImportantMessage,
1110 "Message has been posted.\n");
1111 dont_post = atol(bstr("postseq"));
1113 sprintf(WC->ImportantMessage,
1118 free_attachments(WC);
1119 readloop("readnew");
1126 * display the message entry screen
1128 void display_enter(void)
1132 struct wc_attachment *att;
1136 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
1140 if (!strncmp(buf, "570", 3)) {
1141 if (strlen(bstr("recp")) > 0) {
1142 svprintf("RECPERROR", WCS_STRING,
1143 "<SPAN CLASS=\"errormsg\">%s</SPAN><BR>\n",
1147 do_template("prompt_for_recipient");
1150 if (buf[0] != '2') {
1151 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
1157 strcat(&buf[strlen(buf)], " <I>from</I> ");
1158 stresc(&buf[strlen(buf)], WC->wc_username, 1);
1159 if (strlen(bstr("recp")) > 0) {
1160 strcat(&buf[strlen(buf)], " <I>to</I> ");
1161 stresc(&buf[strlen(buf)], bstr("recp"), 1);
1163 strcat(&buf[strlen(buf)], " <I>in</I> ");
1164 stresc(&buf[strlen(buf)], WC->wc_roomname, 1);
1165 svprintf("BOXTITLE", WCS_STRING, buf);
1166 do_template("beginbox");
1168 wprintf("<CENTER>\n");
1170 wprintf("<FORM ENCTYPE=\"multipart/form-data\" "
1171 "METHOD=\"POST\" ACTION=\"/post\" "
1172 "NAME=\"enterform\">\n");
1173 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
1175 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
1177 wprintf("<IMG SRC=\"static/enter.gif\" ALIGN=MIDDLE ALT=\" \" "
1178 "onLoad=\"document.enterform.msgtext.focus();\" >");
1179 wprintf("<FONT SIZE=-1>Subject (optional):</FONT>"
1180 "<INPUT TYPE=\"text\" NAME=\"subject\" VALUE=\"");
1181 escputs(bstr("subject"));
1182 wprintf("\" MAXLENGTH=70>"
1183 " "
1184 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
1185 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
1187 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=25 COLS=80 "
1189 escputs(bstr("msgtext"));
1190 wprintf("</TEXTAREA><BR>\n");
1192 /* Enumerate any attachments which are already in place... */
1193 for (att = WC->first_attachment; att != NULL; att = att->next) {
1194 wprintf("<IMG SRC=\"/static/attachment.gif\" "
1195 "BORDER=0 ALIGN=MIDDLE> Attachment: ");
1196 escputs(att->filename);
1197 wprintf(" (%s, %d bytes)<BR>\n",
1198 att->content_type, att->length);
1201 /* Now offer the ability to attach additional files... */
1202 wprintf("Attach file: <input NAME=\"attachfile\" "
1203 "SIZE=48 TYPE=\"file\">\n "
1204 "<input type=\"submit\" name=\"attach\" value=\"Add\">\n");
1206 wprintf("</FORM></CENTER>\n");
1207 do_template("endbox");
1208 DONE: wDumpContent(1);
1218 void delete_msg(void)
1223 msgid = atol(bstr("msgid"));
1227 sprintf(buf, "DELE %ld", msgid);
1230 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
1239 * Confirm move of a message
1241 void confirm_move_msg(void)
1247 msgid = atol(bstr("msgid"));
1251 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1252 wprintf("<FONT SIZE=+1 COLOR=\"#FFFFFF\"");
1253 wprintf("<B>Confirm move of message</B>\n");
1254 wprintf("</FONT></TD></TR></TABLE>\n");
1256 wprintf("<CENTER>");
1258 wprintf("Please select the room to which you would like this message moved:<BR>\n");
1260 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
1261 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
1265 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1268 if (buf[0] == '1') {
1269 while (serv_gets(buf), strcmp(buf, "000")) {
1270 extract(targ, buf, 0);
1271 wprintf("<OPTION>");
1276 wprintf("</SELECT>\n");
1279 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
1280 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
1281 wprintf("</FORM></CENTER>\n");
1283 wprintf("</CENTER>\n");
1294 msgid = atol(bstr("msgid"));
1298 if (!strcasecmp(bstr("yesno"), "Move")) {
1299 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1302 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
1304 wprintf("<EM>Message not moved.</EM><BR>\n");
1312 void do_stuff_to_msgs(void) {
1317 struct stuff_t *next;
1321 struct stuff_t *stuff = NULL;
1322 struct stuff_t *ptr;
1325 serv_puts("MSGS ALL");
1328 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
1329 ptr = malloc(sizeof(struct stuff_t));
1330 ptr->msgnum = atol(buf);
1335 strcpy(sc, bstr("sc"));
1337 while (stuff != NULL) {
1339 sprintf(buf, "msg_%ld", stuff->msgnum);
1340 if (!strcasecmp(bstr(buf), "yes")) {
1342 if (!strcasecmp(sc, "Delete selected")) {
1343 serv_printf("DELE %ld", stuff->msgnum);
1354 readloop("readfwd");