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=CCCCCC><TR><TD>\n");
110 if (!is_summary) wprintf("SIZE=+1 ");
111 wprintf("COLOR=\"000000\"> ");
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]);
123 wprintf("from <A HREF=\"/showuser&who=");
129 if (!strncasecmp(buf, "subj=", 5))
130 strcpy(m_subject, &buf[5]);
131 if ((!strncasecmp(buf, "hnod=", 5))
132 && (strcasecmp(&buf[5], serv_info.serv_humannode)))
133 wprintf("(%s) ", &buf[5]);
134 if ((!strncasecmp(buf, "room=", 5))
135 && (strcasecmp(&buf[5], WC->wc_roomname)))
136 wprintf("in %s> ", &buf[5]);
137 if (!strncasecmp(buf, "rfca=", 5)) {
138 strcpy(rfca, &buf[5]);
144 if (!strncasecmp(buf, "node=", 5)) {
145 if ( ((WC->room_flags & QR_NETWORK)
146 || ((strcasecmp(&buf[5], serv_info.serv_nodename)
147 && (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
150 wprintf("@%s ", &buf[5]);
153 if (!strncasecmp(buf, "rcpt=", 5))
154 wprintf("to %s ", &buf[5]);
155 if (!strncasecmp(buf, "time=", 5)) {
156 fmt_date(now, atol(&buf[5]));
162 /* Generate a reply-to address */
163 if (strlen(rfca) > 0) {
164 strcpy(reply_to, rfca);
167 if (strlen(node) > 0) {
168 snprintf(reply_to, sizeof(reply_to), "%s @ %s",
172 snprintf(reply_to, sizeof(reply_to), "%s", from);
178 wprintf("</FONT></TD>");
180 /* begin right-hand toolbar */
181 wprintf("<TD ALIGN=RIGHT>\n"
182 "<TABLE BORDER=0><TR>\n");
185 wprintf("<TD BGCOLOR=\"AAAADD\">"
186 "<A HREF=\"/readfwd?startmsg=%ld", msgnum);
187 wprintf("&maxmsgs=1&summary=0\">Read</A>"
191 wprintf("<TD BGCOLOR=\"AAAADD\">"
192 "<A HREF=\"/display_enter?recp=");
193 urlescputs(reply_to);
194 wprintf("\"><FONT SIZE=-1>Reply</FONT></A>"
197 if (WC->is_room_aide) {
198 wprintf("<TD BGCOLOR=\"AAAADD\">"
199 "<A HREF=\"/confirm_move_msg"
201 "\"><FONT SIZE=-1>Move</FONT></A>"
204 wprintf("<TD BGCOLOR=\"AAAADD\">"
205 "<A HREF=\"/delete_msg"
207 "onClick=\"return confirm('Delete this message?');\""
208 "><FONT SIZE=-1>Del</FONT></A>"
212 wprintf("</TR></TABLE>\n"
215 /* end right-hand toolbar */
218 if (strlen(m_subject) > 0) {
219 wprintf("<TR><TD><FONT COLOR=\"FFFFFF\">"
221 "</TD><TD> </TD></TR>\n", m_subject);
224 wprintf("</TR></TABLE>\n");
227 while (serv_gets(buf), strcmp(buf, "000")) ;
231 if (format_type == 0) {
234 while (serv_gets(buf), strcmp(buf, "000")) {
235 while ((strlen(buf) > 0) && (isspace(buf[strlen(buf) - 1])))
236 buf[strlen(buf) - 1] = 0;
238 ((!strncmp(buf, ">", 1)) || (!strncmp(buf, " >", 2)) || (!strncmp(buf, " :-)", 4)))) {
239 wprintf("<FONT COLOR=\"000044\"><I>");
241 } else if ((bq == 1) &&
242 (strncmp(buf, ">", 1)) && (strncmp(buf, " >", 2)) && (strncmp(buf, " :-)", 4))) {
243 wprintf("</FONT></I>");
249 wprintf("</TT><BR>\n");
258 * load message pointers from the server
260 int load_msg_ptrs(servcmd)
270 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
273 while (serv_gets(buf), strcmp(buf, "000")) {
274 WC->msgarr[nummsgs] = atol(buf);
282 * command loop for reading messages
284 void readloop(char *oper)
291 int num_displayed = 0;
293 int remaining_messages;
295 int lowest_displayed = 0;
296 int highest_displayed = 0;
298 startmsg = atol(bstr("startmsg"));
299 maxmsgs = atoi(bstr("maxmsgs"));
300 is_summary = atoi(bstr("summary"));
301 if (maxmsgs == 0) maxmsgs = 20;
305 if (!strcmp(oper, "readnew")) {
306 strcpy(cmd, "MSGS NEW");
307 } else if (!strcmp(oper, "readold")) {
308 strcpy(cmd, "MSGS OLD");
310 strcpy(cmd, "MSGS ALL");
313 nummsgs = load_msg_ptrs(cmd);
315 if (!strcmp(oper, "readnew")) {
316 wprintf("<EM>No new messages in this room.</EM>\n");
317 } else if (!strcmp(oper, "readold")) {
318 wprintf("<EM>No old messages in this room.</EM>\n");
320 wprintf("<EM>This room is empty.</EM>\n");
325 if (startmsg == 0L) startmsg = WC->msgarr[0];
326 remaining_messages = 0;
328 for (a = 0; a < nummsgs; ++a) {
329 if (WC->msgarr[a] >= startmsg) {
330 ++remaining_messages;
334 for (a = 0; ( (a < nummsgs) && (num_displayed < maxmsgs) ) ; ++a) {
335 if (WC->msgarr[a] >= startmsg) {
337 read_message(WC->msgarr[a], is_summary);
338 if (lowest_displayed == 0) lowest_displayed = a;
339 highest_displayed = a;
340 if (is_summary) wprintf("<BR>");
343 --remaining_messages;
347 /* Bump these because although we're thinking in zero base, the user
348 * is a drooling idiot and is thinking in one base.
354 * If we're not currently looking at ALL requested
355 * messages, then display the selector bar
357 if (num_displayed < nummsgs) {
360 "<TABLE BORDER=0 WIDTH=100%% BGCOLOR=DDDDDD><TR><TD>"
361 "You are reading #%d-%d of %d messages.</TD>\n"
362 "<TD ALIGN=RIGHT><FONT SIZE=+1>",
363 lowest_displayed, highest_displayed, nummsgs);
365 for (b=0; b<nummsgs; b = b + maxmsgs) {
368 if (hi > nummsgs) hi = nummsgs;
369 if (WC->msgarr[b] != startmsg) {
370 wprintf("<A HREF=\"/%s"
382 wprintf("%d-%d \n", lo, hi);
386 wprintf("<A HREF=\"/%s?startmsg=%ld"
387 "&maxmsgs=999999&summary=%d\">"
389 "</A> ",
391 WC->msgarr[0], is_summary);
392 wprintf("</TD></TR></TABLE></CENTER><HR>\n");
395 DONE: wDumpContent(1);
402 * Post message (or don't post message)
404 * Note regarding the "dont_post" variable:
405 * A random value (actually, it's just a timestamp) is inserted as a hidden
406 * field called "postseq" when the display_enter page is generated. This
407 * value is checked when posting, using the static variable dont_post. If a
408 * user attempts to post twice using the same dont_post value, the message is
409 * discarded. This prevents the accidental double-saving of the same message
410 * if the user happens to click the browser "back" button.
412 void post_message(void)
415 static long dont_post = (-1L);
419 wprintf("<FONT FACE=\"Arial,Helvetica,sans-serif\">");
420 strcpy(buf, bstr("sc"));
421 if (strcasecmp(buf, "Save message")) {
422 wprintf("Cancelled. Message was not posted.<BR>\n");
423 } else if (atol(bstr("postseq")) == dont_post) {
424 wprintf("Automatically cancelled because you have already "
425 "saved this message.<BR>\n");
427 sprintf(buf, "ENT0 1|%s|0|0", bstr("recp"));
431 text_to_server(bstr("msgtext"));
433 wprintf("Message has been posted.<BR>\n");
434 dont_post = atol(bstr("postseq"));
436 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
451 * prompt for a recipient (to be called from display_enter() only)
453 void prompt_for_recipient()
456 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=007700><TR><TD>");
457 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
458 wprintf("<B>Send private e-mail</B>\n");
459 wprintf("</FONT></TD></TR></TABLE>\n");
462 wprintf("<FORM METHOD=\"POST\" ACTION=\"/display_enter\">\n");
463 wprintf("Enter recipient: ");
464 wprintf("<INPUT TYPE=\"text\" NAME=\"recp\" MAXLENGTH=\"64\"><BR>\n");
465 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Enter message\">");
466 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\">");
467 wprintf("</FORM></CENTER>\n");
473 * display the message entry screen
475 void display_enter(void)
483 wprintf("<FACE=\"Arial,Helvetica,sans-serif\">");
485 sprintf(buf, "ENT0 0|%s|0|0", bstr("recp"));
489 if (!strncmp(buf, "570", 3)) {
490 if (strlen(bstr("recp")) > 0) {
491 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
493 prompt_for_recipient();
497 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
502 tm = (struct tm *) localtime(&now);
503 strcpy(buf, (char *) asctime(tm));
504 buf[strlen(buf) - 1] = 0;
505 strcpy(&buf[16], &buf[19]);
506 wprintf("</CENTER><FONT COLOR=\"440000\"><B> %s ", &buf[4]);
507 wprintf("from %s ", WC->wc_username);
508 if (strlen(bstr("recp")) > 0)
509 wprintf("to %s ", bstr("recp"));
510 wprintf("in %s> ", WC->wc_roomname);
511 wprintf("</B></FONT><BR><CENTER>\n");
513 wprintf("<FORM METHOD=\"POST\" ACTION=\"/post\">\n");
514 wprintf("<INPUT TYPE=\"hidden\" NAME=\"recp\" VALUE=\"%s\">\n",
516 wprintf("<INPUT TYPE=\"hidden\" NAME=\"postseq\" VALUE=\"%ld\">\n",
518 wprintf("<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Save message\">"
519 "<INPUT TYPE=\"submit\" NAME=\"sc\" VALUE=\"Cancel\"><BR>\n");
521 wprintf("<TEXTAREA NAME=\"msgtext\" wrap=soft ROWS=30 COLS=80 "
522 "WIDTH=80></TEXTAREA><P>\n");
524 wprintf("</FORM></CENTER>\n");
525 DONE: wDumpContent(1);
536 void delete_msg(void)
541 msgid = atol(bstr("msgid"));
545 sprintf(buf, "DELE %ld", msgid);
548 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
557 * Confirm move of a message
559 void confirm_move_msg(void)
565 msgid = atol(bstr("msgid"));
569 wprintf("<TABLE WIDTH=100%% BORDER=0 BGCOLOR=770000><TR><TD>");
570 wprintf("<FONT SIZE=+1 COLOR=\"FFFFFF\"");
571 wprintf("<B>Confirm move of message</B>\n");
572 wprintf("</FONT></TD></TR></TABLE>\n");
576 wprintf("Please select the room to which you would like this message moved:<BR>\n");
578 wprintf("<FORM METHOD=\"POST\" ACTION=\"/move_msg\">\n");
579 wprintf("<INPUT TYPE=\"hidden\" NAME=\"msgid\" VALUE=\"%s\">\n",
583 wprintf("<SELECT NAME=\"target_room\" SIZE=5>\n");
587 while (serv_gets(buf), strcmp(buf, "000")) {
588 extract(targ, buf, 0);
594 wprintf("</SELECT>\n");
597 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Move\">");
598 wprintf("<INPUT TYPE=\"submit\" NAME=\"yesno\" VALUE=\"Cancel\">");
599 wprintf("</FORM></CENTER>\n");
601 wprintf("</CENTER>\n");
612 msgid = atol(bstr("msgid"));
616 if (!strcasecmp(bstr("yesno"), "Move")) {
617 sprintf(buf, "MOVE %ld|%s", msgid, bstr("target_room"));
620 wprintf("<EM>%s</EM><BR>\n", &buf[4]);
622 wprintf("<EM>Message not deleted.</EM><BR>\n");