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>
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.
48 for (pos = 0; pos < strlen(buf); ++pos) {
49 if (!strncasecmp(&buf[pos], "http://", 7))
51 if (!strncasecmp(&buf[pos], "ftp://", 6))
58 if ((start > 0) && (buf[start - 1] == '<'))
60 if ((start > 0) && (buf[start - 1] == '['))
62 if ((start > 0) && (buf[start - 1] == '('))
64 if ((start > 0) && (buf[start - 1] == '{'))
67 for (pos = strlen(buf); pos > start; --pos) {
68 if ((buf[pos] == ' ') || (buf[pos] == ench))
72 strncpy(urlbuf, &buf[start], end - start);
73 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 )
88 * Experimental output type of thing
90 void display_vcard(char *vcard_source) {
95 v = vcard_load(vcard_source);
96 if (v == NULL) return;
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");
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);
113 escputs(v->prop[i].value);
114 wprintf("</A></TD></TR>\n");
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) {
125 wprintf("</TD></TR>\n");
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) {
137 wprintf("</TD></TR>\n");
141 escputs(v->prop[i].name);
142 wprintf("</TD><TD>");
143 escputs(v->prop[i].value);
144 wprintf("</TD></TR>\n");
148 wprintf("</TABLE>\n");
158 void read_message(long msgnum, int is_summary) {
160 char mime_partnum[SIZ];
161 char mime_filename[SIZ];
162 char mime_content_type[SIZ];
163 char mime_disposition[SIZ];
165 char *mime_http = NULL;
175 char vcard_partnum[SIZ];
176 char *vcard_source = NULL;
181 strcpy(reply_to, "");
182 strcpy(vcard_partnum, "");
184 sprintf(buf, "MSG0 %ld", msgnum);
188 wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
191 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 CELLPADDING=1 BGCOLOR=CCCCCC><TR><TD>\n");
193 if (!is_summary) wprintf("SIZE=+1 ");
194 wprintf("COLOR=\"000000\"> ");
195 strcpy(m_subject, "");
197 while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
198 if (!strncasecmp(buf, "nhdr=yes", 8))
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=");
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]);
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)))))
233 wprintf("@%s ", &buf[5]);
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]));
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);
250 if (!strcasecmp(mime_disposition, "attachment")) {
251 if (mime_http == NULL) {
252 mime_http = malloc(512);
253 strcpy(mime_http, "");
256 mime_http = realloc(mime_http,
257 strlen(mime_http) + 512);
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);
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, "");
279 mime_http = realloc(mime_http,
280 strlen(mime_http) + 512);
282 sprintf(&mime_http[strlen(mime_http)],
283 "<IMG SRC=\"/output_mimepart?"
284 "msgnum=%ld&partnum=%s\">",
285 msgnum, mime_partnum);
288 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
289 strcpy(vcard_partnum, mime_partnum);
297 /* Generate a reply-to address */
298 if (strlen(rfca) > 0) {
299 strcpy(reply_to, rfca);
302 if (strlen(node) > 0) {
303 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
307 snprintf(reply_to, sizeof(reply_to), "%s", from);
313 wprintf("</FONT></TD>");
315 /* begin right-hand toolbar */
316 wprintf("<TD ALIGN=RIGHT>\n"
317 "<TABLE BORDER=0><TR>\n");
320 wprintf("<TD BGCOLOR=\"AAAADD\">"
321 "<A HREF=\"/readfwd?startmsg=%ld", msgnum);
322 wprintf("&maxmsgs=1&summary=0\">Read</A>"
326 wprintf("<TD BGCOLOR=\"AAAADD\">"
327 "<A HREF=\"/display_enter?recp=");
328 urlescputs(reply_to);
329 wprintf("\"><FONT SIZE=-1>Reply</FONT></A>"
332 if (WC->is_room_aide) {
333 wprintf("<TD BGCOLOR=\"AAAADD\">"
334 "<A HREF=\"/confirm_move_msg"
336 "\"><FONT SIZE=-1>Move</FONT></A>"
339 wprintf("<TD BGCOLOR=\"AAAADD\">"
340 "<A HREF=\"/delete_msg"
342 "onClick=\"return confirm('Delete this message?');\""
343 "><FONT SIZE=-1>Del</FONT></A>"
347 wprintf("</TR></TABLE>\n"
350 /* end right-hand toolbar */
353 if (strlen(m_subject) > 0) {
354 wprintf("<TR><TD><FONT COLOR=\"0000FF\">"
356 "</TD><TD> </TD></TR>\n", m_subject);
359 wprintf("</TR></TABLE>\n");
362 while (serv_gets(buf), strcmp(buf, "000")) ;
366 if (format_type == 0) {
369 while (serv_gets(buf), strcmp(buf, "000")) {
370 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
371 buf[strlen(buf) - 1] = 0;
373 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
374 wprintf("<FONT COLOR=\"000044\"><I>");
376 } else if ((bq == 1) &&
377 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
378 wprintf("</FONT></I>");
384 wprintf("</TT><BR>\n");
389 if (mime_http != NULL) {
390 wprintf("%s", mime_http);
394 if (strlen(vcard_partnum) > 0) {
395 vcard_source = load_mimepart(msgnum, vcard_partnum);
396 if (vcard_source != NULL) {
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>");
407 /* In all cases, display it */
408 display_vcard(vcard_source);
418 * load message pointers from the server
420 int load_msg_ptrs(servcmd)
430 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
433 while (serv_gets(buf), strcmp(buf, "000")) {
434 WC->msgarr[nummsgs] = atol(buf);
442 * command loop for reading messages
444 void readloop(char *oper)
451 int num_displayed = 0;
453 int remaining_messages;
455 int lowest_displayed = 0;
456 int highest_displayed = 0;
457 long pn_previous = 0L;
458 long pn_current = 0L;
461 startmsg = atol(bstr("startmsg"));
462 maxmsgs = atoi(bstr("maxmsgs"));
463 is_summary = atoi(bstr("summary"));
464 if (maxmsgs == 0) maxmsgs = 20;
466 /* FIXME put in the correct constant #defs */
467 if ((is_summary == 0) && (WC->wc_view == 1)) is_summary = 1;
471 if (!strcmp(oper, "readnew")) {
472 strcpy(cmd, "MSGS NEW");
473 } else if (!strcmp(oper, "readold")) {
474 strcpy(cmd, "MSGS OLD");
476 strcpy(cmd, "MSGS ALL");
479 nummsgs = load_msg_ptrs(cmd);
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");
486 wprintf("<EM>This room is empty.</EM>\n");
491 if (startmsg == 0L) startmsg = WC->msgarr[0];
492 remaining_messages = 0;
494 for (a = 0; a < nummsgs; ++a) {
495 if (WC->msgarr[a] >= startmsg) {
496 ++remaining_messages;
500 for (a = 0; a < nummsgs; ++a) {
501 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
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];
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>");
515 --remaining_messages;
519 /* Bump these because although we're thinking in zero base, the user
520 * is a drooling idiot and is thinking in one base.
525 /* If we're only looking at one message, do a prev/next thing */
526 if (num_displayed == 1) {
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);
534 if (pn_previous > 0L) {
535 wprintf("<A HREF=\"/%s"
545 wprintf("<A HREF=\"/%s"
554 wprintf("<A HREF=\"/%s?startmsg=%ld"
555 "&maxmsgs=999999&summary=1\">"
561 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
566 * If we're not currently looking at ALL requested
567 * messages, then display the selector bar
569 /* if (num_displayed < nummsgs) { */
570 if (num_displayed > 1) {
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);
578 for (b=0; b<nummsgs; b = b + maxmsgs) {
581 if (hi > nummsgs) hi = nummsgs;
582 if (WC->msgarr[b] != startmsg) {
583 wprintf("<A HREF=\"/%s"
595 wprintf("%d-%d \n", lo, hi);
599 wprintf("<A HREF=\"/%s?startmsg=%ld"
600 "&maxmsgs=999999&summary=%d\">"
604 WC->msgarr[0], is_summary);
606 wprintf("<A HREF=\"/%s?startmsg=%ld"
607 "&maxmsgs=999999&summary=1\">"
613 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
616 DONE: wDumpContent(1);
623 * Post message (or don't post message)
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.
633 void post_message(void)
636 static long dont_post = (-1L);
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");
648 sprintf(buf, "ENT0 1|%s|0|0|%s",
654 text_to_server(bstr("msgtext"));
656 wprintf("Message has been posted.<BR>\n");
657 dont_post = atol(bstr("postseq"));
659 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
670 * display the message entry screen
672 void display_enter(void)
680 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
682 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
686 if (!strncmp(buf, "570", 3)) {
687 if (strlen(bstr("recp")) > 0) {
688 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
690 do_template("prompt_for_recipient.html");
694 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
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> ", WC->wc_roomname);
711 wprintf("</B></FONT><BR><CENTER>\n");
713 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\" "
714 "NAME=\"enterform\">\n");
715 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
717 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
719 wprintf("<FONT SIZE=-1>Subject (optional):</FONT>"
720 "<INPUT TYPE=\"text\" NAME=\"subject\" MAXLENGTH=70>"
722 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
723 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
725 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
726 "WIDTH=80></TEXTAREA><P>\n");
728 wprintf("</FORM></CENTER>\n");
729 DONE: wDumpContent(1);
740 void delete_msg(void)
745 msgid = atol(bstr("msgid"));
749 sprintf(buf, "DELE %ld", msgid);
752 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
761 * Confirm move of a message
763 void confirm_move_msg(void)
769 msgid = atol(bstr("msgid"));
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");
780 wprintf("Please select the room to which you would like this message moved:<BR>\n");
782 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
783 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
787 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
791 while (serv_gets(buf), strcmp(buf, "000")) {
792 extract(targ, buf, 0);
798 wprintf("</SELECT>\n");
801 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
802 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
803 wprintf("</FORM></CENTER>\n");
805 wprintf("</CENTER>\n");
816 msgid = atol(bstr("msgid"));
820 if (!strcasecmp(bstr("yesno"), "Move")) {
821 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
824 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
826 wprintf("<EM>Message not deleted.</EM><BR>\n");