+
+ while (instant_msgs != 0) {
+ r = CtdlIPCGetInstantMessage(ipc_for_signal_handlers, &listing, buf);
+ if (r / 100 != 1)
+ return;
+
+ instant_msgs = extract_int(buf, 0);
+ timestamp = extract_long(buf, 1);
+ flags = extract_int(buf, 2);
+ extract_token(sender, buf, 3, '|', sizeof sender);
+ extract_token(node, buf, 4, '|', sizeof node);
+ strcpy(last_paged, sender);
+
+ localtime_r(×tamp, &stamp);
+
+ /* If the page is a Logoff Request, honor it. */
+ if (flags & 2) {
+ termn8 = 1;
+ return;
+ }
+
+ if (!IsEmptyStr(rc_exp_cmd)) {
+ outpipe = popen(rc_exp_cmd, "w");
+ if (outpipe != NULL) {
+ /* Header derived from flags */
+ if (flags & 2)
+ fprintf(outpipe,
+ "Please log off now, as requested ");
+ else if (flags & 1)
+ fprintf(outpipe, "Broadcast message ");
+ else if (flags & 4)
+ fprintf(outpipe, "Chat request ");
+ else
+ fprintf(outpipe, "Message ");
+ /* Timestamp. Can this be improved? */
+ if (stamp.tm_hour == 0 || stamp.tm_hour == 12)
+ fprintf(outpipe, "at 12:%02d%cm",
+ stamp.tm_min,
+ stamp.tm_hour ? 'p' : 'a');
+ else if (stamp.tm_hour > 12) /* pm */
+ fprintf(outpipe, "at %d:%02dpm",
+ stamp.tm_hour - 12,
+ stamp.tm_min);
+ else /* am */
+ fprintf(outpipe, "at %d:%02dam",
+ stamp.tm_hour, stamp.tm_min);
+ fprintf(outpipe, " from %s", sender);
+ if (strncmp(ipc_for_signal_handlers->ServInfo.nodename, node, 32))
+ fprintf(outpipe, " @%s", node);
+ fprintf(outpipe, ":\n%s\n", listing);
+ pclose(outpipe);
+ if (instant_msgs == 0)
+ return;
+ continue;
+ }
+ }
+ /* fall back to built-in instant message display */
+ scr_printf("\n");
+ lines_printed++;
+
+ /* Header derived from flags */
+ if (flags & 2)
+ scr_printf("Please log off now, as requested ");
+ else if (flags & 1)
+ scr_printf("Broadcast message ");
+ else if (flags & 4)
+ scr_printf("Chat request ");
+ else
+ scr_printf("Message ");
+
+ /* Timestamp. Can this be improved? */
+ if (stamp.tm_hour == 0 || stamp.tm_hour == 12)/* 12am/12pm */
+ scr_printf("at 12:%02d%cm", stamp.tm_min,
+ stamp.tm_hour ? 'p' : 'a');
+ else if (stamp.tm_hour > 12) /* pm */
+ scr_printf("at %d:%02dpm",
+ stamp.tm_hour - 12, stamp.tm_min);
+ else /* am */
+ scr_printf("at %d:%02dam", stamp.tm_hour, stamp.tm_min);
+
+ /* Sender */
+ scr_printf(" from %s", sender);
+
+ /* Remote node, if any */
+ if (strncmp(ipc_for_signal_handlers->ServInfo.nodename, node, 32))
+ scr_printf(" @%s", node);
+
+ scr_printf(":\n");
+ lines_printed++;
+ fmout(screenwidth, NULL, listing, NULL, 1, screenheight, -1, 0);
+ free(listing);
+
+ /* when running in curses mode, the scroll bar in most
+ xterm-style programs becomes useless, so it makes sense to
+ pause after a screenful of pages if the user has been idle
+ for a while. However, this is annoying to some of the users
+ who aren't in curses mode and tend to leave their clients
+ idle. keepalives become disabled, resulting in getting booted
+ when coming back to the idle session. but they probably have
+ a working scrollback in their terminal, so disable it in this
+ case:
+ */
+ if (!is_curses_enabled())
+ lines_printed = 0;
+ }
+ scr_printf("\n---\n");