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) {
101 sprintf(buf, "MSG0 %ld", msgnum);
105 wprintf("<STRONG>ERROR:</STRONG> %s<BR>\n", &buf[4]);
108 wprintf("<TABLE WIDTH=100%% BORDER=0 CELLSPACING=0 CELLPADDING=1 BGCOLOR=000077><TR><TD>\n");
110 if (!is_summary) wprintf("SIZE=+1 ");
111 wprintf("COLOR=\"FFFF00\"> ");
112 strcpy(m_subject, "");
114 while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
115 if (!strncasecmp(buf, "nhdr=yes", 8))
119 if (!strncasecmp(buf, "type=", 5))
120 format_type = atoi(&buf[5]);
121 if (!strncasecmp(buf, "from=", 5)) {
122 strcpy(from, &buf[5]);
127 if (!strncasecmp(buf, "subj=", 5))
128 strcpy(m_subject, &buf[5]);
129 if ((!strncasecmp(buf, "hnod=", 5))
130 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
131 wprintf("(%s) ", &buf[5]);
132 if ((!strncasecmp(buf, "room=", 5))
133 && (strcasecmp(&buf[5], WC->wc_roomname)))
134 wprintf("in %s> ", &buf[5]);
135 if (!strncasecmp(buf, "rfca=", 5)) {
136 strcpy(rfca, &buf[5]);
142 if (!strncasecmp(buf, "node=", 5)) {
143 if ( ((WC->room_flags & QR_NETWORK)
144 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
145 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
148 wprintf("@%s ", &buf[5]);
151 if (!strncasecmp(buf, "rcpt=", 5))
152 wprintf("to %s ", &buf[5]);
153 if (!strncasecmp(buf, "time=", 5)) {
154 fmt_date(now, atol(&buf[5]));
160 /* Generate a reply-to address */
161 if (strlen(rfca) > 0) {
162 strcpy(reply_to, rfca);
165 if (strlen(node) > 0) {
166 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
170 snprintf(reply_to, sizeof(reply_to), "%s", from);
176 wprintf("</FONT></TD>");
178 /* begin right-hand toolbar */
179 wprintf("<TD ALIGN=RIGHT>\n"
180 "<TABLE BORDER=0><TR>\n");
183 wprintf("<TD BGCOLOR=\"AAAADD\">"
184 "<A HREF=\"/readfwd?startmsg=%ld", msgnum);
185 wprintf("&maxmsgs=1&summary=0\">Read</A>"
189 wprintf("<TD BGCOLOR=\"AAAADD\">"
190 "<A HREF=\"/display_enter?recp=");
191 urlescputs(reply_to);
192 wprintf("\">Reply</A>"
195 if (WC->is_room_aide) {
196 wprintf("<TD BGCOLOR=\"AAAADD\">"
197 "<A HREF=\"/confirm_move_msg"
202 wprintf("<TD BGCOLOR=\"AAAADD\">"
203 "<A HREF=\"/confirm_delete_msg"
210 wprintf("</TR></TABLE>\n"
213 /* end right-hand toolbar */
216 if (strlen(m_subject) > 0) {
217 wprintf("<TR><TD><FONT COLOR=\"FFFFFF\">"
219 "</TD><TD> </TD></TR>\n", m_subject);
222 wprintf("</TR></TABLE>\n");
225 while (serv_gets(buf), strcmp(buf, "000")) ;
229 if (format_type == 0) {
232 while (serv_gets(buf), strcmp(buf, "000")) {
233 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
234 buf[strlen(buf) - 1] = 0;
236 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
237 wprintf("<FONT COLOR=\"000044\"><I>");
239 } else if ((bq == 1) &&
240 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
241 wprintf("</FONT></I>");
247 wprintf("</TT><BR>\n");
256 * load message pointers from the server
258 int load_msg_ptrs(servcmd)
268 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
271 while (serv_gets(buf), strcmp(buf, "000")) {
272 WC->msgarr[nummsgs] = atol(buf);
280 * command loop for reading messages
282 void readloop(char *oper)
289 int num_displayed = 0;
291 int remaining_messages;
293 int lowest_displayed = 0;
294 int highest_displayed = 0;
296 startmsg = atol(bstr("startmsg"));
297 maxmsgs = atoi(bstr("maxmsgs"));
298 is_summary = atoi(bstr("summary"));
299 if (maxmsgs == 0) maxmsgs = 20;
303 if (!strcmp(oper, "readnew")) {
304 strcpy(cmd, "MSGS NEW");
305 } else if (!strcmp(oper, "readold")) {
306 strcpy(cmd, "MSGS OLD");
308 strcpy(cmd, "MSGS ALL");
311 nummsgs = load_msg_ptrs(cmd);
313 if (!strcmp(oper, "readnew")) {
314 wprintf("<EM>No new messages in this room.</EM>\n");
315 } else if (!strcmp(oper, "readold")) {
316 wprintf("<EM>No old messages in this room.</EM>\n");
318 wprintf("<EM>This room is empty.</EM>\n");
323 if (startmsg == 0L) startmsg = WC->msgarr[0];
324 remaining_messages = 0;
326 for (a = 0; a < nummsgs; ++a) {
327 if (WC->msgarr[a] >= startmsg) {
328 ++remaining_messages;
332 for (a = 0; ( (a < nummsgs) && (num_displayed < maxmsgs) ) ; ++a) {
333 if (WC->msgarr[a] >= startmsg) {
335 read_message(WC->msgarr[a], is_summary);
336 if (lowest_displayed == 0) lowest_displayed = a;
337 highest_displayed = a;
338 if (is_summary) wprintf("<BR>");
341 --remaining_messages;
345 /* Bump these because although we're thinking in zero base, the user
346 * is a drooling idiot and is thinking in one base.
352 * If we're not currently looking at ALL requested
353 * messages, then display the selector bar
355 if (num_displayed < nummsgs) {
358 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=DDDDDD><TR><TD>"
359 "You are reading #%d-%d of %d messages.</TD>\n"
360 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
361 lowest_displayed, highest_displayed, nummsgs);
363 for (b=0; b<nummsgs; b = b + maxmsgs) {
366 if (hi > nummsgs) hi = nummsgs;
367 if (WC->msgarr[b] != startmsg) {
368 wprintf("<A HREF=\"/readfwd"
379 wprintf("%d-%d \n", lo, hi);
383 wprintf("<A HREF=\"/readfwd?startmsg=%ld"
384 "&maxmsgs=999999&summary=%d\">"
386 "</A> ",
387 WC->msgarr[0], is_summary);
388 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
391 DONE: wDumpContent(1);
398 * Post message (or don't post message)
400 * Note regarding the "dont_post" variable:
401 * A random value (actually, it's just a timestamp) is inserted as a hidden
402 * field called "postseq" when the display_enter page is generated. This
403 * value is checked when posting, using the static variable dont_post. If a
404 * user attempts to post twice using the same dont_post value, the message is
405 * discarded. This prevents the accidental double-saving of the same message
406 * if the user happens to click the browser "back" button.
408 void post_message(void)
411 static long dont_post = (-1L);
415 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
416 strcpy(buf, bstr("sc"));
417 if (strcasecmp(buf, "Save message")) {
418 wprintf("Cancelled. Message was not posted.<BR>\n");
419 } else if (atol(bstr("postseq")) == dont_post) {
420 wprintf("Automatically cancelled because you have already "
421 "saved this message.<BR>\n");
423 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
427 text_to_server(bstr("msgtext"));
429 wprintf("Message has been posted.<BR>\n");
430 dont_post = atol(bstr("postseq"));
432 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
447 * prompt for a recipient (to be called from display_enter() only)
449 void prompt_for_recipient()
452 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
453 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
454 wprintf("<B>Send private e-mail</B>\n");
455 wprintf("</FONT></TD></TR></TABLE>\n");
458 wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
459 wprintf("Enter recipient: ");
460 wprintf("<INPUT TYPE=\"text\" NAME=\"recp\" MAXLENGTH=\"64\"><BR>\n");
461 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
462 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
463 wprintf("</FORM></CENTER>\n");
469 * display the message entry screen
471 void display_enter(void)
479 wprintf("<FACE=\"Arial,Helvetica,sans-serif\">");
481 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
485 if (!strncmp(buf, "570", 3)) {
486 if (strlen(bstr("recp")) > 0) {
487 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
489 prompt_for_recipient();
493 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
498 tm = (struct tm *) localtime(&now);
499 strcpy(buf, (char *) asctime(tm));
500 buf[strlen(buf) - 1] = 0;
501 strcpy(&buf[16], &buf[19]);
502 wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
503 wprintf("from %s ", WC->wc_username);
504 if (strlen(bstr("recp")) > 0)
505 wprintf("to %s ", bstr("recp"));
506 wprintf("in %s> ", WC->wc_roomname);
507 wprintf("</B></FONT><BR><CENTER>\n");
509 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
510 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
512 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
514 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
515 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
517 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
518 "WIDTH=80></TEXTAREA><P>\n");
520 wprintf("</FORM></CENTER>\n");
521 DONE: wDumpContent(1);
532 * Confirm deletion of a message
534 void confirm_delete_msg(void)
538 msgid = atol(bstr("msgid"));
542 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
543 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
544 wprintf("<B>Confirm deletion of message</B>\n");
545 wprintf("</FONT></TD></TR></TABLE>\n");
549 wprintf("Are you sure you want to delete this message? <BR>\n");
551 wprintf("<FORM METHOD=\"POST\" ACTION=\"/delete_msg\">\n");
552 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
554 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Yes\">");
555 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"No\">");
556 wprintf("</FORM></CENTER>\n");
558 wprintf("</CENTER>\n");
564 void delete_msg(void)
569 msgid = atol(bstr("msgid"));
573 if (!strcasecmp(bstr("yesno"), "Yes")) {
574 sprintf(buf, "DELE %ld", msgid);
577 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
579 wprintf("<EM>Message not deleted.</EM><BR>\n");
589 * Confirm move of a message
591 void confirm_move_msg(void)
597 msgid = atol(bstr("msgid"));
601 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
602 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
603 wprintf("<B>Confirm move of message</B>\n");
604 wprintf("</FONT></TD></TR></TABLE>\n");
608 wprintf("Please select the room to which you would like this message moved:<BR>\n");
610 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
611 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
615 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
619 while (serv_gets(buf), strcmp(buf, "000")) {
620 extract(targ, buf, 0);
626 wprintf("</SELECT>\n");
629 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
630 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
631 wprintf("</FORM></CENTER>\n");
633 wprintf("</CENTER>\n");
644 msgid = atol(bstr("msgid"));
648 if (!strcasecmp(bstr("yesno"), "Move")) {
649 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
652 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
654 wprintf("<EM>Message not deleted.</EM><BR>\n");