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;
468 if (!strcmp(oper, "readnew")) {
469 strcpy(cmd, "MSGS NEW");
470 } else if (!strcmp(oper, "readold")) {
471 strcpy(cmd, "MSGS OLD");
473 strcpy(cmd, "MSGS ALL");
476 nummsgs = load_msg_ptrs(cmd);
478 if (!strcmp(oper, "readnew")) {
479 wprintf("<EM>No new messages in this room.</EM>\n");
480 } else if (!strcmp(oper, "readold")) {
481 wprintf("<EM>No old messages in this room.</EM>\n");
483 wprintf("<EM>This room is empty.</EM>\n");
488 if (startmsg == 0L) startmsg = WC->msgarr[0];
489 remaining_messages = 0;
491 for (a = 0; a < nummsgs; ++a) {
492 if (WC->msgarr[a] >= startmsg) {
493 ++remaining_messages;
497 for (a = 0; a < nummsgs; ++a) {
498 if ((WC->msgarr[a] >= startmsg) && (num_displayed < maxmsgs)) {
500 /* Learn which msgs "Prev" & "Next" buttons go to */
501 pn_current = WC->msgarr[a];
502 if (a > 0) pn_previous = WC->msgarr[a-1];
503 if (a < (nummsgs-1)) pn_next = WC->msgarr[a+1];
505 /* Display the message */
506 read_message(WC->msgarr[a], is_summary);
507 if (lowest_displayed == 0) lowest_displayed = a;
508 highest_displayed = a;
509 if (is_summary) wprintf("<BR>");
512 --remaining_messages;
516 /* Bump these because although we're thinking in zero base, the user
517 * is a drooling idiot and is thinking in one base.
522 /* If we're only looking at one message, do a prev/next thing */
523 if (num_displayed == 1) {
526 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=DDDDDD><TR><TD>"
527 "Reading #%d of %d messages.</TD>\n"
528 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
529 lowest_displayed, nummsgs);
531 if (pn_previous > 0L) {
532 wprintf("<A HREF=\"/%s"
542 wprintf("<A HREF=\"/%s"
551 wprintf("<A HREF=\"/%s?startmsg=%ld"
552 "&maxmsgs=999999&summary=1\">"
558 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
563 * If we're not currently looking at ALL requested
564 * messages, then display the selector bar
566 /* if (num_displayed < nummsgs) { */
567 if (num_displayed > 1) {
570 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=DDDDDD><TR><TD>"
571 "Reading #%d-%d of %d messages.</TD>\n"
572 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
573 lowest_displayed, highest_displayed, nummsgs);
575 for (b=0; b<nummsgs; b = b + maxmsgs) {
578 if (hi > nummsgs) hi = nummsgs;
579 if (WC->msgarr[b] != startmsg) {
580 wprintf("<A HREF=\"/%s"
592 wprintf("%d-%d \n", lo, hi);
596 wprintf("<A HREF=\"/%s?startmsg=%ld"
597 "&maxmsgs=999999&summary=%d\">"
601 WC->msgarr[0], is_summary);
603 wprintf("<A HREF=\"/%s?startmsg=%ld"
604 "&maxmsgs=999999&summary=1\">"
610 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
613 DONE: wDumpContent(1);
620 * Post message (or don't post message)
622 * Note regarding the "dont_post" variable:
623 * A random value (actually, it's just a timestamp) is inserted as a hidden
624 * field called "postseq" when the display_enter page is generated. This
625 * value is checked when posting, using the static variable dont_post. If a
626 * user attempts to post twice using the same dont_post value, the message is
627 * discarded. This prevents the accidental double-saving of the same message
628 * if the user happens to click the browser "back" button.
630 void post_message(void)
633 static long dont_post = (-1L);
637 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
638 strcpy(buf, bstr("sc"));
639 if (strcasecmp(buf, "Save message")) {
640 wprintf("Cancelled. Message was not posted.<BR>\n");
641 } else if (atol(bstr("postseq")) == dont_post) {
642 wprintf("Automatically cancelled because you have already "
643 "saved this message.<BR>\n");
645 sprintf(buf, "ENT0 1|%s|0|0|%s",
651 text_to_server(bstr("msgtext"));
653 wprintf("Message has been posted.<BR>\n");
654 dont_post = atol(bstr("postseq"));
656 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
667 * display the message entry screen
669 void display_enter(void)
677 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
679 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
683 if (!strncmp(buf, "570", 3)) {
684 if (strlen(bstr("recp")) > 0) {
685 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
687 do_template("prompt_for_recipient.html");
691 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
696 tm = (struct tm *) localtime(&now);
697 strcpy(buf, (char *) asctime(tm));
698 buf[strlen(buf) - 1] = 0;
699 strcpy(&buf[16], &buf[19]);
700 wprintf("</CENTER><FONT COLOR=\"440000\">\n"
701 "<IMG SRC=\"static/enter.gif\" ALIGN=MIDDLE ALT=\" \" "
702 "onLoad=\"document.enterform.msgtext.focus();\" >");
703 wprintf("<B> %s ", &buf[4]);
704 wprintf("from %s ", WC->wc_username);
705 if (strlen(bstr("recp")) > 0)
706 wprintf("to %s ", bstr("recp"));
707 wprintf("in %s> ", WC->wc_roomname);
708 wprintf("</B></FONT><BR><CENTER>\n");
710 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\" "
711 "NAME=\"enterform\">\n");
712 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
714 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
716 wprintf("<FONT SIZE=-1>Subject (optional):</FONT>"
717 "<INPUT TYPE=\"text\" NAME=\"subject\" MAXLENGTH=70>"
719 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
720 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
722 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
723 "WIDTH=80></TEXTAREA><P>\n");
725 wprintf("</FORM></CENTER>\n");
726 DONE: wDumpContent(1);
737 void delete_msg(void)
742 msgid = atol(bstr("msgid"));
746 sprintf(buf, "DELE %ld", msgid);
749 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
758 * Confirm move of a message
760 void confirm_move_msg(void)
766 msgid = atol(bstr("msgid"));
770 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
771 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
772 wprintf("<B>Confirm move of message</B>\n");
773 wprintf("</FONT></TD></TR></TABLE>\n");
777 wprintf("Please select the room to which you would like this message moved:<BR>\n");
779 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
780 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
784 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
788 while (serv_gets(buf), strcmp(buf, "000")) {
789 extract(targ, buf, 0);
795 wprintf("</SELECT>\n");
798 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
799 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
800 wprintf("</FORM></CENTER>\n");
802 wprintf("</CENTER>\n");
813 msgid = atol(bstr("msgid"));
817 if (!strcasecmp(bstr("yesno"), "Move")) {
818 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
821 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
823 wprintf("<EM>Message not deleted.</EM><BR>\n");