int msg_arr_size = 0;
int num_msgs;
char rc_alt_semantics;
+char rc_reply_extedit;
extern char room_name[];
extern unsigned room_flags;
extern long highest_msg_read;
extern char axlevel;
extern unsigned userflags;
extern char sigcaught;
-extern char editor_path[];
extern char printcmd[];
extern int rc_allow_attachments;
extern int rc_display_message_numbers;
extern int rc_force_mail_prompts;
extern int editor_pid;
extern CtdlIPC *ipc_for_signal_handlers; /* KLUDGE cover your eyes */
+int num_urls = 0;
+char urls[MAXURLS][SIZ];
void ka_sigcatch(int signum)
{
struct ctdlipcmessage *message = NULL;
int r; /* IPC response code */
char *converted_text = NULL;
+ char *lineptr;
+ char *nextline;
+ char *searchptr;
+ int i;
+ char ch;
+ int linelen;
+ int final_line_is_blank = 0;
sigcaught = 0;
sttybbs(1);
format_type = 1;
}
+ /* Extract URL's */
+ num_urls = 0; /* Start with a clean slate */
+ searchptr = message->text;
+ while ( (searchptr != NULL) && (num_urls < MAXURLS) ) {
+ searchptr = strstr(searchptr, "http://");
+ if (searchptr != NULL) {
+ safestrncpy(urls[num_urls], searchptr, sizeof(urls[num_urls]));
+ for (i = 0; i < strlen(urls[num_urls]); i++) {
+ ch = urls[num_urls][i];
+ if (ch == '>' || ch == '\"' || ch == ')' ||
+ ch == ' ' || ch == '\n') {
+ urls[num_urls][i] = 0;
+ break;
+ }
+ }
+ num_urls++;
+ ++searchptr;
+ }
+ }
+
/*
* Here we go
*/
fr = fmout(screenwidth, NULL, message->text, dest,
((pagin == 1) ? 1 : 0), screenheight, (-1), 1);
} else {
- /* FIXME: renderer for text/plain */
- char *msgtext;
- char *lineptr;
+ /* renderer for text/plain */
- msgtext = message->text;
+ lineptr = message->text;
- while (lineptr = strtok(msgtext, "\n"), lineptr != NULL) {
- msgtext = NULL;
+ do {
+ nextline = strchr(lineptr, '\n');
+ if (nextline != NULL) {
+ *nextline = 0;
+ ++nextline;
+ if (*nextline == 0) nextline = NULL;
+ }
if (sigcaught == 0) {
+ linelen = strlen(lineptr);
+ if (lineptr[linelen-1] == '\r') {
+ lineptr[--linelen] = 0;
+ }
if (dest) {
fprintf(dest, "%s\n", lineptr);
} else {
scr_printf("%s\n", lineptr);
lines_printed = lines_printed + 1 +
- (strlen(lineptr) / screenwidth);
+ (linelen / screenwidth);
lines_printed =
checkpagin(lines_printed, pagin,
screenheight);
}
}
- }
+ if (lineptr[0] == 0) final_line_is_blank = 1;
+ else final_line_is_blank = 0;
+ lineptr = nextline;
+ } while (nextline);
fr = sigcaught;
}
- if (dest) {
- fprintf(dest, "\n");
- } else {
- scr_printf("\n");
- /* scr_flush(); */
- ++lines_printed;
- lines_printed = checkpagin(lines_printed, pagin, screenheight);
+ if (!final_line_is_blank) {
+ if (dest) {
+ fprintf(dest, "\n");
+ }
+ else {
+ scr_printf("\n");
+ ++lines_printed;
+ lines_printed = checkpagin(lines_printed, pagin, screenheight);
+ }
}
/* Enumerate any attachments */
int client_make_message(CtdlIPC *ipc,
char *filename, /* temporary file name */
char *recipient, /* NULL if it's not mail */
- int anon_type, /* see MES_ types in header file */
+ int is_anonymous,
int format_type,
int mode,
char *subject) /* buffer to store subject line */
long beg;
char datestr[SIZ];
char header[SIZ];
+ char *editor_path = NULL;
int cksum = 0;
- if (mode == 2)
- if (strlen(editor_path) == 0) {
+ if (mode >= 2)
+ {
+ if((mode-2) < MAX_EDITORS && strlen(editor_paths[mode-2]) > 0) {
+ editor_path = editor_paths[mode-2];
+ } else if (strlen(editor_paths[0]) > 0) {
+ editor_path = editor_paths[0];
+ } else {
err_printf
("*** No editor available, using built-in editor\n");
mode = 0;
}
+ }
fmt_date(datestr, sizeof datestr, time(NULL), 0);
header[0] = 0;
}
else {
snprintf(header, sizeof header,
- " %s from %s", datestr, fullname);
+ " %s from %s",
+ datestr,
+ (is_anonymous ? "[anonymous]" : fullname)
+ );
if (strlen(recipient) > 0) {
size_t tmp = strlen(header);
snprintf(&header[tmp], sizeof header - tmp,
break;
case 2:
+ default: /* allow 2+ modes */
e_ex_code = 1; /* start with a failed exit code */
editor_pid = fork();
cksum = file_checksum(filename);
break;
}
-MECR: if (mode == 2) {
+MECR: if (mode >= 2) {
if (file_checksum(filename) == cksum) {
err_printf("*** Aborted message.\n");
e_ex_code = 1;
FILE *fp;
char subject[SIZ];
struct ctdlipcmessage message;
+ unsigned long *msgarr = NULL;
int r; /* IPC response code */
if (c > 0)
* tell upon saving whether someone else has posted too.
*/
num_msgs = 0;
- free(msg_arr); msg_arr = NULL;
- r = CtdlIPCGetMessages(ipc, LastMessages, 1, NULL, &msg_arr, buf);
+ r = CtdlIPCGetMessages(ipc, LastMessages, 1, NULL, &msgarr, buf);
if (r / 100 != 1) {
scr_printf("%s\n", buf);
} else {
- for (num_msgs = 0; msg_arr[num_msgs]; num_msgs++)
+ for (num_msgs = 0; msgarr[num_msgs]; num_msgs++)
;
}
return (1);
}
- if (num_msgs >= 1) highmsg = msg_arr[num_msgs - 1];
+ if (num_msgs >= 1) highmsg = msgarr[num_msgs - 1];
- free(msg_arr); msg_arr = NULL;
- r = CtdlIPCGetMessages(ipc, NewMessages, 0, NULL, &msg_arr, buf);
+ if (msgarr) free(msgarr);
+ msgarr = NULL;
+ r = CtdlIPCGetMessages(ipc, NewMessages, 0, NULL, &msgarr, buf);
if (r / 100 != 1) {
scr_printf("%s\n", buf);
} else {
- for (num_msgs = 0; msg_arr[num_msgs]; num_msgs++)
+ for (num_msgs = 0; msgarr[num_msgs]; num_msgs++)
;
}
/* get new highest message number in room to set lrp for goto... */
- maxmsgnum = msg_arr[num_msgs - 1];
+ maxmsgnum = msgarr[num_msgs - 1];
/* now see if anyone else has posted in here */
b = (-1);
for (a = 0; a < num_msgs; ++a) {
- if (msg_arr[a] > highmsg) {
+ if (msgarr[a] > highmsg) {
++b;
}
}
+ if (msgarr) free(msgarr);
+ msgarr = NULL;
/* In the Mail> room, this algorithm always counts one message
* higher than in public rooms, so we decrement it by one.
;
}
- if (num_msgs == 0) {
- if (c == 3) return;
+ if (num_msgs == 0) { /* TODO look at this later */
+ if (c == LastMessages) return;
scr_printf("*** There are no ");
- if (c == 1) scr_printf("new ");
- if (c == 2) scr_printf("old ");
+ if (c == NewMessages) scr_printf("new ");
+ if (c == OldMessages) scr_printf("old ");
scr_printf("messages in this room.\n");
return;
}
((sizeof filename) - 1));
r = CtdlIPCAttachmentDownload(ipc, msg_arr[a],
filename, &attachment, progress, cmd);
- extract(filename, cmd, 2);
- destination_directory(save_to, filename);
- r = CtdlIPCAttachmentDownload(ipc, msg_arr[a],
- filename, &attachment, progress, cmd);
if (r / 100 != 2) {
scr_printf("%s\n", cmd);
} else {
+ extract(filename, cmd, 2);
+ /*
+ * Part 1 won't have a filename; use the
+ * subject of the message instead. IO
+ */
+ if (!strlen(filename))
+ strcpy(filename, reply_subject);
+ destination_directory(save_to, filename);
save_buffer(attachment,
extract_unsigned_long(cmd, 0),
save_to);
goto RMSGREAD;
case 'r':
savedpos = num_msgs;
- entmsg(ipc, 1, (DEFAULT_ENTRY == 46 ? 2 : 0));
+ entmsg(ipc, 1, (rc_reply_extedit ? 2 : 0));
num_msgs = savedpos;
goto RMSGREAD;
case 'u':
char buf[SIZ];
int founda = 0;
- snprintf(buf, sizeof buf, "MSG0 %ld|1", msg_arr[finda]); /* read the header so we can get 'from=' */
+ /* read the header so we can get 'from=' */
+ snprintf(buf, sizeof buf, "MSG0 %ld|1", msg_arr[finda]);
CtdlIPC_putline(ipc, buf);
CtdlIPC_getline(ipc, buf);
while (CtdlIPC_getline(ipc, buf), strcmp(buf, "000"))