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>
30 * Look for URL's embedded in a buffer and make them linkable. We use a
31 * target window in order to keep the BBS session in its own window.
47 for (pos = 0; pos < strlen(buf); ++pos) {
48 if (!strncasecmp(&buf[pos], "http://", 7))
50 if (!strncasecmp(&buf[pos], "ftp://", 6))
57 if ((start > 0) && (buf[start - 1] == '<'))
59 if ((start > 0) && (buf[start - 1] == '['))
61 if ((start > 0) && (buf[start - 1] == '('))
63 if ((start > 0) && (buf[start - 1] == '{'))
66 for (pos = strlen(buf); pos > start; --pos) {
67 if ((buf[pos] == ' ') || (buf[pos] == ench))
71 strncpy(urlbuf, &buf[start], end - start);
72 urlbuf[end - start] = 0;
75 strncpy(outbuf, buf, start);
76 sprintf(&outbuf[start], "%cA HREF=%c%s%c TARGET=%c%s%c%c%s%c/A%c",
77 LB, QU, urlbuf, QU, QU, TARGET, QU, RB, urlbuf, LB, RB);
78 strcat(outbuf, &buf[end]);
79 if ( strlen(outbuf) < 250 )
84 void read_message(long msgnum, int is_summary) {
86 char mime_partnum[SIZ];
87 char mime_filename[SIZ];
88 char mime_content_type[SIZ];
89 char mime_disposition[SIZ];
91 char *mime_http = NULL;
101 char vcard_partnum[SIZ];
102 char *vcard_source = NULL;
107 strcpy(reply_to, "");
108 strcpy(vcard_partnum, "");
110 sprintf(buf, "MSG0 %ld", msgnum);
114 wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
117 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 CELLPADDING=1 BGCOLOR=CCCCCC><TR><TD>\n");
119 if (!is_summary) wprintf("SIZE=+1 ");
120 wprintf("COLOR=\"000000\"> ");
121 strcpy(m_subject, "");
123 while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
124 if (!strncasecmp(buf, "nhdr=yes", 8))
128 if (!strncasecmp(buf, "type=", 5))
129 format_type = atoi(&buf[5]);
130 if (!strncasecmp(buf, "from=", 5)) {
131 strcpy(from, &buf[5]);
132 wprintf("from <A HREF=\"/showuser&who=");
138 if (!strncasecmp(buf, "subj=", 5))
139 strcpy(m_subject, &buf[5]);
140 if ((!strncasecmp(buf, "hnod=", 5))
141 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
142 wprintf("(%s) ", &buf[5]);
143 if ((!strncasecmp(buf, "room=", 5))
144 && (strcasecmp(&buf[5], WC->wc_roomname)))
145 wprintf("in %s> ", &buf[5]);
146 if (!strncasecmp(buf, "rfca=", 5)) {
147 strcpy(rfca, &buf[5]);
153 if (!strncasecmp(buf, "node=", 5)) {
154 if ( ((WC->room_flags & QR_NETWORK)
155 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
156 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
159 wprintf("@%s ", &buf[5]);
162 if (!strncasecmp(buf, "rcpt=", 5))
163 wprintf("to %s ", &buf[5]);
164 if (!strncasecmp(buf, "time=", 5)) {
165 fmt_date(now, atol(&buf[5]));
169 if (!strncasecmp(buf, "part=", 5)) {
170 extract(mime_filename, &buf[5], 1);
171 extract(mime_partnum, &buf[5], 2);
172 extract(mime_disposition, &buf[5], 3);
173 extract(mime_content_type, &buf[5], 4);
174 mime_length = extract_int(&buf[5], 5);
176 if (!strcasecmp(mime_disposition, "attachment")) {
177 if (mime_http == NULL) {
178 mime_http = malloc(512);
179 strcpy(mime_http, "");
182 mime_http = realloc(mime_http,
183 strlen(mime_http) + 512);
185 sprintf(&mime_http[strlen(mime_http)],
186 "<A HREF=\"/output_mimepart?"
187 "msgnum=%ld&partnum=%s\" "
188 "TARGET=\"wc.%ld.%s\">"
189 "<IMG SRC=\"/static/attachment.gif\" "
190 "BORDER=0 ALIGN=MIDDLE>\n"
191 "Part %s: %s (%s, %d bytes)</A><BR>\n",
192 msgnum, mime_partnum,
193 msgnum, mime_partnum,
194 mime_partnum, mime_filename,
195 mime_content_type, mime_length);
198 if ((!strcasecmp(mime_disposition, "inline"))
199 && (!strncasecmp(mime_content_type, "image/", 6)) ){
200 if (mime_http == NULL) {
201 mime_http = malloc(512);
202 strcpy(mime_http, "");
205 mime_http = realloc(mime_http,
206 strlen(mime_http) + 512);
208 sprintf(&mime_http[strlen(mime_http)],
209 "<IMG SRC=\"/output_mimepart?"
210 "msgnum=%ld&partnum=%s\">",
211 msgnum, mime_partnum);
214 if (!strcasecmp(mime_content_type, "text/x-vcard")) {
215 strcpy(vcard_partnum, mime_partnum);
223 /* Generate a reply-to address */
224 if (strlen(rfca) > 0) {
225 strcpy(reply_to, rfca);
228 if (strlen(node) > 0) {
229 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
233 snprintf(reply_to, sizeof(reply_to), "%s", from);
239 wprintf("</FONT></TD>");
241 /* begin right-hand toolbar */
242 wprintf("<TD ALIGN=RIGHT>\n"
243 "<TABLE BORDER=0><TR>\n");
246 wprintf("<TD BGCOLOR=\"AAAADD\">"
247 "<A HREF=\"/readfwd?startmsg=%ld", msgnum);
248 wprintf("&maxmsgs=1&summary=0\">Read</A>"
252 wprintf("<TD BGCOLOR=\"AAAADD\">"
253 "<A HREF=\"/display_enter?recp=");
254 urlescputs(reply_to);
255 wprintf("\"><FONT SIZE=-1>Reply</FONT></A>"
258 if (WC->is_room_aide) {
259 wprintf("<TD BGCOLOR=\"AAAADD\">"
260 "<A HREF=\"/confirm_move_msg"
262 "\"><FONT SIZE=-1>Move</FONT></A>"
265 wprintf("<TD BGCOLOR=\"AAAADD\">"
266 "<A HREF=\"/delete_msg"
268 "onClick=\"return confirm('Delete this message?');\""
269 "><FONT SIZE=-1>Del</FONT></A>"
273 wprintf("</TR></TABLE>\n"
276 /* end right-hand toolbar */
279 if (strlen(m_subject) > 0) {
280 wprintf("<TR><TD><FONT COLOR=\"FFFFFF\">"
282 "</TD><TD> </TD></TR>\n", m_subject);
285 wprintf("</TR></TABLE>\n");
288 while (serv_gets(buf), strcmp(buf, "000")) ;
292 if (format_type == 0) {
295 while (serv_gets(buf), strcmp(buf, "000")) {
296 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
297 buf[strlen(buf) - 1] = 0;
299 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
300 wprintf("<FONT COLOR=\"000044\"><I>");
302 } else if ((bq == 1) &&
303 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
304 wprintf("</FONT></I>");
310 wprintf("</TT><BR>\n");
315 if (mime_http != NULL) {
316 wprintf("%s", mime_http);
320 if (strlen(vcard_partnum) > 0) {
321 vcard_source = load_mimepart(msgnum, vcard_partnum);
322 if (vcard_source != NULL) {
323 wprintf("vcard object length = %d<BR>\n",
324 strlen(vcard_source));
334 * load message pointers from the server
336 int load_msg_ptrs(servcmd)
346 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
349 while (serv_gets(buf), strcmp(buf, "000")) {
350 WC->msgarr[nummsgs] = atol(buf);
358 * command loop for reading messages
360 void readloop(char *oper)
367 int num_displayed = 0;
369 int remaining_messages;
371 int lowest_displayed = 0;
372 int highest_displayed = 0;
374 startmsg = atol(bstr("startmsg"));
375 maxmsgs = atoi(bstr("maxmsgs"));
376 is_summary = atoi(bstr("summary"));
377 if (maxmsgs == 0) maxmsgs = 20;
381 if (!strcmp(oper, "readnew")) {
382 strcpy(cmd, "MSGS NEW");
383 } else if (!strcmp(oper, "readold")) {
384 strcpy(cmd, "MSGS OLD");
386 strcpy(cmd, "MSGS ALL");
389 nummsgs = load_msg_ptrs(cmd);
391 if (!strcmp(oper, "readnew")) {
392 wprintf("<EM>No new messages in this room.</EM>\n");
393 } else if (!strcmp(oper, "readold")) {
394 wprintf("<EM>No old messages in this room.</EM>\n");
396 wprintf("<EM>This room is empty.</EM>\n");
401 if (startmsg == 0L) startmsg = WC->msgarr[0];
402 remaining_messages = 0;
404 for (a = 0; a < nummsgs; ++a) {
405 if (WC->msgarr[a] >= startmsg) {
406 ++remaining_messages;
410 for (a = 0; ( (a < nummsgs) && (num_displayed < maxmsgs) ) ; ++a) {
411 if (WC->msgarr[a] >= startmsg) {
413 read_message(WC->msgarr[a], is_summary);
414 if (lowest_displayed == 0) lowest_displayed = a;
415 highest_displayed = a;
416 if (is_summary) wprintf("<BR>");
419 --remaining_messages;
423 /* Bump these because although we're thinking in zero base, the user
424 * is a drooling idiot and is thinking in one base.
430 * If we're not currently looking at ALL requested
431 * messages, then display the selector bar
433 if (num_displayed < nummsgs) {
436 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=DDDDDD><TR><TD>"
437 "You are reading #%d-%d of %d messages.</TD>\n"
438 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
439 lowest_displayed, highest_displayed, nummsgs);
441 for (b=0; b<nummsgs; b = b + maxmsgs) {
444 if (hi > nummsgs) hi = nummsgs;
445 if (WC->msgarr[b] != startmsg) {
446 wprintf("<A HREF=\"/%s"
458 wprintf("%d-%d \n", lo, hi);
462 wprintf("<A HREF=\"/%s?startmsg=%ld"
463 "&maxmsgs=999999&summary=%d\">"
465 "</A> ",
467 WC->msgarr[0], is_summary);
468 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
471 DONE: wDumpContent(1);
478 * Post message (or don't post message)
480 * Note regarding the "dont_post" variable:
481 * A random value (actually, it's just a timestamp) is inserted as a hidden
482 * field called "postseq" when the display_enter page is generated. This
483 * value is checked when posting, using the static variable dont_post. If a
484 * user attempts to post twice using the same dont_post value, the message is
485 * discarded. This prevents the accidental double-saving of the same message
486 * if the user happens to click the browser "back" button.
488 void post_message(void)
491 static long dont_post = (-1L);
495 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
496 strcpy(buf, bstr("sc"));
497 if (strcasecmp(buf, "Save message")) {
498 wprintf("Cancelled. Message was not posted.<BR>\n");
499 } else if (atol(bstr("postseq")) == dont_post) {
500 wprintf("Automatically cancelled because you have already "
501 "saved this message.<BR>\n");
503 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
507 text_to_server(bstr("msgtext"));
509 wprintf("Message has been posted.<BR>\n");
510 dont_post = atol(bstr("postseq"));
512 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
523 * display the message entry screen
525 void display_enter(void)
533 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
535 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
539 if (!strncmp(buf, "570", 3)) {
540 if (strlen(bstr("recp")) > 0) {
541 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
543 do_template("prompt_for_recipient.html");
547 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
552 tm = (struct tm *) localtime(&now);
553 strcpy(buf, (char *) asctime(tm));
554 buf[strlen(buf) - 1] = 0;
555 strcpy(&buf[16], &buf[19]);
556 wprintf("</CENTER><FONT COLOR=\"440000\">\n"
557 "<IMG SRC=\"static/enter.gif\" ALIGN=MIDDLE ALT=\" \" "
558 "onLoad=\"document.enterform.msgtext.focus();\" >");
559 wprintf("<B> %s ", &buf[4]);
560 wprintf("from %s ", WC->wc_username);
561 if (strlen(bstr("recp")) > 0)
562 wprintf("to %s ", bstr("recp"));
563 wprintf("in %s> ", WC->wc_roomname);
564 wprintf("</B></FONT><BR><CENTER>\n");
566 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\" "
567 "NAME=\"enterform\">\n");
568 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
570 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
572 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
573 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
575 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
576 "WIDTH=80></TEXTAREA><P>\n");
578 wprintf("</FORM></CENTER>\n");
579 DONE: wDumpContent(1);
590 void delete_msg(void)
595 msgid = atol(bstr("msgid"));
599 sprintf(buf, "DELE %ld", msgid);
602 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
611 * Confirm move of a message
613 void confirm_move_msg(void)
619 msgid = atol(bstr("msgid"));
623 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
624 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
625 wprintf("<B>Confirm move of message</B>\n");
626 wprintf("</FONT></TD></TR></TABLE>\n");
630 wprintf("Please select the room to which you would like this message moved:<BR>\n");
632 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
633 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
637 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
641 while (serv_gets(buf), strcmp(buf, "000")) {
642 extract(targ, buf, 0);
648 wprintf("</SELECT>\n");
651 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
652 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
653 wprintf("</FORM></CENTER>\n");
655 wprintf("</CENTER>\n");
666 msgid = atol(bstr("msgid"));
670 if (!strcasecmp(bstr("yesno"), "Move")) {
671 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
674 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
676 wprintf("<EM>Message not deleted.</EM><BR>\n");