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 if ( ((WC->room_flags & QR_NETWORK)
281 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
282 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
285 wprintf("@%s ", &buf[5]);
288 if (!strncasecmp(buf, "rcpt=", 5))
289 wprintf("to %s ", &buf[5]);
290 if (!strncasecmp(buf, "time=", 5)) {
291 fmt_date(now, atol(&buf[5]));
295 if (!strncasecmp(buf, "part=", 5)) {
296 extract(mime_filename, &buf[5], 1);
297 extract(mime_partnum, &buf[5], 2);
298 extract(mime_disposition, &buf[5], 3);
299 extract(mime_content_type, &buf[5], 4);
300 mime_length = extract_int(&buf[5], 5);
302 if (!strcasecmp(mime_disposition, "attachment")) {
303 snprintf(&mime_http[strlen(mime_http)],
304 (sizeof(mime_http) - strlen(mime_http) - 1),
305 "<A HREF=\"/output_mimepart?"
306 "msgnum=%ld&partnum=%s\" "
307 "TARGET=\"wc.%ld.%s\">"
308 "<IMG SRC=\"/static/attachment.gif\" "
309 "BORDER=0 ALIGN=MIDDLE>\n"
310 "Part %s: %s (%s, %d bytes)</A><BR>\n",
311 msgnum, mime_partnum,
312 msgnum, mime_partnum,
313 mime_partnum, mime_filename,
314 mime_content_type, mime_length);
317 if ((!strcasecmp(mime_disposition, "inline"))
318 && (!strncasecmp(mime_content_type, "image/", 6)) ){
319 snprintf(&mime_http[strlen(mime_http)],
320 (sizeof(mime_http) - strlen(mime_http) - 1),
321 "<IMG SRC=\"/output_mimepart?"
322 "msgnum=%ld&partnum=%s\">",
323 msgnum, mime_partnum);
326 /*** begin handler prep ***/
327 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
328 strcpy(vcard_partnum, mime_partnum);
331 if (!strcasecmp(mime_content_type, "text/calendar")) {
332 strcpy(cal_partnum, mime_partnum);
335 /*** end handler prep ***/
341 /* Generate a reply-to address */
342 if (strlen(rfca) > 0) {
343 strcpy(reply_to, rfca);
346 if (strlen(node) > 0) {
347 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
351 snprintf(reply_to, sizeof(reply_to), "%s", from);
359 wprintf("</SPAN></TD>");
361 wprintf("<TD ALIGN=RIGHT>\n"
362 "<TABLE BORDER=0><TR>\n");
364 wprintf("<TD BGCOLOR=\"#AAAADD\">"
365 "<A HREF=\"/readfwd?startmsg=%ld", msgnum);
366 wprintf("&maxmsgs=1&summary=0\">Read</A>"
369 wprintf("<TD BGCOLOR=\"#AAAADD\">"
370 "<A HREF=\"/display_enter?recp=");
371 urlescputs(reply_to);
372 wprintf("\"><FONT SIZE=-1>Reply</FONT></A>"
375 if (WC->is_room_aide) {
376 wprintf("<TD BGCOLOR=\"#AAAADD\">"
377 "<A HREF=\"/confirm_move_msg"
379 "\"><FONT SIZE=-1>Move</FONT></A>"
382 wprintf("<TD BGCOLOR=\"#AAAADD\">"
383 "<A HREF=\"/delete_msg"
385 "onClick=\"return confirm('Delete this message?');\""
386 "><FONT SIZE=-1>Del</FONT></A>"
390 wprintf("</TR></TABLE>\n"
393 if (strlen(m_subject) > 0) {
395 "<SPAN CLASS=\"message_subject\">"
398 "</TD><TD> </TD></TR>\n", m_subject);
401 wprintf("</TR></TABLE>\n");
404 wprintf("<TABLE BORDER=0 WIDTH=100%% BGCOLOR=#FFFFFF "
405 "CELLPADDING=0 CELLSPACING=0><TR><TD>");
408 * Learn the content type
410 strcpy(mime_content_type, "text/plain");
411 while (serv_gets(buf), (strlen(buf) > 0)) {
412 if (!strcmp(buf, "000")) {
413 wprintf("<I>unexpected end of message</I><BR><BR>\n");
416 if (!strncasecmp(buf, "Content-type: ", 14)) {
417 safestrncpy(mime_content_type, &buf[14],
418 sizeof(mime_content_type));
422 /* Messages in legacy Citadel variformat get handled thusly... */
423 if (!strcasecmp(mime_content_type, "text/x-citadel-variformat")) {
427 /* Boring old 80-column fixed format text gets handled this way... */
428 else if (!strcasecmp(mime_content_type, "text/plain")) {
429 while (serv_gets(buf), strcmp(buf, "000")) {
430 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = 0;
431 if (buf[strlen(buf)-1] == '\r') buf[strlen(buf)-1] = 0;
432 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
433 buf[strlen(buf) - 1] = 0;
435 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
436 wprintf("<SPAN CLASS=\"pull_quote\">");
438 } else if ((bq == 1) &&
439 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
446 wprintf("</TT><BR>\n");
451 else /* HTML is fun, but we've got to strip it first */
452 if (!strcasecmp(mime_content_type, "text/html")) {
456 /* Unknown weirdness */
458 wprintf("I don't know how to display %s<BR>\n",
460 while (serv_gets(buf), strcmp(buf, "000")) { }
464 /* Afterwards, offer links to download attachments 'n' such */
465 if (strlen(mime_http) > 0) {
466 wprintf("%s", mime_http);
469 /* Handler for vCard parts */
470 if (strlen(vcard_partnum) > 0) {
471 part_source = load_mimepart(msgnum, vcard_partnum);
472 if (part_source != NULL) {
474 /* If it's my vCard I can edit it */
475 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
476 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))) {
477 wprintf("<A HREF=\"/edit_vcard?"
478 "msgnum=%ld&partnum=%s\">",
479 msgnum, vcard_partnum);
480 wprintf("(edit)</A>");
483 /* In all cases, display the full card */
484 display_vcard(part_source, 0, 1);
488 /* Handler for calendar parts */
489 if (strlen(cal_partnum) > 0) {
490 part_source = load_mimepart(msgnum, cal_partnum);
491 if (part_source != NULL) {
492 cal_process_attachment(part_source,
493 msgnum, cal_partnum);
503 wprintf("</TD></TR></TABLE>\n");
507 void summarize_message(long msgnum) {
518 memset(&summ, 0, sizeof(summ));
519 strcpy(summ.subj, "(no subject)");
521 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
524 if (buf[0] != '1') return;
526 while (serv_gets(buf), strcmp(buf, "000")) {
527 if (!strncasecmp(buf, "from=", 5)) {
528 strcpy(summ.from, &buf[5]);
530 if (!strncasecmp(buf, "subj=", 5)) {
531 strcpy(summ.subj, &buf[5]);
533 if (!strncasecmp(buf, "rfca=", 5)) {
534 strcat(summ.from, " <");
535 strcat(summ.from, &buf[5]);
536 strcat(summ.from, ">");
539 if (!strncasecmp(buf, "node=", 5)) {
540 if ( ((WC->room_flags & QR_NETWORK)
541 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
542 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
544 strcat(summ.from, " @ ");
545 strcat(summ.from, &buf[5]);
549 if (!strncasecmp(buf, "rcpt=", 5)) {
550 strcpy(summ.to, &buf[5]);
553 if (!strncasecmp(buf, "time=", 5)) {
554 fmt_date(summ.date, atol(&buf[5]));
558 wprintf("<TD><A HREF=\"/readfwd?startmsg=%ld"
559 "&maxmsgs=1&summary=0\">",
562 wprintf("</A></TD><TD>");
564 wprintf(" </TD><TD>");
568 "<INPUT TYPE=\"checkbox\" NAME=\"msg_%ld\" VALUE=\"yes\">"
576 void display_addressbook(long msgnum, char alpha) {
578 char mime_partnum[SIZ];
579 char mime_filename[SIZ];
580 char mime_content_type[SIZ];
581 char mime_disposition[SIZ];
583 char vcard_partnum[SIZ];
584 char *vcard_source = NULL;
594 memset(&summ, 0, sizeof(summ));
595 strcpy(summ.subj, "(no subject)");
597 sprintf(buf, "MSG0 %ld|1", msgnum); /* ask for headers only */
600 if (buf[0] != '1') return;
602 while (serv_gets(buf), strcmp(buf, "000")) {
603 if (!strncasecmp(buf, "part=", 5)) {
604 extract(mime_filename, &buf[5], 1);
605 extract(mime_partnum, &buf[5], 2);
606 extract(mime_disposition, &buf[5], 3);
607 extract(mime_content_type, &buf[5], 4);
608 mime_length = extract_int(&buf[5], 5);
610 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
611 strcpy(vcard_partnum, mime_partnum);
617 if (strlen(vcard_partnum) > 0) {
618 vcard_source = load_mimepart(msgnum, vcard_partnum);
619 if (vcard_source != NULL) {
621 /* Display the summary line */
622 display_vcard(vcard_source, alpha, 0);
624 /* If it's my vCard I can edit it */
625 if ( (!strcasecmp(WC->wc_roomname, USERCONFIGROOM))
626 || (!strcasecmp(&WC->wc_roomname[11], USERCONFIGROOM))) {
627 wprintf("<A HREF=\"/edit_vcard?"
628 "msgnum=%ld&partnum=%s\">",
629 msgnum, vcard_partnum);
630 wprintf("(edit)</A>");
642 * load message pointers from the server
644 int load_msg_ptrs(char *servcmd)
653 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
656 while (serv_gets(buf), strcmp(buf, "000")) {
657 WC->msgarr[nummsgs] = atol(buf);
658 /* FIXME check for overflow */
666 * command loop for reading messages
668 void readloop(char *oper)
676 int num_displayed = 0;
678 int is_addressbook = 0;
681 int remaining_messages;
683 int lowest_displayed = (-1);
684 int highest_displayed = 0;
685 long pn_previous = 0L;
686 long pn_current = 0L;
691 startmsg = atol(bstr("startmsg"));
692 maxmsgs = atoi(bstr("maxmsgs"));
693 is_summary = atoi(bstr("summary"));
694 if (maxmsgs == 0) maxmsgs = 20;
698 if (!strcmp(oper, "readnew")) {
699 strcpy(cmd, "MSGS NEW");
700 } else if (!strcmp(oper, "readold")) {
701 strcpy(cmd, "MSGS OLD");
703 strcpy(cmd, "MSGS ALL");
706 /* FIXME put in the correct constant #defs */
707 if ((WC->wc_view == 1) && (maxmsgs > 1)) {
709 strcpy(cmd, "MSGS ALL");
712 if ((WC->wc_view == 2) && (maxmsgs > 1)) {
714 strcpy(cmd, "MSGS ALL");
716 if (bstr("alpha") == NULL) {
720 strcpy(buf, bstr("alpha"));
724 for (i='A'; i<='Z'; ++i) {
725 if (i == alpha) wprintf("<FONT SIZE=+2>"
728 wprintf("<A HREF=\"/readfwd?alpha=%c\">"
733 if (!isalpha(alpha)) wprintf("<FONT SIZE=+2>(other)</FONT>\n");
734 else wprintf("<A HREF=\"/readfwd?alpha=1\">(other)</A>\n");
735 wprintf("<HR width=100%%>\n");
737 if (WC->wc_view == 3) { /* calendar */
739 strcpy(cmd, "MSGS ALL");
742 if (WC->wc_view == 4) { /* tasks */
744 strcpy(cmd, "MSGS ALL");
749 nummsgs = load_msg_ptrs(cmd);
752 if ((!is_tasks) && (!is_calendar)) {
753 if (!strcmp(oper, "readnew")) {
754 wprintf("<EM>No new messages in this room.</EM>\n");
755 } else if (!strcmp(oper, "readold")) {
756 wprintf("<EM>No old messages in this room.</EM>\n");
758 wprintf("<EM>This room is empty.</EM>\n");
765 if (startmsg == 0L) startmsg = WC->msgarr[0];
766 remaining_messages = 0;
768 for (a = 0; a < nummsgs; ++a) {
769 if (WC->msgarr[a] >= startmsg) {
770 ++remaining_messages;
775 wprintf("<FORM METHOD=\"POST\" ACTION=\"/do_stuff_to_msgs\">\n"
776 "<TABLE border=0 cellspacing=0 "
777 "cellpadding=0 width=100%%>\n"
779 "<TD><I>Subject</I></TD>"
780 "<TD><I>Sender</I></TD>"
781 "<TD><I>Date</I></TD>"
787 if (is_addressbook) {
788 wprintf("<TABLE border=0 cellspacing=0 "
789 "cellpadding=0 width=100%%>\n"
793 for (a = 0; a < nummsgs; ++a) {
794 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
796 /* Learn which msgs "Prev" & "Next" buttons go to */
797 pn_current = WC->msgarr[a];
798 if (a > 0) pn_previous = WC->msgarr[a-1];
799 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
801 /* If a tabular view, set up the line */
802 if ( (is_summary) || (is_addressbook) ) {
804 wprintf("<TR BGCOLOR=\"#%s\">",
805 (bg ? "DDDDDD" : "FFFFFF")
809 /* Display the message */
811 summarize_message(WC->msgarr[a]);
813 else if (is_addressbook) {
814 display_addressbook(WC->msgarr[a], alpha);
816 else if (is_calendar) {
817 display_calendar(WC->msgarr[a]);
820 display_task(WC->msgarr[a]);
823 read_message(WC->msgarr[a]);
826 /* If a tabular view, finish the line */
827 if ( (is_summary) || (is_addressbook) ) {
831 if (lowest_displayed < 0) lowest_displayed = a;
832 highest_displayed = a;
835 --remaining_messages;
840 wprintf("</TABLE>\n");
843 if (is_addressbook) {
844 wprintf("</TABLE>\n");
851 /* Bump these because although we're thinking in zero base, the user
852 * is a drooling idiot and is thinking in one base.
857 /* If we're only looking at one message, do a prev/next thing */
858 if (num_displayed == 1) {
859 if ((!is_tasks) && (!is_calendar)) {
862 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=\"#DDDDDD\"><TR><TD>"
863 "Reading #%d of %d messages.</TD>\n"
864 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
865 lowest_displayed, nummsgs);
868 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" "
869 "VALUE=\"Delete selected\">\n");
872 if (pn_previous > 0L) {
873 wprintf("<A HREF=\"/%s"
883 wprintf("<A HREF=\"/%s"
892 wprintf("<A HREF=\"/%s?startmsg=%ld"
893 "&maxmsgs=999999&summary=1\">"
899 wprintf("</TD></TR></TABLE></CENTER>\n");
905 * If we're not currently looking at ALL requested
906 * messages, then display the selector bar
908 if (num_displayed > 1) {
909 if ((!is_tasks) && (!is_calendar)) {
911 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=\"#DDDDDD\"><TR><TD>"
912 "Reading #%d-%d of %d messages.</TD>\n"
913 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
914 lowest_displayed, highest_displayed, nummsgs);
917 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" "
918 "VALUE=\"Delete selected\">\n");
922 for (b=0; b<nummsgs; b = b + maxmsgs) {
925 if (hi > nummsgs) hi = nummsgs;
926 if (WC->msgarr[b] != startmsg) {
927 wprintf("<A HREF=\"/%s"
939 wprintf("%d-%d \n", lo, hi);
943 wprintf("<A HREF=\"/%s?startmsg=%ld"
944 "&maxmsgs=999999&summary=%d\">"
948 WC->msgarr[0], is_summary);
950 wprintf("<A HREF=\"/%s?startmsg=%ld"
951 "&maxmsgs=999999&summary=1\">"
957 wprintf("</TD></TR></TABLE></CENTER>\n");
960 if (is_summary) wprintf("</FORM>\n");
964 wprintf("<A HREF=\"/display_edit_task?msgnum=0\">"
970 do_calendar_view(); /* Render the calendar */
978 * Back end for post_message() ... this is where the actual message
979 * gets transmitted to the server.
981 void post_mime_to_server(void) {
983 int is_multipart = 0;
985 struct wc_attachment *att;
987 size_t encoded_length;
989 /* If there are attachments, we have to do multipart/mixed */
990 if (WC->first_attachment != NULL) {
995 sprintf(boundary, "---Citadel-Multipart-%s-%04x%04x---",
1001 /* Remember, serv_printf() appends an extra newline */
1002 serv_printf("Content-type: multipart/mixed; "
1003 "boundary=\"%s\"\n", boundary);
1004 serv_printf("This is a multipart message in MIME format.\n");
1005 serv_printf("--%s", boundary);
1008 serv_puts("Content-type: text/html");
1010 text_to_server(bstr("msgtext"), 1);
1014 /* Add in the attachments */
1015 for (att = WC->first_attachment; att!=NULL; att=att->next) {
1017 encoded_length = ((att->length * 150) / 100);
1018 encoded = malloc(encoded_length);
1019 if (encoded == NULL) break;
1020 CtdlEncodeBase64(encoded, att->data, att->length);
1022 serv_printf("--%s", boundary);
1023 serv_printf("Content-type: %s", att->content_type);
1024 serv_printf("Content-disposition: attachment; "
1025 "filename=\"%s\"", att->filename);
1026 serv_puts("Content-transfer-encoding: base64");
1028 serv_write(encoded, strlen(encoded));
1033 serv_printf("--%s--", boundary);
1041 * Post message (or don't post message)
1043 * Note regarding the "dont_post" variable:
1044 * A random value (actually, it's just a timestamp) is inserted as a hidden
1045 * field called "postseq" when the display_enter page is generated. This
1046 * value is checked when posting, using the static variable dont_post. If a
1047 * user attempts to post twice using the same dont_post value, the message is
1048 * discarded. This prevents the accidental double-saving of the same message
1049 * if the user happens to click the browser "back" button.
1051 void post_message(void)
1054 static long dont_post = (-1L);
1055 struct wc_attachment *att;
1057 if (WC->upload_length > 0) {
1059 att = malloc(sizeof(struct wc_attachment));
1060 memset(att, 0, sizeof(struct wc_attachment));
1061 att->next = WC->first_attachment;
1062 WC->first_attachment = att;
1063 att->length = WC->upload_length;
1064 strcpy(att->content_type, WC->upload_content_type);
1065 strcpy(att->filename, WC->upload_filename);
1067 /* Netscape sends a simple filename, which is what we want,
1068 * but Satan's browser sends an entire pathname. Reduce
1069 * the path to just a filename if we need to.
1071 while (num_tokens(att->filename, '/') > 1) {
1072 remove_token(att->filename, 0, '/');
1074 while (num_tokens(att->filename, '\\') > 1) {
1075 remove_token(att->filename, 0, '\\');
1078 /* Transfer control of this memory from the upload struct
1079 * to the attachment struct.
1081 att->data = WC->upload;
1082 WC->upload_length = 0;
1090 if (strcasecmp(bstr("sc"), "Save message")) {
1091 wprintf("Cancelled. Message was not posted.<BR>\n");
1092 } else if (atol(bstr("postseq")) == dont_post) {
1093 wprintf("Automatically cancelled because you have already "
1094 "saved this message.<BR>\n");
1096 sprintf(buf, "ENT0 1|%s|0|4|%s",
1101 if (buf[0] == '4') {
1102 post_mime_to_server();
1103 wprintf("Message has been posted.<BR>\n");
1104 dont_post = atol(bstr("postseq"));
1106 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
1111 free_attachments(WC);
1118 * display the message entry screen
1120 void display_enter(void)
1125 struct wc_attachment *att;
1129 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
1133 if (!strncmp(buf, "570", 3)) {
1134 if (strlen(bstr("recp")) > 0) {
1135 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
1137 do_template("prompt_for_recipient");
1140 if (buf[0] != '2') {
1141 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
1146 tm = (struct tm *) localtime(&now);
1147 strcpy(buf, (char *) asctime(tm));
1148 buf[strlen(buf) - 1] = 0;
1149 strcpy(&buf[16], &buf[19]);
1150 wprintf("</CENTER><FONT COLOR=\"#440000\">\n"
1151 "<IMG SRC=\"static/enter.gif\" ALIGN=MIDDLE ALT=\" \" "
1152 "onLoad=\"document.enterform.msgtext.focus();\" >");
1153 wprintf("<B> %s ", &buf[4]);
1154 wprintf("from %s ", WC->wc_username);
1155 if (strlen(bstr("recp")) > 0)
1156 wprintf("to %s ", bstr("recp"));
1157 wprintf("in %s> ", WC->wc_roomname);
1158 wprintf("</B></FONT><BR><CENTER>\n");
1160 wprintf("<FORM ENCTYPE=\"multipart/form-data\" "
1161 "METHOD=\"POST\" ACTION=\"/post\" "
1162 "NAME=\"enterform\">\n");
1163 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
1165 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
1167 wprintf("<FONT SIZE=-1>Subject (optional):</FONT>"
1168 "<INPUT TYPE=\"text\" NAME=\"subject\" VALUE=\"");
1169 escputs(bstr("subject"));
1170 wprintf("\" MAXLENGTH=70>"
1171 " "
1172 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
1173 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
1175 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
1177 escputs(bstr("msgtext"));
1178 wprintf("</TEXTAREA><BR>\n");
1180 /* Enumerate any attachments which are already in place... */
1181 for (att = WC->first_attachment; att != NULL; att = att->next) {
1182 wprintf("<IMG SRC=\"/static/attachment.gif\" "
1183 "BORDER=0 ALIGN=MIDDLE> Attachment: ");
1184 escputs(att->filename);
1185 wprintf(" (%s, %d bytes)<BR>\n",
1186 att->content_type, att->length);
1189 /* Now offer the ability to attach additional files... */
1190 wprintf("Attach file: <input NAME=\"attachfile\" "
1191 "SIZE=48 TYPE=\"file\">\n "
1192 "<input type=\"submit\" name=\"attach\" value=\"Add\">\n");
1194 wprintf("</FORM></CENTER>\n");
1195 DONE: wDumpContent(1);
1206 void delete_msg(void)
1211 msgid = atol(bstr("msgid"));
1215 sprintf(buf, "DELE %ld", msgid);
1218 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
1227 * Confirm move of a message
1229 void confirm_move_msg(void)
1235 msgid = atol(bstr("msgid"));
1239 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=\"#770000\"><TR><TD>");
1240 wprintf("<FONT SIZE=+1 COLOR=\"#FFFFFF\"");
1241 wprintf("<B>Confirm move of message</B>\n");
1242 wprintf("</FONT></TD></TR></TABLE>\n");
1244 wprintf("<CENTER>");
1246 wprintf("Please select the room to which you would like this message moved:<BR>\n");
1248 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
1249 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
1253 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
1256 if (buf[0] == '1') {
1257 while (serv_gets(buf), strcmp(buf, "000")) {
1258 extract(targ, buf, 0);
1259 wprintf("<OPTION>");
1264 wprintf("</SELECT>\n");
1267 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
1268 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
1269 wprintf("</FORM></CENTER>\n");
1271 wprintf("</CENTER>\n");
1282 msgid = atol(bstr("msgid"));
1286 if (!strcasecmp(bstr("yesno"), "Move")) {
1287 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
1290 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
1292 wprintf("<EM>Message not moved.</EM><BR>\n");
1300 void do_stuff_to_msgs(void) {
1305 struct stuff_t *next;
1309 struct stuff_t *stuff = NULL;
1310 struct stuff_t *ptr;
1313 serv_puts("MSGS ALL");
1316 if (buf[0] == '1') while (serv_gets(buf), strcmp(buf, "000")) {
1317 ptr = malloc(sizeof(struct stuff_t));
1318 ptr->msgnum = atol(buf);
1323 strcpy(sc, bstr("sc"));
1325 while (stuff != NULL) {
1327 sprintf(buf, "msg_%ld", stuff->msgnum);
1328 if (!strcasecmp(bstr(buf), "yes")) {
1330 if (!strcasecmp(sc, "Delete selected")) {
1331 serv_printf("DELE %ld", stuff->msgnum);
1342 readloop("readfwd");