/*
- * $Id$
- *
* Text client functions for reading and writing of messages
*
* Copyright (c) 1987-2010 by the citadel.org team
putc(10, fp);
fflush(fp);
rv = ftruncate(fileno(fp), ftell(fp));
+ if (rv < 0)
+ scr_printf("failed to set message buffer: %s\n", strerror(errno));
+
/* and deallocate the memory we used */
while (textlist != NULL) {
ptr = textlist->next;
r = CtdlIPCGetSingleMessage(ipc, num, (pagin == READ_HEADER ? 1 : 0), 4, &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);
+ scr_printf("*** msg #%ld: %d %s\n", num, r, buf);
stty_ctdl(0);
free(message->text);
free_parts(message->attachments);
fprintf(dest, "\n ");
} else {
scr_printf("\n");
- ++lines_printed;
- lines_printed = checkpagin(lines_printed, pagin, screenheight);
if (pagin != 2)
scr_printf(" ");
}
/* View headers only */
if (pagin == 2) {
- pprintf("nhdr=%s\nfrom=%s\ntype=%d\nmsgn=%s\n",
+ scr_printf("nhdr=%s\nfrom=%s\ntype=%d\nmsgn=%s\n",
message->nhdr ? "yes" : "no",
message->author, message->type,
message->msgid);
if (!IsEmptyStr(message->subject)) {
- pprintf("subj=%s\n", message->subject);
+ scr_printf("subj=%s\n", message->subject);
}
if (!IsEmptyStr(message->email)) {
- pprintf("rfca=%s\n", message->email);
+ scr_printf("rfca=%s\n", message->email);
}
- pprintf("hnod=%s\nroom=%s\nnode=%s\ntime=%s",
+ scr_printf("hnod=%s\nroom=%s\nnode=%s\ntime=%s",
message->hnod, message->room,
message->node,
asctime(localtime(&message->time)));
if (!IsEmptyStr(message->recipient)) {
- pprintf("rcpt=%s\n", message->recipient);
+ scr_printf("rcpt=%s\n", message->recipient);
}
if (message->attachments) {
struct parts *ptr;
for (ptr = message->attachments; ptr; ptr = ptr->next) {
- pprintf("part=%s|%s|%s|%s|%s|%ld\n",
+ scr_printf("part=%s|%s|%s|%s|%s|%ld\n",
ptr->name, ptr->filename, ptr->number,
ptr->disposition, ptr->mimetype,
ptr->length);
}
}
- pprintf("\n");
+ scr_printf("\n");
stty_ctdl(0);
free(message->text);
free_parts(message->attachments);
message->author, message->node);
}
- if (!dest) {
- ++lines_printed;
- lines_printed = checkpagin(lines_printed, pagin, screenheight);
- }
-
-
if (message->msgid != NULL) {
safestrncpy(reply_inreplyto, message->msgid, sizeof reply_inreplyto);
}
scr_printf("Subject: ");
color(BRIGHT_CYAN);
scr_printf("%s\n", message->subject);
- ++lines_printed;
- lines_printed = checkpagin(lines_printed,
- pagin, screenheight);
}
}
}
* Here we go
*/
if (format_type == 0) {
- fr = fmout(screenwidth, NULL, message->text, dest,
- ((pagin == 1) ? 1 : 0), screenheight, (-1), 1);
+ fr = fmout(screenwidth, NULL, message->text, dest, 1);
} else {
/* renderer for text/plain */
fprintf(dest, "%s\n", lineptr);
} else {
scr_printf("%s\n", lineptr);
- lines_printed = lines_printed + 1 +
- (linelen / screenwidth);
- lines_printed =
- checkpagin(lines_printed, pagin,
- screenheight);
}
}
if (lineptr[0] == 0) final_line_is_blank = 1;
}
else {
scr_printf("\n");
- ++lines_printed;
- lines_printed = checkpagin(lines_printed, pagin, screenheight);
fr = sigcaught;
}
}
&& (!IsEmptyStr(ptr->mimetype))
) {
color(DIM_WHITE);
- pprintf("Part ");
+ scr_printf("Part ");
color(BRIGHT_MAGENTA);
- pprintf("%s", ptr->number);
+ scr_printf("%s", ptr->number);
color(DIM_WHITE);
- pprintf(": ");
+ scr_printf(": ");
color(BRIGHT_CYAN);
- pprintf("%s", ptr->filename);
+ scr_printf("%s", ptr->filename);
color(DIM_WHITE);
- pprintf(" (%s, %ld bytes)\n", ptr->mimetype, ptr->length);
+ scr_printf(" (%s, %ld bytes)\n", ptr->mimetype, ptr->length);
if (!strncmp(ptr->mimetype, "image/", 6)) {
has_images++;
}
rpos = ftell(fp);
fseek(fp, wpos, 0);
rv = fwrite((char *) buf, 128, 1, fp);
+ if (rv < 0) {
+ scr_printf("failed to replace string: %s\n", strerror(errno));
+ break; /*whoopsi! */
+ }
strcpy(buf, &buf[128]);
wpos = ftell(fp);
fseek(fp, rpos, 0);
{
editor_path = editor_paths[0];
} else {
- err_printf("*** No editor available; using built-in editor.\n");
+ scr_printf("*** No editor available; using built-in editor.\n");
mode = 0;
}
}
newprompt("Subject: ", subject, 70);
}
- beg = 0L;
-
if (mode == 1) {
scr_printf("(Press ctrl-d when finished)\n");
}
if (mode == 0) {
fp = fopen(filename, "r");
if (fp != NULL) {
- fmout(screenwidth, fp, NULL, NULL, 0,
- screenheight, 0, 0);
+ fmout(screenwidth, fp, NULL, NULL, 0);
beg = ftell(fp);
+ if (beg < 0)
+ scr_printf("failed to get stream position %s\n",
+ strerror(errno));
fclose(fp);
} else {
fp = fopen(filename, "w");
if (fp == NULL) {
- err_printf("*** Error opening temp file!\n %s: %s\n",
+ scr_printf("*** Error opening temp file!\n %s: %s\n",
filename, strerror(errno)
);
return(1);
case 0:
fp = fopen(filename, "r+");
if (fp == NULL) {
- err_printf("*** Error opening temp file!\n %s: %s\n",
+ scr_printf("*** Error opening temp file!\n %s: %s\n",
filename, strerror(errno)
);
return(1);
case 1:
fp = fopen(filename, "a");
if (fp == NULL) {
- err_printf("*** Error opening temp file!\n"
+ scr_printf("*** Error opening temp file!\n"
" %s: %s\n",
filename, strerror(errno));
return(1);
case 2:
default: /* allow 2+ modes */
e_ex_code = 1; /* start with a failed exit code */
- screen_reset();
stty_ctdl(SB_RESTORE);
editor_pid = fork();
cksum = file_checksum(filename);
} while ((b != editor_pid) && (b >= 0));
editor_pid = (-1);
stty_ctdl(0);
- screen_set();
break;
}
MECR: if (mode >= 2) {
if (file_checksum(filename) == cksum) {
- err_printf("*** Aborted message.\n");
+ scr_printf("*** Aborted message.\n");
e_ex_code = 1;
}
if (e_ex_code == 0) {
}
fp = fopen(filename, "r");
if (fp != NULL) {
- fmout(screenwidth, fp, NULL, NULL,
- ((userflags & US_PAGINATOR) ? 1 : 0),
- screenheight, 0, 0);
+ fmout(screenwidth, fp, NULL, NULL, 0);
+ /* TODO: why ftell if we ignore the result? */
beg = ftell(fp);
+ if (beg < 0)
+ scr_printf("failed to get stream position %s\n",
+ strerror(errno));
fclose(fp);
}
goto MECR;
newprompt("Display name for this message: ", message.author, 40);
}
+ if (is_reply) {
+
+ if (!IsEmptyStr(reply_subject)) {
+ if (!strncasecmp(reply_subject,
+ "Re: ", 3)) {
+ strcpy(message.subject, reply_subject);
+ }
+ else {
+ snprintf(message.subject,
+ sizeof message.subject,
+ "Re: %s",
+ reply_subject);
+ }
+ }
+
+ /* Trim down excessively long lists of thread references. We eliminate the
+ * second one in the list so that the thread root remains intact.
+ */
+ int rrtok = num_tokens(reply_references, '|');
+ int rrlen = strlen(reply_references);
+ if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
+ remove_token(reply_references, 1, '|');
+ }
+
+ snprintf(message.references, sizeof message.references, "%s%s%s",
+ reply_references,
+ (IsEmptyStr(reply_references) ? "" : "|"),
+ reply_inreplyto
+ );
+ }
+
r = CtdlIPCPostMessage(ipc, 0, &subject_required, &message, buf);
if (r / 100 != 2 && r / 10 != 57) {
}
strcpy(message.recipient, buf);
- if (is_reply) {
-
- if (!IsEmptyStr(reply_subject)) {
- if (!strncasecmp(reply_subject,
- "Re: ", 3)) {
- strcpy(message.subject, reply_subject);
- }
- else {
- snprintf(message.subject,
- sizeof message.subject,
- "Re: %s",
- reply_subject);
- }
- }
-
- /* Trim down excessively long lists of thread references. We eliminate the
- * second one in the list so that the thread root remains intact.
- */
- int rrtok = num_tokens(reply_references, '|');
- int rrlen = strlen(reply_references);
- if ( ((rrtok >= 3) && (rrlen > 900)) || (rrtok > 10) ) {
- remove_token(reply_references, 1, '|');
- }
-
- snprintf(message.references, sizeof message.references, "%s%s%s",
- reply_references,
- (IsEmptyStr(reply_references) ? "" : "|"),
- reply_inreplyto
- );
- }
-
if (room_flags & QR_ANONOPT) {
scr_printf("Anonymous (Y/N)? ");
if (yesno() == 1)
fp = fopen(temp, "r");
if (!fp || !(message.text = load_message_from_file(fp))) {
- err_printf("*** Internal error while trying to save message!\n"
+ scr_printf("*** Internal error while trying to save message!\n"
"%s: %s\n",
temp, strerror(errno));
unlink(temp);
snprintf(cmd, sizeof cmd, rc_url_cmd, urls[i - 1]);
rv = system(cmd);
+ if (rv != 0)
+ scr_printf("failed to '%s' by %d\n", cmd, rv);
scr_printf("\n");
}
enum MessageDirection rdir, /* 1=Forward (-1)=Reverse */
int q /* Number of msgs to read (if c==3) */
) {
- int a, b, e, f, g, start;
+ int a, e, f, g, start;
int savedpos;
int hold_sw = 0;
char arcflag = 0;
static int att_seq = 0; /* Attachment download sequence number */
int rv = 0; /* silence the stupid warn_unused_result warnings */
- if (c < 0)
- b = (num_msgs - 1);
- else
- b = 0;
-
CtdlMakeTempFileName(prtfile, sizeof prtfile);
if (msg_arr) {
return;
}
- lines_printed = 0;
-
/* this loop cycles through each message... */
start = ((rdir == 1) ? 0 : (num_msgs - 1));
for (a = start; ((a < num_msgs) && (a >= 0)); a = a + rdir) {
if ((quotflag) || (arcflag)) {
screenwidth = hold_sw;
}
-RMSGREAD: scr_flush();
+RMSGREAD:
highest_msg_read = msg_arr[a];
if (quotflag) {
fclose(dest);
if (freopen(prtfile, "r", stdin) == NULL) {
/* we probably should handle the error condition here */
}
- screen_reset();
stty_ctdl(SB_RESTORE);
ka_system(printcmd);
stty_ctdl(SB_NO_INTR);
- screen_set();
unlink(prtfile);
exit(0);
}
keyopt("<?>help -> ");
do {
- lines_printed = 2;
e = (inkey() & 127);
e = tolower(e);
/* return key same as <N> */ if (e == 10)
scr_printf("\r%79s\r", "");
else
scr_printf("\n");
- scr_flush();
}
DONE_QUOTING: switch (e) {
case '?':
save_buffer(attachment, extract_unsigned_long(cmd, 0), save_to);
snprintf(cmd, sizeof cmd, rc_open_cmd, save_to);
rv = system(cmd);
+ if (rv != 0)
+ scr_printf("failed to save %s Reason %d\n", cmd, rv);
}
else { /* save attachment to disk */
destination_directory(save_to, filename);
}
while (transcript && !IsEmptyStr(transcript)) {
- lines_printed = 1;
extract_token(buf, transcript, 0, '\n', sizeof buf);
remove_token(transcript, 0, '\n');
- pprintf("%s\n", buf);
+ scr_printf("%s\n", buf);
}
if (transcript) free(transcript);
return;