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><TD><FONT SIZE=+1><B>");
102 escputs(v->prop[i].value);
103 wprintf("</B></FONT></TD></TR>\n");
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);
110 escputs(v->prop[i].value);
111 wprintf("</A></TD></TR>\n");
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) {
122 wprintf("</TD></TR>\n");
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) {
134 wprintf("</TD></TR>\n");
138 escputs(v->prop[i].name);
139 wprintf("</TD><TD>");
140 escputs(v->prop[i].value);
141 wprintf("</TD></TR>\n");
145 wprintf("</TABLE>\n");
155 void read_message(long msgnum, int is_summary) {
157 char mime_partnum[SIZ];
158 char mime_filename[SIZ];
159 char mime_content_type[SIZ];
160 char mime_disposition[SIZ];
162 char *mime_http = NULL;
172 char vcard_partnum[SIZ];
173 char *vcard_source = NULL;
178 strcpy(reply_to, "");
179 strcpy(vcard_partnum, "");
181 sprintf(buf, "MSG0 %ld", msgnum);
185 wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
188 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 CELLPADDING=1 BGCOLOR=CCCCCC><TR><TD>\n");
190 if (!is_summary) wprintf("SIZE=+1 ");
191 wprintf("COLOR=\"000000\"> ");
192 strcpy(m_subject, "");
194 while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
195 if (!strncasecmp(buf, "nhdr=yes", 8))
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=");
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]);
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)))))
230 wprintf("@%s ", &buf[5]);
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]));
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);
247 if (!strcasecmp(mime_disposition, "attachment")) {
248 if (mime_http == NULL) {
249 mime_http = malloc(512);
250 strcpy(mime_http, "");
253 mime_http = realloc(mime_http,
254 strlen(mime_http) + 512);
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);
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, "");
276 mime_http = realloc(mime_http,
277 strlen(mime_http) + 512);
279 sprintf(&mime_http[strlen(mime_http)],
280 "<IMG SRC=\"/output_mimepart?"
281 "msgnum=%ld&partnum=%s\">",
282 msgnum, mime_partnum);
285 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
286 strcpy(vcard_partnum, mime_partnum);
294 /* Generate a reply-to address */
295 if (strlen(rfca) > 0) {
296 strcpy(reply_to, rfca);
299 if (strlen(node) > 0) {
300 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
304 snprintf(reply_to, sizeof(reply_to), "%s", from);
310 wprintf("</FONT></TD>");
312 /* begin right-hand toolbar */
313 wprintf("<TD ALIGN=RIGHT>\n"
314 "<TABLE BORDER=0><TR>\n");
317 wprintf("<TD BGCOLOR=\"AAAADD\">"
318 "<A HREF=\"/readfwd?startmsg=%ld", msgnum);
319 wprintf("&maxmsgs=1&summary=0\">Read</A>"
323 wprintf("<TD BGCOLOR=\"AAAADD\">"
324 "<A HREF=\"/display_enter?recp=");
325 urlescputs(reply_to);
326 wprintf("\"><FONT SIZE=-1>Reply</FONT></A>"
329 if (WC->is_room_aide) {
330 wprintf("<TD BGCOLOR=\"AAAADD\">"
331 "<A HREF=\"/confirm_move_msg"
333 "\"><FONT SIZE=-1>Move</FONT></A>"
336 wprintf("<TD BGCOLOR=\"AAAADD\">"
337 "<A HREF=\"/delete_msg"
339 "onClick=\"return confirm('Delete this message?');\""
340 "><FONT SIZE=-1>Del</FONT></A>"
344 wprintf("</TR></TABLE>\n"
347 /* end right-hand toolbar */
350 if (strlen(m_subject) > 0) {
351 wprintf("<TR><TD><FONT COLOR=\"FFFFFF\">"
353 "</TD><TD> </TD></TR>\n", m_subject);
356 wprintf("</TR></TABLE>\n");
359 while (serv_gets(buf), strcmp(buf, "000")) ;
363 if (format_type == 0) {
366 while (serv_gets(buf), strcmp(buf, "000")) {
367 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
368 buf[strlen(buf) - 1] = 0;
370 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
371 wprintf("<FONT COLOR=\"000044\"><I>");
373 } else if ((bq == 1) &&
374 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
375 wprintf("</FONT></I>");
381 wprintf("</TT><BR>\n");
386 if (mime_http != NULL) {
387 wprintf("%s", mime_http);
391 if (strlen(vcard_partnum) > 0) {
392 vcard_source = load_mimepart(msgnum, vcard_partnum);
393 if (vcard_source != NULL) {
394 display_vcard(vcard_source);
404 * load message pointers from the server
406 int load_msg_ptrs(servcmd)
416 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
419 while (serv_gets(buf), strcmp(buf, "000")) {
420 WC->msgarr[nummsgs] = atol(buf);
428 * command loop for reading messages
430 void readloop(char *oper)
437 int num_displayed = 0;
439 int remaining_messages;
441 int lowest_displayed = 0;
442 int highest_displayed = 0;
444 startmsg = atol(bstr("startmsg"));
445 maxmsgs = atoi(bstr("maxmsgs"));
446 is_summary = atoi(bstr("summary"));
447 if (maxmsgs == 0) maxmsgs = 20;
451 if (!strcmp(oper, "readnew")) {
452 strcpy(cmd, "MSGS NEW");
453 } else if (!strcmp(oper, "readold")) {
454 strcpy(cmd, "MSGS OLD");
456 strcpy(cmd, "MSGS ALL");
459 nummsgs = load_msg_ptrs(cmd);
461 if (!strcmp(oper, "readnew")) {
462 wprintf("<EM>No new messages in this room.</EM>\n");
463 } else if (!strcmp(oper, "readold")) {
464 wprintf("<EM>No old messages in this room.</EM>\n");
466 wprintf("<EM>This room is empty.</EM>\n");
471 if (startmsg == 0L) startmsg = WC->msgarr[0];
472 remaining_messages = 0;
474 for (a = 0; a < nummsgs; ++a) {
475 if (WC->msgarr[a] >= startmsg) {
476 ++remaining_messages;
480 for (a = 0; ( (a < nummsgs) && (num_displayed < maxmsgs) ) ; ++a) {
481 if (WC->msgarr[a] >= startmsg) {
483 read_message(WC->msgarr[a], is_summary);
484 if (lowest_displayed == 0) lowest_displayed = a;
485 highest_displayed = a;
486 if (is_summary) wprintf("<BR>");
489 --remaining_messages;
493 /* Bump these because although we're thinking in zero base, the user
494 * is a drooling idiot and is thinking in one base.
500 * If we're not currently looking at ALL requested
501 * messages, then display the selector bar
503 if (num_displayed < nummsgs) {
506 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=DDDDDD><TR><TD>"
507 "You are reading #%d-%d of %d messages.</TD>\n"
508 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
509 lowest_displayed, highest_displayed, nummsgs);
511 for (b=0; b<nummsgs; b = b + maxmsgs) {
514 if (hi > nummsgs) hi = nummsgs;
515 if (WC->msgarr[b] != startmsg) {
516 wprintf("<A HREF=\"/%s"
528 wprintf("%d-%d \n", lo, hi);
532 wprintf("<A HREF=\"/%s?startmsg=%ld"
533 "&maxmsgs=999999&summary=%d\">"
535 "</A> ",
537 WC->msgarr[0], is_summary);
538 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
541 DONE: wDumpContent(1);
548 * Post message (or don't post message)
550 * Note regarding the "dont_post" variable:
551 * A random value (actually, it's just a timestamp) is inserted as a hidden
552 * field called "postseq" when the display_enter page is generated. This
553 * value is checked when posting, using the static variable dont_post. If a
554 * user attempts to post twice using the same dont_post value, the message is
555 * discarded. This prevents the accidental double-saving of the same message
556 * if the user happens to click the browser "back" button.
558 void post_message(void)
561 static long dont_post = (-1L);
565 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
566 strcpy(buf, bstr("sc"));
567 if (strcasecmp(buf, "Save message")) {
568 wprintf("Cancelled. Message was not posted.<BR>\n");
569 } else if (atol(bstr("postseq")) == dont_post) {
570 wprintf("Automatically cancelled because you have already "
571 "saved this message.<BR>\n");
573 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
577 text_to_server(bstr("msgtext"));
579 wprintf("Message has been posted.<BR>\n");
580 dont_post = atol(bstr("postseq"));
582 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
593 * display the message entry screen
595 void display_enter(void)
603 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
605 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
609 if (!strncmp(buf, "570", 3)) {
610 if (strlen(bstr("recp")) > 0) {
611 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
613 do_template("prompt_for_recipient.html");
617 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
622 tm = (struct tm *) localtime(&now);
623 strcpy(buf, (char *) asctime(tm));
624 buf[strlen(buf) - 1] = 0;
625 strcpy(&buf[16], &buf[19]);
626 wprintf("</CENTER><FONT COLOR=\"440000\">\n"
627 "<IMG SRC=\"static/enter.gif\" ALIGN=MIDDLE ALT=\" \" "
628 "onLoad=\"document.enterform.msgtext.focus();\" >");
629 wprintf("<B> %s ", &buf[4]);
630 wprintf("from %s ", WC->wc_username);
631 if (strlen(bstr("recp")) > 0)
632 wprintf("to %s ", bstr("recp"));
633 wprintf("in %s> ", WC->wc_roomname);
634 wprintf("</B></FONT><BR><CENTER>\n");
636 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\" "
637 "NAME=\"enterform\">\n");
638 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
640 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
642 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
643 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
645 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
646 "WIDTH=80></TEXTAREA><P>\n");
648 wprintf("</FORM></CENTER>\n");
649 DONE: wDumpContent(1);
660 void delete_msg(void)
665 msgid = atol(bstr("msgid"));
669 sprintf(buf, "DELE %ld", msgid);
672 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
681 * Confirm move of a message
683 void confirm_move_msg(void)
689 msgid = atol(bstr("msgid"));
693 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
694 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
695 wprintf("<B>Confirm move of message</B>\n");
696 wprintf("</FONT></TD></TR></TABLE>\n");
700 wprintf("Please select the room to which you would like this message moved:<BR>\n");
702 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
703 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
707 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
711 while (serv_gets(buf), strcmp(buf, "000")) {
712 extract(targ, buf, 0);
718 wprintf("</SELECT>\n");
721 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
722 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
723 wprintf("</FORM></CENTER>\n");
725 wprintf("</CENTER>\n");
736 msgid = atol(bstr("msgid"));
740 if (!strcasecmp(bstr("yesno"), "Move")) {
741 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
744 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
746 wprintf("<EM>Message not deleted.</EM><BR>\n");