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")) {
175 if (mime_http == NULL) {
176 mime_http = malloc(512);
177 strcpy(mime_http, "");
180 mime_http = realloc(mime_http,
181 strlen(mime_http) + 512);
184 sprintf(&mime_http[strlen(mime_http)],
185 "<A HREF=\"/output_mimepart?"
186 "msgnum=%ld&partnum=%s\" "
187 "TARGET=\"wc.%ld.%s\">"
188 "<IMG SRC=\"/static/attachment.gif\" "
189 "BORDER=0 ALIGN=MIDDLE>\n"
190 "Part %s: %s (%s, %d bytes)</A><BR>\n",
191 msgnum, mime_partnum,
192 msgnum, mime_partnum,
193 mime_partnum, mime_filename,
194 mime_content_type, mime_length);
201 /* Generate a reply-to address */
202 if (strlen(rfca) > 0) {
203 strcpy(reply_to, rfca);
206 if (strlen(node) > 0) {
207 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
211 snprintf(reply_to, sizeof(reply_to), "%s", from);
217 wprintf("</FONT></TD>");
219 /* begin right-hand toolbar */
220 wprintf("<TD ALIGN=RIGHT>\n"
221 "<TABLE BORDER=0><TR>\n");
224 wprintf("<TD BGCOLOR=\"AAAADD\">"
225 "<A HREF=\"/readfwd?startmsg=%ld", msgnum);
226 wprintf("&maxmsgs=1&summary=0\">Read</A>"
230 wprintf("<TD BGCOLOR=\"AAAADD\">"
231 "<A HREF=\"/display_enter?recp=");
232 urlescputs(reply_to);
233 wprintf("\"><FONT SIZE=-1>Reply</FONT></A>"
236 if (WC->is_room_aide) {
237 wprintf("<TD BGCOLOR=\"AAAADD\">"
238 "<A HREF=\"/confirm_move_msg"
240 "\"><FONT SIZE=-1>Move</FONT></A>"
243 wprintf("<TD BGCOLOR=\"AAAADD\">"
244 "<A HREF=\"/delete_msg"
246 "onClick=\"return confirm('Delete this message?');\""
247 "><FONT SIZE=-1>Del</FONT></A>"
251 wprintf("</TR></TABLE>\n"
254 /* end right-hand toolbar */
257 if (strlen(m_subject) > 0) {
258 wprintf("<TR><TD><FONT COLOR=\"FFFFFF\">"
260 "</TD><TD> </TD></TR>\n", m_subject);
263 wprintf("</TR></TABLE>\n");
266 while (serv_gets(buf), strcmp(buf, "000")) ;
270 if (format_type == 0) {
273 while (serv_gets(buf), strcmp(buf, "000")) {
274 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
275 buf[strlen(buf) - 1] = 0;
277 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
278 wprintf("<FONT COLOR=\"000044\"><I>");
280 } else if ((bq == 1) &&
281 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
282 wprintf("</FONT></I>");
288 wprintf("</TT><BR>\n");
293 if (mime_http != NULL) {
294 wprintf("%s", mime_http);
302 * load message pointers from the server
304 int load_msg_ptrs(servcmd)
314 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
317 while (serv_gets(buf), strcmp(buf, "000")) {
318 WC->msgarr[nummsgs] = atol(buf);
326 * command loop for reading messages
328 void readloop(char *oper)
335 int num_displayed = 0;
337 int remaining_messages;
339 int lowest_displayed = 0;
340 int highest_displayed = 0;
342 startmsg = atol(bstr("startmsg"));
343 maxmsgs = atoi(bstr("maxmsgs"));
344 is_summary = atoi(bstr("summary"));
345 if (maxmsgs == 0) maxmsgs = 20;
349 if (!strcmp(oper, "readnew")) {
350 strcpy(cmd, "MSGS NEW");
351 } else if (!strcmp(oper, "readold")) {
352 strcpy(cmd, "MSGS OLD");
354 strcpy(cmd, "MSGS ALL");
357 nummsgs = load_msg_ptrs(cmd);
359 if (!strcmp(oper, "readnew")) {
360 wprintf("<EM>No new messages in this room.</EM>\n");
361 } else if (!strcmp(oper, "readold")) {
362 wprintf("<EM>No old messages in this room.</EM>\n");
364 wprintf("<EM>This room is empty.</EM>\n");
369 if (startmsg == 0L) startmsg = WC->msgarr[0];
370 remaining_messages = 0;
372 for (a = 0; a < nummsgs; ++a) {
373 if (WC->msgarr[a] >= startmsg) {
374 ++remaining_messages;
378 for (a = 0; ( (a < nummsgs) && (num_displayed < maxmsgs) ) ; ++a) {
379 if (WC->msgarr[a] >= startmsg) {
381 read_message(WC->msgarr[a], is_summary);
382 if (lowest_displayed == 0) lowest_displayed = a;
383 highest_displayed = a;
384 if (is_summary) wprintf("<BR>");
387 --remaining_messages;
391 /* Bump these because although we're thinking in zero base, the user
392 * is a drooling idiot and is thinking in one base.
398 * If we're not currently looking at ALL requested
399 * messages, then display the selector bar
401 if (num_displayed < nummsgs) {
404 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=DDDDDD><TR><TD>"
405 "You are reading #%d-%d of %d messages.</TD>\n"
406 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
407 lowest_displayed, highest_displayed, nummsgs);
409 for (b=0; b<nummsgs; b = b + maxmsgs) {
412 if (hi > nummsgs) hi = nummsgs;
413 if (WC->msgarr[b] != startmsg) {
414 wprintf("<A HREF=\"/%s"
426 wprintf("%d-%d \n", lo, hi);
430 wprintf("<A HREF=\"/%s?startmsg=%ld"
431 "&maxmsgs=999999&summary=%d\">"
433 "</A> ",
435 WC->msgarr[0], is_summary);
436 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
439 DONE: wDumpContent(1);
446 * Post message (or don't post message)
448 * Note regarding the "dont_post" variable:
449 * A random value (actually, it's just a timestamp) is inserted as a hidden
450 * field called "postseq" when the display_enter page is generated. This
451 * value is checked when posting, using the static variable dont_post. If a
452 * user attempts to post twice using the same dont_post value, the message is
453 * discarded. This prevents the accidental double-saving of the same message
454 * if the user happens to click the browser "back" button.
456 void post_message(void)
459 static long dont_post = (-1L);
463 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
464 strcpy(buf, bstr("sc"));
465 if (strcasecmp(buf, "Save message")) {
466 wprintf("Cancelled. Message was not posted.<BR>\n");
467 } else if (atol(bstr("postseq")) == dont_post) {
468 wprintf("Automatically cancelled because you have already "
469 "saved this message.<BR>\n");
471 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
475 text_to_server(bstr("msgtext"));
477 wprintf("Message has been posted.<BR>\n");
478 dont_post = atol(bstr("postseq"));
480 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
495 * prompt for a recipient (to be called from display_enter() only)
497 void prompt_for_recipient()
500 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
501 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
502 wprintf("<B>Send private e-mail</B>\n");
503 wprintf("</FONT></TD></TR></TABLE>\n");
506 wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
507 wprintf("Enter recipient: ");
508 wprintf("<INPUT TYPE=\"text\" NAME=\"recp\" MAXLENGTH=\"64\"><BR>\n");
509 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
510 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
511 wprintf("</FORM></CENTER>\n");
517 * display the message entry screen
519 void display_enter(void)
527 wprintf("<FACE=\"Arial,Helvetica,sans-serif\">");
529 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
533 if (!strncmp(buf, "570", 3)) {
534 if (strlen(bstr("recp")) > 0) {
535 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
537 prompt_for_recipient();
541 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
546 tm = (struct tm *) localtime(&now);
547 strcpy(buf, (char *) asctime(tm));
548 buf[strlen(buf) - 1] = 0;
549 strcpy(&buf[16], &buf[19]);
550 wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
551 wprintf("from %s ", WC->wc_username);
552 if (strlen(bstr("recp")) > 0)
553 wprintf("to %s ", bstr("recp"));
554 wprintf("in %s> ", WC->wc_roomname);
555 wprintf("</B></FONT><BR><CENTER>\n");
557 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
558 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
560 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
562 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
563 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
565 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
566 "WIDTH=80></TEXTAREA><P>\n");
568 wprintf("</FORM></CENTER>\n");
569 DONE: wDumpContent(1);
580 void delete_msg(void)
585 msgid = atol(bstr("msgid"));
589 sprintf(buf, "DELE %ld", msgid);
592 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
601 * Confirm move of a message
603 void confirm_move_msg(void)
609 msgid = atol(bstr("msgid"));
613 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
614 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
615 wprintf("<B>Confirm move of message</B>\n");
616 wprintf("</FONT></TD></TR></TABLE>\n");
620 wprintf("Please select the room to which you would like this message moved:<BR>\n");
622 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
623 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
627 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
631 while (serv_gets(buf), strcmp(buf, "000")) {
632 extract(targ, buf, 0);
638 wprintf("</SELECT>\n");
641 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
642 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
643 wprintf("</FORM></CENTER>\n");
645 wprintf("</CENTER>\n");
656 msgid = atol(bstr("msgid"));
660 if (!strcasecmp(bstr("yesno"), "Move")) {
661 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
664 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
666 wprintf("<EM>Message not deleted.</EM><BR>\n");