#endif
#include <stdarg.h>
+#include <libcitadel.h>
#include "citadel.h"
#include "citadel_ipc.h"
#include "citadel_decls.h"
#include "messages.h"
#include "commands.h"
#include "rooms.h"
-#include "tools.h"
-#include "html.h"
#ifndef HAVE_SNPRINTF
#include "snprintf.h"
#endif
int num_msgs;
char rc_alt_semantics;
extern char room_name[];
+extern char tempdir[];
extern unsigned room_flags;
+extern unsigned room_flags2;
extern long highest_msg_read;
extern char temp[];
extern char temp2[];
}
if (a == 8) {
- if (strlen(wordbuf) > 0) {
+ if (!IsEmptyStr(wordbuf)) {
wordbuf[strlen(wordbuf) - 1] = 0;
scr_putc(8);
scr_putc(32);
scr_putc(8);
scr_putc(32);
scr_putc(8);
- } while (strlen(wordbuf) && wordbuf[strlen(wordbuf) - 1] != ' ');
+ } while (!IsEmptyStr(wordbuf) && wordbuf[strlen(wordbuf) - 1] != ' ');
} else if (a == 13) {
scr_printf("\n");
- if (strlen(wordbuf) == 0)
+ if (IsEmptyStr(wordbuf))
finished = 1;
else {
for (b = 0; b < strlen(wordbuf); ++b)
strcpy(reply_to, NO_REPLY_TO);
strcpy(reply_subject, "");
- r = CtdlIPCGetSingleMessage(ipc, num, (pagin == READ_HEADER ? 1 : 0),
- (can_do_msg4 ? 4 : 0),
- &message, buf);
+ 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);
+ lines_printed = checkpagin(lines_printed, pagin, screenheight);
stty_ctdl(0);
+ free(message->text);
+ free_parts(message->attachments);
+ free(message);
return (0);
}
message->nhdr ? "yes" : "no",
message->author, message->type,
message->msgid);
- if (strlen(message->subject)) {
+ if (!IsEmptyStr(message->subject)) {
pprintf("subj=%s\n", message->subject);
}
- if (strlen(message->email)) {
+ if (!IsEmptyStr(message->email)) {
pprintf("rfca=%s\n", message->email);
}
pprintf("hnod=%s\nroom=%s\nnode=%s\ntime=%s",
message->hnod, message->room,
message->node,
asctime(localtime(&message->time)));
- if (strlen(message->recipient)) {
+ if (!IsEmptyStr(message->recipient)) {
pprintf("rcpt=%s\n", message->recipient);
}
if (message->attachments) {
}
pprintf("\n");
stty_ctdl(0);
+ free(message->text);
+ free_parts(message->attachments);
+ free(message);
return (0);
}
fmt_date(now, sizeof now, message->time, 0);
if (dest) {
fprintf(dest, "%s from %s ", now, message->author);
- if (strlen(message->email)) {
+ if (!IsEmptyStr(message->email)) {
fprintf(dest, "<%s> ", message->email);
}
} else {
scr_printf("from ");
color(BRIGHT_CYAN);
scr_printf("%s ", message->author);
- if (strlen(message->email)) {
+ if (!IsEmptyStr(message->email)) {
color(DIM_WHITE);
scr_printf("<");
color(BRIGHT_BLUE);
scr_printf("> ");
}
}
- if (strlen(message->node)) {
+ if (!IsEmptyStr(message->node)) {
if ((room_flags & QR_NETWORK)
|| ((strcasecmp(message->node, ipc->ServInfo.nodename)
&& (strcasecmp(message->node, ipc->ServInfo.fqdn))))) {
- if (strlen(message->email) == 0) {
+ if (IsEmptyStr(message->email)) {
if (dest) {
fprintf(dest, "@%s ", message->node);
} else {
}
}
if (strcasecmp(message->hnod, ipc->ServInfo.humannode)
- && (strlen(message->hnod)) && (!strlen(message->email))) {
+ && (!IsEmptyStr(message->hnod)) && (IsEmptyStr(message->email))) {
if (dest) {
fprintf(dest, "(%s) ", message->hnod);
} else {
scr_printf(") ");
}
}
- if (strcasecmp(message->room, room_name) && (strlen(message->email) == 0)) {
+ if (strcasecmp(message->room, room_name) && (IsEmptyStr(message->email))) {
if (dest) {
fprintf(dest, "in %s> ", message->room);
} else {
scr_printf("%s> ", message->room);
}
}
- if (strlen(message->recipient)) {
+ if (!IsEmptyStr(message->recipient)) {
if (dest) {
fprintf(dest, "to %s ", message->recipient);
} else {
/* Set the reply-to address to an Internet e-mail address if possible
*/
- if (message->email != NULL) if (strlen(message->email) > 0) {
- if (strlen(message->author) > 0) {
+ if (message->email != NULL) if (!IsEmptyStr(message->email)) {
+ if (!IsEmptyStr(message->author)) {
snprintf(reply_to, sizeof reply_to, "%s <%s>", message->author, message->email);
}
else {
if (message->subject != NULL) {
safestrncpy(reply_subject, message->subject,
sizeof reply_subject);
- if (strlen(message->subject) > 0) {
+ if (!IsEmptyStr(message->subject)) {
if (dest) {
fprintf(dest, "Subject: %s\n",
message->subject);
if (sigcaught == 0) {
linelen = strlen(lineptr);
- if (lineptr[linelen-1] == '\r') {
+ if (linelen && (lineptr[linelen-1] == '\r')) {
lineptr[--linelen] = 0;
}
if (dest) {
scr_printf("\n");
++lines_printed;
lines_printed = checkpagin(lines_printed, pagin, screenheight);
+ fr = sigcaught;
}
}
/* Enumerate any attachments */
- if ( (pagin == 1) && (can_do_msg4) && (message->attachments) ) {
+ if ( (pagin == 1) && (message->attachments) ) {
struct parts *ptr;
for (ptr = message->attachments; ptr; ptr = ptr->next) {
if ( (!strcasecmp(ptr->disposition, "attachment"))
- || (!strcasecmp(ptr->disposition, "inline"))) {
- color(DIM_WHITE);
- pprintf("Part ");
- color(BRIGHT_MAGENTA);
- pprintf("%s", ptr->number);
- color(DIM_WHITE);
- pprintf(": ");
- color(BRIGHT_CYAN);
- pprintf("%s", ptr->filename);
- color(DIM_WHITE);
- pprintf(" (%s, %ld bytes)\n", ptr->mimetype, ptr->length);
- if (!strncmp(ptr->mimetype, "image/", 6))
- has_images++;
+ || (!strcasecmp(ptr->disposition, "inline"))
+ || (!strcasecmp(ptr->disposition, ""))
+ ) {
+ if ( (strcasecmp(ptr->number, message->mime_chosen))
+ && (!IsEmptyStr(ptr->mimetype))
+ ) {
+ color(DIM_WHITE);
+ pprintf("Part ");
+ color(BRIGHT_MAGENTA);
+ pprintf("%s", ptr->number);
+ color(DIM_WHITE);
+ pprintf(": ");
+ color(BRIGHT_CYAN);
+ pprintf("%s", ptr->filename);
+ color(DIM_WHITE);
+ pprintf(" (%s, %ld bytes)\n", ptr->mimetype, ptr->length);
+ if (!strncmp(ptr->mimetype, "image/", 6)) {
+ has_images++;
+ }
+ }
}
}
}
scr_printf("Enter text to be replaced:\n: ");
ctdl_getline(srch_str, (sizeof(srch_str)-1) );
- if (strlen(srch_str) == 0)
+ if (IsEmptyStr(srch_str))
return;
scr_printf("Enter text to replace it with:\n: ");
}
}
fseek(fp, wpos, 0);
- if (strlen(buf) > 0)
+ if (!IsEmptyStr(buf))
fwrite((char *) buf, strlen(buf), 1, fp);
wpos = ftell(fp);
fclose(fp);
* Function to begin composing a new message
*/
int client_make_message(CtdlIPC *ipc,
- char *filename, /* temporary file name */
- char *recipient, /* NULL if it's not mail */
- int is_anonymous,
- int format_type,
- int mode,
- char *subject) /* buffer to store subject line */
+ char *filename, /* temporary file name */
+ char *recipient, /* NULL if it's not mail */
+ int is_anonymous,
+ int format_type,
+ int mode,
+ char *subject, /* buffer to store subject line */
+ int subject_required)
{
FILE *fp;
int a, b, e_ex_code;
if (mode >= 2)
{
- if((mode-2) < MAX_EDITORS && strlen(editor_paths[mode-2]) > 0) {
+ if((mode-2) < MAX_EDITORS && !IsEmptyStr(editor_paths[mode-2])) {
editor_path = editor_paths[mode-2];
- } else if (strlen(editor_paths[0]) > 0) {
+ } else if (!IsEmptyStr(editor_paths[0])) {
editor_path = editor_paths[0];
} else {
err_printf("*** No editor available, "
datestr,
(is_anonymous ? "[anonymous]" : fullname)
);
- if (strlen(recipient) > 0) {
+ if (!IsEmptyStr(recipient)) {
size_t tmp = strlen(header);
snprintf(&header[tmp], sizeof header - tmp,
" to %s", recipient);
}
}
scr_printf("%s\n", header);
- if (subject != NULL) if (strlen(subject) > 0) {
+ if (subject != NULL) if (!IsEmptyStr(subject)) {
scr_printf("Subject: %s\n", subject);
}
+
+ if ( (subject_required) && (IsEmptyStr(subject)) ) {
+ newprompt("Subject: ", subject, 70);
+ }
beg = 0L;
if (b == 's') goto MEFIN;
if (b == 'p') {
scr_printf(" %s from %s", datestr, fullname);
- if (strlen(recipient) > 0) {
+ if (!IsEmptyStr(recipient)) {
scr_printf(" to %s", recipient);
}
scr_printf("\n");
- if (subject != NULL) if (strlen(subject) > 0) {
+ if (subject != NULL) if (!IsEmptyStr(subject)) {
scr_printf("Subject: %s\n", subject);
}
fp = fopen(filename, "r");
}
-#if 0
-/*
- * Transmit message text to the server.
- *
- * This loop also implements a "tick" counter that displays the progress, if
- * we're sending something that will take a long time to transmit.
- */
-void transmit_message(CtdlIPC *ipc, FILE *fp)
-{
- char buf[SIZ];
- int ch, a;
- long msglen;
- time_t lasttick;
-
- fseek(fp, 0L, SEEK_END);
- msglen = ftell(fp);
- rewind(fp);
- lasttick = time(NULL);
- strcpy(buf, "");
- while (ch = getc(fp), (ch >= 0)) {
- if (ch == 10) {
- if (!strcmp(buf, "000"))
- strcpy(buf, ">000");
- CtdlIPC_putline(ipc, buf);
- strcpy(buf, "");
- } else {
- a = strlen(buf);
- buf[a + 1] = 0;
- buf[a] = ch;
- if ((ch == 32) && (strlen(buf) > 200)) {
- buf[a] = 0;
- if (!strcmp(buf, "000"))
- strcpy(buf, ">000");
- CtdlIPC_putline(ipc, buf);
- strcpy(buf, "");
- }
- if (strlen(buf) > 250) {
- if (!strcmp(buf, "000"))
- strcpy(buf, ">000");
- CtdlIPC_putline(ipc, buf);
- strcpy(buf, "");
- }
- }
-
- if ((time(NULL) - lasttick) > 2L) {
- scr_printf(" %3ld%% completed\r",
- ((ftell(fp) * 100L) / msglen));
- scr_flush();
- lasttick = time(NULL);
- }
-
- }
- CtdlIPC_putline(ipc, buf);
- scr_printf(" \r");
- scr_flush();
-}
-#endif
-
-
/*
* Make sure there's room in msg_arr[] for at least one more.
*/
struct ctdlipcmessage message;
unsigned long *msgarr = NULL;
int r; /* IPC response code */
+ int subject_required = 0;
if (c > 0)
mode = 1;
newprompt("Display name for this message: ", message.author, 40);
}
- r = CtdlIPCPostMessage(ipc, 0, &message, buf);
+ r = CtdlIPCPostMessage(ipc, 0, &subject_required, &message, buf);
if (r / 100 != 2 && r / 10 != 57) {
scr_printf("%s\n", buf);
} else {
scr_printf("Enter recipient: ");
ctdl_getline(buf, (SIZ-100) );
- if (strlen(buf) == 0)
+ if (IsEmptyStr(buf))
return (1);
}
} else
strcpy(message.recipient, buf);
if (is_reply) {
- if (strlen(reply_subject) > 0) {
+ if (!IsEmptyStr(reply_subject)) {
if (!strncasecmp(reply_subject,
"Re: ", 3)) {
strcpy(message.subject, reply_subject);
}
/* If it's mail, we've got to check the validity of the recipient... */
- if (strlen(message.recipient) > 0) {
- r = CtdlIPCPostMessage(ipc, 0, &message, buf);
+ if (!IsEmptyStr(message.recipient)) {
+ r = CtdlIPCPostMessage(ipc, 0, &subject_required, &message, buf);
if (r / 100 != 2) {
scr_printf("%s\n", buf);
return (1);
/* Now compose the message... */
if (client_make_message(ipc, temp, message.recipient,
- message.anonymous, 0, c, message.subject) != 0) {
+ message.anonymous, 0, c, message.subject, subject_required) != 0) {
+ if (msgarr) free(msgarr);
return (2);
}
break_big_lines(message.text);
/* Transmit message to the server */
- r = CtdlIPCPostMessage(ipc, 1, &message, buf);
+ r = CtdlIPCPostMessage(ipc, 1, NULL, &message, buf);
if (r / 100 != 4) {
scr_printf("%s\n", buf);
return (1);
line = 0;
fgets(buf, 128, qfile);
while (fgets(buf, 128, qfile) != NULL) {
- scr_printf("%2d %s", ++line, buf);
+ scr_printf("%3d %s", ++line, buf);
}
- scr_printf("Begin quoting at [ 1] : ");
- ctdl_getline(buf, 3);
+ scr_printf("Begin quoting at [1] : ");
+ ctdl_getline(buf, 4);
qstart = (buf[0] == 0) ? (1) : atoi(buf);
scr_printf(" End quoting at [%d] : ", line);
- ctdl_getline(buf, 3);
+ ctdl_getline(buf, 4);
qend = (buf[0] == 0) ? (line) : atoi(buf);
rewind(qfile);
line = 0;
char filename[PATH_MAX];
char save_to[PATH_MAX];
void *attachment = NULL; /* Downloaded attachment */
- FILE *dest = NULL; /* Alternate destination other than screen */
+ FILE *dest = NULL; /* Alternate destination other than screen */
int r; /* IPC response code */
+ static int att_seq = 0; /* Attachment download sequence number */
if (c < 0)
b = (num_msgs - 1);
r = CtdlIPCSetMessageSeen(ipc, msg_arr[a], 1, buf);
}
- if (e == 3)
+ if (e == SIGQUIT)
return;
- if (((userflags & US_NOPROMPT) || (e == 2))
- && (((room_flags & QR_MAILBOX) == 0)
+ if (((userflags & US_NOPROMPT) || (e == SIGINT))
+ && (((room_flags & QR_MAILBOX) == 0)
|| (rc_force_mail_prompts == 0))) {
e = 'n';
} else {
keyopt("<B>ack <A>gain <Q>uote <R>eply <N>ext <S>top ");
if (rc_url_cmd[0] && num_urls)
keyopt("<U>RLview ");
- if (has_images > 0 && strlen(imagecmd) > 0)
+ if (has_images > 0 && !IsEmptyStr(imagecmd))
keyopt("<I>mages ");
keyopt("<?>help -> ");
/* space key same as <N> */ if (e == 32)
e = 'n';
/* del/move for aides only */
- if ((!is_room_aide)
- && ((room_flags & QR_MAILBOX) ==
- 0)) {
+ if ( (!is_room_aide)
+ && ((room_flags & QR_MAILBOX) == 0)
+ && ((room_flags2 & QR2_COLLABDEL) == 0)
+ ) {
if ((e == 'd') || (e == 'm'))
e = 0;
}
/* print only if available */
- if ((e == 'p') && (strlen(printcmd) == 0))
+ if ((e == 'p') && (IsEmptyStr(printcmd)))
e = 0;
/* can't file if not allowed */
if ((e == 'f')
e = 0;
/* link only if browser avail*/
if ((e == 'u')
- && (strlen(rc_url_cmd) == 0))
+ && (IsEmptyStr(rc_url_cmd)))
e = 0;
if ((e == 'i')
- && (!strlen(imagecmd) || !has_images))
+ && (IsEmptyStr(imagecmd) || !has_images))
e = 0;
} while ((e != 'a') && (e != 'n') && (e != 's')
&& (e != 'd') && (e != 'm') && (e != 'p')
&& (e != 'q') && (e != 'b') && (e != 'h')
&& (e != 'r') && (e != 'f') && (e != '?')
&& (e != 'u') && (e != 'c') && (e != 'y')
- && (e != 'i'));
+ && (e != 'i') && (e != 'o') );
switch (e) {
case 's':
scr_printf("Stop");
case 'r':
scr_printf("Reply");
break;
+ case 'o':
+ scr_printf("Open attachments");
+ break;
case 'f':
scr_printf("File");
break;
" N Next (continue with next message)\n"
" Y My Next (continue with next message you authored)\n"
" B Back (go back to previous message)\n");
- if ((is_room_aide)
- || (room_flags & QR_MAILBOX)) {
+ if ( (is_room_aide)
+ || (room_flags & QR_MAILBOX)
+ || (room_flags2 & QR2_COLLABDEL)
+ ) {
scr_printf(" D Delete this message\n"
" M Move message to another room\n");
}
scr_printf(" C Copy message to another room\n");
- if (strlen(printcmd) > 0)
+ if (!IsEmptyStr(printcmd))
scr_printf(" P Print this message\n");
scr_printf(
" Q Quote portions of this message for your next post\n"
" H Headers (display message headers only)\n");
if (is_mail)
scr_printf(" R Reply to this message\n");
- if (rc_allow_attachments)
- scr_printf
- (" F (save attachments to a file)\n");
- if (strlen(rc_url_cmd) > 0)
+ if (rc_allow_attachments) {
+ scr_printf(" O (Open attachments)\n");
+ scr_printf(" F (save attachments to a File)\n");
+ }
+ if (!IsEmptyStr(rc_url_cmd))
scr_printf(" U (list URL's for display)\n");
- if (strlen(imagecmd) > 0 && has_images > 0)
+ if (!IsEmptyStr(imagecmd) && has_images > 0)
scr_printf(" I Image viewer\n");
scr_printf("\n");
goto RMSGREAD;
case 'c':
newprompt("Enter target room: ",
targ, ROOMNAMELEN - 1);
- if (strlen(targ) > 0) {
+ if (!IsEmptyStr(targ)) {
r = CtdlIPCMoveMessage(ipc, (e == 'c' ? 1 : 0),
msg_arr[a], targ, cmd);
scr_printf("%s\n", cmd);
if (r / 100 != 2) /* r will be init'ed, FIXME */
goto RMSGREAD; /* the logic here sucks */
break;
+ case 'o':
case 'f':
- newprompt("Which section? ", filename,
- ((sizeof filename) - 1));
+ newprompt("Which section? ", filename, ((sizeof filename) - 1));
r = CtdlIPCAttachmentDownload(ipc, msg_arr[a],
filename, &attachment, progress, cmd);
if (r / 100 != 2) {
* Part 1 won't have a filename; use the
* subject of the message instead. IO
*/
- if (!strlen(filename))
+ if (IsEmptyStr(filename)) {
strcpy(filename, reply_subject);
- destination_directory(save_to, filename);
- save_buffer(attachment,
- extract_unsigned_long(cmd, 0),
- save_to);
+ }
+ if (e == 'o') { /* open attachment */
+ mkdir(tempdir, 0700);
+ snprintf(save_to, sizeof save_to, "%s/%04x.%s",
+ tempdir,
+ ++att_seq,
+ filename);
+ save_buffer(attachment, extract_unsigned_long(cmd, 0), save_to);
+ snprintf(cmd, sizeof cmd, rc_open_cmd, save_to);
+ system(cmd);
+ }
+ else { /* save attachment to disk */
+ destination_directory(save_to, filename);
+ save_buffer(attachment, extract_unsigned_long(cmd, 0), save_to);
+ }
}
if (attachment) {
free(attachment);
return;
}
- while (transcript && strlen(transcript)) {
+ while (transcript && !IsEmptyStr(transcript)) {
lines_printed = 1;
extract_token(buf, transcript, 0, '\n', sizeof buf);
remove_token(transcript, 0, '\n');