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[256];
87 char mime_filename[256];
88 char mime_content_type[256];
89 char mime_disposition[256];
91 char *mime_http = NULL;
105 strcpy(reply_to, "");
107 sprintf(buf, "MSG0 %ld", msgnum);
111 wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
114 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 CELLPADDING=1 BGCOLOR=CCCCCC><TR><TD>\n");
116 if (!is_summary) wprintf("SIZE=+1 ");
117 wprintf("COLOR=\"000000\"> ");
118 strcpy(m_subject, "");
120 while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
121 if (!strncasecmp(buf, "nhdr=yes", 8))
125 if (!strncasecmp(buf, "type=", 5))
126 format_type = atoi(&buf[5]);
127 if (!strncasecmp(buf, "from=", 5)) {
128 strcpy(from, &buf[5]);
129 wprintf("from <A HREF=\"/showuser&who=");
135 if (!strncasecmp(buf, "subj=", 5))
136 strcpy(m_subject, &buf[5]);
137 if ((!strncasecmp(buf, "hnod=", 5))
138 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
139 wprintf("(%s) ", &buf[5]);
140 if ((!strncasecmp(buf, "room=", 5))
141 && (strcasecmp(&buf[5], WC->wc_roomname)))
142 wprintf("in %s> ", &buf[5]);
143 if (!strncasecmp(buf, "rfca=", 5)) {
144 strcpy(rfca, &buf[5]);
150 if (!strncasecmp(buf, "node=", 5)) {
151 if ( ((WC->room_flags & QR_NETWORK)
152 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
153 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
156 wprintf("@%s ", &buf[5]);
159 if (!strncasecmp(buf, "rcpt=", 5))
160 wprintf("to %s ", &buf[5]);
161 if (!strncasecmp(buf, "time=", 5)) {
162 fmt_date(now, atol(&buf[5]));
166 if (!strncasecmp(buf, "part=", 5)) {
167 extract(mime_filename, &buf[5], 1);
168 extract(mime_partnum, &buf[5], 2);
169 extract(mime_disposition, &buf[5], 3);
170 extract(mime_content_type, &buf[5], 4);
171 mime_length = extract_int(&buf[5], 5);
173 if (!strcasecmp(mime_disposition, "attachment")) {
174 if (mime_http == NULL) {
175 mime_http = malloc(512);
176 strcpy(mime_http, "");
179 mime_http = realloc(mime_http,
180 strlen(mime_http) + 512);
182 sprintf(&mime_http[strlen(mime_http)],
183 "<A HREF=\"/output_mimepart?"
184 "msgnum=%ld&partnum=%s\" "
185 "TARGET=\"wc.%ld.%s\">"
186 "<IMG SRC=\"/static/attachment.gif\" "
187 "BORDER=0 ALIGN=MIDDLE>\n"
188 "Part %s: %s (%s, %d bytes)</A><BR>\n",
189 msgnum, mime_partnum,
190 msgnum, mime_partnum,
191 mime_partnum, mime_filename,
192 mime_content_type, mime_length);
195 if ((!strcasecmp(mime_disposition, "inline"))
196 && (!strncasecmp(mime_content_type, "image/", 6)) ){
197 if (mime_http == NULL) {
198 mime_http = malloc(512);
199 strcpy(mime_http, "");
202 mime_http = realloc(mime_http,
203 strlen(mime_http) + 512);
205 sprintf(&mime_http[strlen(mime_http)],
206 "<IMG SRC=\"/output_mimepart?"
207 "msgnum=%ld&partnum=%s\">",
208 msgnum, mime_partnum);
216 /* Generate a reply-to address */
217 if (strlen(rfca) > 0) {
218 strcpy(reply_to, rfca);
221 if (strlen(node) > 0) {
222 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
226 snprintf(reply_to, sizeof(reply_to), "%s", from);
232 wprintf("</FONT></TD>");
234 /* begin right-hand toolbar */
235 wprintf("<TD ALIGN=RIGHT>\n"
236 "<TABLE BORDER=0><TR>\n");
239 wprintf("<TD BGCOLOR=\"AAAADD\">"
240 "<A HREF=\"/readfwd?startmsg=%ld", msgnum);
241 wprintf("&maxmsgs=1&summary=0\">Read</A>"
245 wprintf("<TD BGCOLOR=\"AAAADD\">"
246 "<A HREF=\"/display_enter?recp=");
247 urlescputs(reply_to);
248 wprintf("\"><FONT SIZE=-1>Reply</FONT></A>"
251 if (WC->is_room_aide) {
252 wprintf("<TD BGCOLOR=\"AAAADD\">"
253 "<A HREF=\"/confirm_move_msg"
255 "\"><FONT SIZE=-1>Move</FONT></A>"
258 wprintf("<TD BGCOLOR=\"AAAADD\">"
259 "<A HREF=\"/delete_msg"
261 "onClick=\"return confirm('Delete this message?');\""
262 "><FONT SIZE=-1>Del</FONT></A>"
266 wprintf("</TR></TABLE>\n"
269 /* end right-hand toolbar */
272 if (strlen(m_subject) > 0) {
273 wprintf("<TR><TD><FONT COLOR=\"FFFFFF\">"
275 "</TD><TD> </TD></TR>\n", m_subject);
278 wprintf("</TR></TABLE>\n");
281 while (serv_gets(buf), strcmp(buf, "000")) ;
285 if (format_type == 0) {
288 while (serv_gets(buf), strcmp(buf, "000")) {
289 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
290 buf[strlen(buf) - 1] = 0;
292 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
293 wprintf("<FONT COLOR=\"000044\"><I>");
295 } else if ((bq == 1) &&
296 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
297 wprintf("</FONT></I>");
303 wprintf("</TT><BR>\n");
308 if (mime_http != NULL) {
309 wprintf("%s", mime_http);
317 * load message pointers from the server
319 int load_msg_ptrs(servcmd)
329 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
332 while (serv_gets(buf), strcmp(buf, "000")) {
333 WC->msgarr[nummsgs] = atol(buf);
341 * command loop for reading messages
343 void readloop(char *oper)
350 int num_displayed = 0;
352 int remaining_messages;
354 int lowest_displayed = 0;
355 int highest_displayed = 0;
357 startmsg = atol(bstr("startmsg"));
358 maxmsgs = atoi(bstr("maxmsgs"));
359 is_summary = atoi(bstr("summary"));
360 if (maxmsgs == 0) maxmsgs = 20;
364 if (!strcmp(oper, "readnew")) {
365 strcpy(cmd, "MSGS NEW");
366 } else if (!strcmp(oper, "readold")) {
367 strcpy(cmd, "MSGS OLD");
369 strcpy(cmd, "MSGS ALL");
372 nummsgs = load_msg_ptrs(cmd);
374 if (!strcmp(oper, "readnew")) {
375 wprintf("<EM>No new messages in this room.</EM>\n");
376 } else if (!strcmp(oper, "readold")) {
377 wprintf("<EM>No old messages in this room.</EM>\n");
379 wprintf("<EM>This room is empty.</EM>\n");
384 if (startmsg == 0L) startmsg = WC->msgarr[0];
385 remaining_messages = 0;
387 for (a = 0; a < nummsgs; ++a) {
388 if (WC->msgarr[a] >= startmsg) {
389 ++remaining_messages;
393 for (a = 0; ( (a < nummsgs) && (num_displayed < maxmsgs) ) ; ++a) {
394 if (WC->msgarr[a] >= startmsg) {
396 read_message(WC->msgarr[a], is_summary);
397 if (lowest_displayed == 0) lowest_displayed = a;
398 highest_displayed = a;
399 if (is_summary) wprintf("<BR>");
402 --remaining_messages;
406 /* Bump these because although we're thinking in zero base, the user
407 * is a drooling idiot and is thinking in one base.
413 * If we're not currently looking at ALL requested
414 * messages, then display the selector bar
416 if (num_displayed < nummsgs) {
419 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=DDDDDD><TR><TD>"
420 "You are reading #%d-%d of %d messages.</TD>\n"
421 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
422 lowest_displayed, highest_displayed, nummsgs);
424 for (b=0; b<nummsgs; b = b + maxmsgs) {
427 if (hi > nummsgs) hi = nummsgs;
428 if (WC->msgarr[b] != startmsg) {
429 wprintf("<A HREF=\"/%s"
441 wprintf("%d-%d \n", lo, hi);
445 wprintf("<A HREF=\"/%s?startmsg=%ld"
446 "&maxmsgs=999999&summary=%d\">"
448 "</A> ",
450 WC->msgarr[0], is_summary);
451 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
454 DONE: wDumpContent(1);
461 * Post message (or don't post message)
463 * Note regarding the "dont_post" variable:
464 * A random value (actually, it's just a timestamp) is inserted as a hidden
465 * field called "postseq" when the display_enter page is generated. This
466 * value is checked when posting, using the static variable dont_post. If a
467 * user attempts to post twice using the same dont_post value, the message is
468 * discarded. This prevents the accidental double-saving of the same message
469 * if the user happens to click the browser "back" button.
471 void post_message(void)
474 static long dont_post = (-1L);
478 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
479 strcpy(buf, bstr("sc"));
480 if (strcasecmp(buf, "Save message")) {
481 wprintf("Cancelled. Message was not posted.<BR>\n");
482 } else if (atol(bstr("postseq")) == dont_post) {
483 wprintf("Automatically cancelled because you have already "
484 "saved this message.<BR>\n");
486 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
490 text_to_server(bstr("msgtext"));
492 wprintf("Message has been posted.<BR>\n");
493 dont_post = atol(bstr("postseq"));
495 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
510 * prompt for a recipient (to be called from display_enter() only)
512 void prompt_for_recipient()
515 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
516 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
517 wprintf("<B>Send private e-mail</B>\n");
518 wprintf("</FONT></TD></TR></TABLE>\n");
521 wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
522 wprintf("Enter recipient: ");
523 wprintf("<INPUT TYPE=\"text\" NAME=\"recp\" MAXLENGTH=\"64\"><BR>\n");
524 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
525 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
526 wprintf("</FORM></CENTER>\n");
532 * display the message entry screen
534 void display_enter(void)
542 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
544 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
548 if (!strncmp(buf, "570", 3)) {
549 if (strlen(bstr("recp")) > 0) {
550 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
552 prompt_for_recipient();
556 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
561 tm = (struct tm *) localtime(&now);
562 strcpy(buf, (char *) asctime(tm));
563 buf[strlen(buf) - 1] = 0;
564 strcpy(&buf[16], &buf[19]);
565 wprintf("</CENTER><FONT COLOR=\"440000\">\n"
566 "<IMG SRC=\"static/enter.gif\" ALIGN=MIDDLE ALT=\" \" "
567 "onLoad=\"document.enterform.msgtext.focus();\" >");
568 wprintf("<B> %s ", &buf[4]);
569 wprintf("from %s ", WC->wc_username);
570 if (strlen(bstr("recp")) > 0)
571 wprintf("to %s ", bstr("recp"));
572 wprintf("in %s> ", WC->wc_roomname);
573 wprintf("</B></FONT><BR><CENTER>\n");
575 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\" "
576 "NAME=\"enterform\">\n");
577 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
579 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
581 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
582 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
584 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
585 "WIDTH=80></TEXTAREA><P>\n");
587 wprintf("</FORM></CENTER>\n");
588 DONE: wDumpContent(1);
599 void delete_msg(void)
604 msgid = atol(bstr("msgid"));
608 sprintf(buf, "DELE %ld", msgid);
611 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
620 * Confirm move of a message
622 void confirm_move_msg(void)
628 msgid = atol(bstr("msgid"));
632 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
633 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
634 wprintf("<B>Confirm move of message</B>\n");
635 wprintf("</FONT></TD></TR></TABLE>\n");
639 wprintf("Please select the room to which you would like this message moved:<BR>\n");
641 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
642 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
646 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
650 while (serv_gets(buf), strcmp(buf, "000")) {
651 extract(targ, buf, 0);
657 wprintf("</SELECT>\n");
660 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
661 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
662 wprintf("</FORM></CENTER>\n");
664 wprintf("</CENTER>\n");
675 msgid = atol(bstr("msgid"));
679 if (!strcasecmp(bstr("yesno"), "Move")) {
680 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
683 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
685 wprintf("<EM>Message not deleted.</EM><BR>\n");