#include "tools.h"
#include "rooms.h"
#include "client_chat.h"
+#include "citadel_ipc.h"
#ifndef HAVE_SNPRINTF
#include "snprintf.h"
#endif
int flags = 0;
char sender[64];
char node[64];
+ char *listing = NULL;
+ int r; /* IPC result code */
if (express_msgs == 0)
return;
}
while (express_msgs != 0) {
- serv_puts("GEXP");
- serv_gets(buf);
- if (buf[0] != '1')
+ r = CtdlIPCGetInstantMessage(&listing, buf);
+ if (r / 100 != 1)
return;
- express_msgs = extract_int(&buf[4], 0);
- timestamp = extract_long(&buf[4], 1);
- flags = extract_int(&buf[4], 2);
- extract(sender, &buf[4], 3);
- extract(node, &buf[4], 4);
+ express_msgs = extract_int(buf, 0);
+ timestamp = extract_long(buf, 1);
+ flags = extract_int(buf, 2);
+ extract(sender, buf, 3);
+ extract(node, buf, 4);
strcpy(last_paged, sender);
stamp = localtime(×tamp);
fprintf(outpipe, " from %s", sender);
if (strncmp(serv_info.serv_nodename, node, 32))
fprintf(outpipe, " @%s", node);
- fprintf(outpipe, ":\n");
- while (serv_gets(buf), strcmp(buf, "000")) {
- fprintf(outpipe, "%s\n", buf);
- }
+ fprintf(outpipe, ":\n%s\n", listing);
pclose(outpipe);
if (express_msgs == 0)
return;
scr_printf(":\n");
lines_printed++;
- fmout(screenwidth, NULL, NULL, 1, screenheight, -1, 0);
+ 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
*/
int fmout(
int width, /* screen width to use */
- FILE *fpin, /* file to read from, or NULL to read from server */
+ FILE *fpin, /* file to read from, or NULL to format given text */
+ char *text, /* Text to be formatted (when fpin is NULL) */
FILE *fpout, /* File to write to, or NULL to write to screen */
char pagin, /* nonzero if we should use the paginator */
int height, /* screen height to use */
int starting_lp,/* starting value for lines_printed, -1 for global */
char subst) /* nonzero if we should use hypertext mode */
{
- int a, b, c, d, old;
+ int a, b, c, old;
int real = (-1);
char aaa[140];
char buffer[512];
+ char *e;
int eof_flag = 0;
num_urls = 0; /* Start with a clean slate of embedded URL's */
old = 255;
strcpy(buffer, "");
c = 1; /* c is the current pos */
+ e = text; /* e is pointer to current pos */
FMTA: while ((eof_flag == 0) && (strlen(buffer) < 126)) {
if (fpin != NULL) { /* read from file */
buffer[strlen(buffer) + 1] = 0;
buffer[strlen(buffer)] = a;
}
- } else { /* read from server */
- d = strlen(buffer);
- serv_gets(&buffer[d]);
- while ((!isspace(buffer[d])) && (isspace(buffer[strlen(buffer) - 1])))
- buffer[strlen(buffer) - 1] = 0;
- if (!strcmp(&buffer[d], "000")) {
- buffer[d] = 0;
+ } else { /* read from text */
+ if (!*e) {
eof_flag = 1;
while (isspace(buffer[strlen(buffer) - 1]))
buffer[strlen(buffer) - 1] = 0;
+ buffer[strlen(buffer) + 1] = 0;
+ buffer[strlen(buffer)] = 10;
+ }
+ if (eof_flag == 0) {
+ a = *e++;
+ buffer[strlen(buffer) + 1] = 0;
+ buffer[strlen(buffer)] = a;
}
- d = strlen(buffer);
- buffer[d] = 10;
- buffer[d + 1] = 0;
}
}
goto FMTA;
/* keypress caught; drain the server */
-OOPS: do {
+OOPS: /* do {
serv_gets(aaa);
- } while (strcmp(aaa, "000"));
+ } while (strcmp(aaa, "000")); */
FMTEND:
if (fpout) {
#include "commands.h"
#include "rooms.h"
#include "tools.h"
+#include "citadel_ipc.h"
#ifndef HAVE_SNPRINTF
#include "snprintf.h"
#endif
int format_type = 0;
int fr = 0;
int nhdr = 0;
+ struct ctdlipcmessage *message = NULL;
+ int r; /* IPC response code */
sigcaught = 0;
sttybbs(1);
- snprintf(buf, sizeof buf, "MSG0 %ld|%d", num, (pagin == READ_HEADER ? 1 : 0));
- serv_puts(buf);
- serv_gets(buf);
- if (buf[0] != '1') {
- err_printf("*** msg #%ld: %s\n", num, buf);
+ r = CtdlIPCGetSingleMessage(num, (pagin == READ_HEADER ? 1 : 0), 0,
+ &message, buf);
+ if (r / 100 != 1) {
+ err_printf("*** msg #%ld: %d %s\n", num, r, buf);
++lines_printed;
lines_printed =
checkpagin(lines_printed, pagin, screenheight);
color(BRIGHT_CYAN);
}
+ /* View headers only */
if (pagin == 2) {
- while (serv_gets(buf), strcmp(buf, "000")) {
- if (buf[4] == '=') {
- if (dest) {
- fprintf(dest, "%s\n", buf);
- } else {
- scr_printf("%s\n", buf);
- ++lines_printed;
- lines_printed =
- checkpagin(lines_printed,
- pagin, screenheight);
- }
+ sprintf(buf, "nhdr=%s\nfrom=%s\ntype=%d\nmsgn=%s\n",
+ message->nhdr ? "yes" : "no",
+ message->author, message->type,
+ message->msgid);
+ /* FIXME output buf */
+ if (strlen(message->subject)) {
+ sprintf(buf, "subj=%s\n", message->subject);
+ /* FIXME: output buf */
+ }
+ if (strlen(message->email)) {
+ sprintf(buf, "rfca=%s\n", message->email);
+ /* FIXME: output buf */
+ }
+ sprintf(buf, "hnod=%s\nroom=%s\nnode=%s\ntime=%ld\n",
+ message->hnod, message->room,
+ message->node, message->time);
+ if (strlen(message->recipient)) {
+ sprintf(buf, "rcpt=%s\n", message->recipient);
+ /* FIXME: output buf */
+ }
+ if (message->attachments) {
+ struct parts *ptr;
+
+ for (ptr = message->attachments; ptr; ptr = ptr->next) {
+ sprintf(buf, "part=%s|%s|%s|%s|%s|%ld\n",
+ ptr->name, ptr->filename, ptr->number,
+ ptr->disposition, ptr->mimetype,
+ ptr->length);
+ /* FIXME: output buf */
}
}
sttybbs(0);
return (0);
}
- while (serv_gets(buf), strncasecmp(buf, "text", 4)) {
- if (!strncasecmp(buf, "nhdr=yes", 8))
- nhdr = 1;
- if (!strncasecmp(buf, "from=", 5)) {
- strcpy(from, &buf[5]);
+ if (rc_display_message_numbers) {
+ if (dest) {
+ fprintf(dest, "[#%s] ", message->msgid);
+ } else {
+ color(DIM_WHITE);
+ scr_printf("[");
+ color(BRIGHT_WHITE);
+ scr_printf("#%s", message->msgid);
+ color(DIM_WHITE);
+ scr_printf("] ");
}
- if (nhdr == 1)
- buf[0] = '_';
-
- if (!strncasecmp(buf, "type=", 5))
- format_type = atoi(&buf[5]);
- else if ((!strncasecmp(buf, "msgn=", 5))
- && (rc_display_message_numbers)) {
- if (dest) {
- fprintf(dest, "[#%s] ", &buf[5]);
- } else {
- color(DIM_WHITE);
- scr_printf("[");
- color(BRIGHT_WHITE);
- scr_printf("#%s", &buf[5]);
- color(DIM_WHITE);
- scr_printf("] ");
- }
+ }
+ if (nhdr == 1 && !is_room_aide) {
+ if (dest) {
+ fprintf(dest, " ****");
+ } else {
+ scr_printf(" ****");
}
- else if (!strncasecmp(buf, "from=", 5)) {
- if (dest) {
- fprintf(dest, "from %s ", &buf[5]);
- } else {
- color(DIM_WHITE);
- scr_printf("from ");
- color(BRIGHT_CYAN);
- scr_printf("%s ", &buf[5]);
+ } else {
+ fmt_date(now, sizeof now, message->time, 0);
+ if (dest) {
+ fprintf(dest, "%s from %s ", now, message->author);
+ if (strlen(message->email)) {
+ fprintf(dest, "<%s> ", message->email);
}
- }
- else if (!strncasecmp(buf, "subj=", 5)) {
- strcpy(m_subject, &buf[5]);
- }
- else if (!strncasecmp(buf, "rfca=", 5)) {
- safestrncpy(rfca, &buf[5], sizeof(rfca) - 5);
- if (dest) {
- fprintf(dest, "<%s> ", &buf[5]);
- } else {
+ } else {
+ color(BRIGHT_CYAN);
+ scr_printf("%s ", now);
+ color(DIM_WHITE);
+ scr_printf("from ");
+ color(BRIGHT_CYAN);
+ scr_printf("%s ", message->author);
+ if (strlen(message->email)) {
color(DIM_WHITE);
scr_printf("<");
color(BRIGHT_BLUE);
- scr_printf("%s", &buf[5]);
- color(DIM_WHITE);
+ scr_printf("%s", message->email);
+ color(DIM_WHITE);
scr_printf("> ");
}
}
- else if ((!strncasecmp(buf, "hnod=", 5))
- && (strcasecmp(&buf[5], serv_info.serv_humannode))
- && (strlen(rfca) == 0)) {
- if (dest) {
- fprintf(dest, "(%s) ", &buf[5]);
- } else {
- color(DIM_WHITE);
- scr_printf("(");
- color(BRIGHT_WHITE);
- scr_printf("%s", &buf[5]);
- color(DIM_WHITE);
- scr_printf(") ");
- }
- }
- else if ((!strncasecmp(buf, "room=", 5))
- && (strcasecmp(&buf[5], room_name))
- && (strlen(rfca) == 0)) {
- if (dest) {
- fprintf(dest, "in %s> ", &buf[5]);
- } else {
- color(DIM_WHITE);
- scr_printf("in ");
- color(BRIGHT_MAGENTA);
- scr_printf("%s> ", &buf[5]);
- }
- }
- else if (!strncasecmp(buf, "node=", 5)) {
- safestrncpy(node, &buf[5], sizeof(buf) - 5);
+ if (strlen(message->node)) {
if ((room_flags & QR_NETWORK)
- ||
- ((strcasecmp
- (&buf[5], serv_info.serv_nodename)
- &&
- (strcasecmp(&buf[5], serv_info.serv_fqdn)))))
- {
+ || ((strcasecmp(message->node, serv_info.serv_nodename)
+ && (strcasecmp(message->node, serv_info.serv_fqdn))))) {
if (strlen(rfca) == 0) {
if (dest) {
- fprintf(dest, "@%s ", &buf[5]);
+ fprintf(dest, "@%s ", message->node);
} else {
color(DIM_WHITE);
scr_printf("@");
color(BRIGHT_YELLOW);
- scr_printf("%s ", &buf[5]);
+ scr_printf("%s ", message->node);
}
}
}
}
- else if (!strncasecmp(buf, "rcpt=", 5)) {
+ if (strcasecmp(message->hnod, serv_info.serv_humannode)
+ && (strlen(message->hnod)) && (!strlen(rfca))) {
if (dest) {
- fprintf(dest, "to %s ", &buf[5]);
+ fprintf(dest, "(%s) ", message->hnod);
} else {
color(DIM_WHITE);
- scr_printf("to ");
- color(BRIGHT_CYAN);
- scr_printf("%s ", &buf[5]);
+ scr_printf("(");
+ color(BRIGHT_WHITE);
+ scr_printf("%s", message->hnod);
+ color(DIM_WHITE);
+ scr_printf(") ");
}
}
- else if (!strncasecmp(buf, "time=", 5)) {
- fmt_date(now, sizeof now, atol(&buf[5]), 0);
+ if (strcasecmp(message->room, room_name) && (strlen(rfca) == 0)) {
if (dest) {
- fprintf(dest, "%s ", now);
+ fprintf(dest, "in %s> ", message->room);
} else {
- scr_printf("%s ", now);
+ color(DIM_WHITE);
+ scr_printf("in ");
+ color(BRIGHT_MAGENTA);
+ scr_printf("%s> ", message->room);
}
}
- }
-
- if (nhdr == 1) {
- if (!is_room_aide) {
+ if (strlen(message->recipient)) {
if (dest) {
- fprintf(dest, " ****");
+ fprintf(dest, "to %s ", message->recipient);
} else {
- scr_printf(" ****");
- }
- } else {
- if (dest) {
- fprintf(dest, " %s", from);
- } else {
- scr_printf(" %s", from);
+ color(DIM_WHITE);
+ scr_printf("to ");
+ color(BRIGHT_CYAN);
+ scr_printf("%s ", message->recipient);
}
}
}
+
if (dest) {
fprintf(dest, "\n");
} else {
if (strlen(rfca) > 0) {
strcpy(reply_to, rfca);
} else {
- snprintf(reply_to, sizeof(reply_to), "%s @ %s", from,
- node);
+ snprintf(reply_to, sizeof(reply_to), "%s @ %s", from, node);
}
if (pagin == 1 && !dest)
lines_printed = checkpagin(lines_printed, pagin, screenheight);
}
- strcpy(reply_subject, m_subject);
- if (strlen(m_subject) > 0) {
+ strcpy(reply_subject, message->subject);
+ if (strlen(message->subject) > 0) {
if (dest) {
- fprintf(dest, "Subject: %s\n", m_subject);
+ fprintf(dest, "Subject: %s\n", message->subject);
} else {
- scr_printf("Subject: %s\n", m_subject);
+ scr_printf("Subject: %s\n", message->subject);
++lines_printed;
lines_printed = checkpagin(lines_printed,
pagin, screenheight);
}
if (format_type == 0) {
- fr = fmout(screenwidth, NULL, dest,
+ fr = fmout(screenwidth, NULL, message->text, dest,
((pagin == 1) ? 1 : 0), screenheight, (-1), 1);
} else {
- while (serv_gets(buf), strcmp(buf, "000")) {
+ int i;
+
+ for (i = 0; i < num_tokens(message->text, '\n'); i++) {
if (sigcaught == 0) {
+ extract_token(buf, message->text, i, '\n');
if (dest) {
fprintf(dest, "%s\n", buf);
} else {
- scr_printf("%s\n", buf);
+ scr_printf("%s\n", buf);
lines_printed = lines_printed + 1 +
(strlen(buf) / screenwidth);
lines_printed =
++lines_printed;
lines_printed = checkpagin(lines_printed, pagin, screenheight);
}
+ free(message->text);
+ free(message);
if (pagin == 1 && !dest)
color(DIM_WHITE);
if (mode == 0) {
fp = fopen(filename, "r");
if (fp != NULL) {
- fmout(screenwidth, fp, NULL, 0, screenheight, 0, 0);
+ fmout(screenwidth, fp, NULL, NULL, 0, screenheight, 0, 0);
beg = ftell(fp);
fclose(fp);
} else {
}
fp = fopen(filename, "r");
if (fp != NULL) {
- fmout(screenwidth, fp, NULL,
+ fmout(screenwidth, fp, NULL, NULL,
((userflags & US_PAGINATOR) ? 1 : 0),
screenheight, 0, 0);
beg = ftell(fp);