]> code.citadel.org Git - citadel.git/blobdiff - citadel/messages.c
* Replaced the DEFAULT_ENTRY definition in sysconfig.h with a new option
[citadel.git] / citadel / messages.c
index c02ceb4ec3dc24686cbc56e565fd9d561b87acb8..24b051464c9802cee62ff94a425544d4840d7df8 100644 (file)
@@ -65,6 +65,7 @@ unsigned long *msg_arr = NULL;
 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;
@@ -81,13 +82,14 @@ extern char fullname[];
 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)
 {
@@ -362,6 +364,13 @@ int read_message(CtdlIPC *ipc,
        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);
@@ -587,6 +596,26 @@ int read_message(CtdlIPC *ipc,
                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
         */
@@ -594,37 +623,49 @@ int read_message(CtdlIPC *ipc,
                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 */
@@ -723,7 +764,7 @@ void replace_string(char *filename, long int startpos)
 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 */
@@ -733,14 +774,21 @@ int client_make_message(CtdlIPC *ipc,
        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;
@@ -750,7 +798,10 @@ int client_make_message(CtdlIPC *ipc,
        }
        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,
@@ -825,6 +876,7 @@ ME1:        switch (mode) {
                break;
 
        case 2:
+       default:        /* allow 2+ modes */
                e_ex_code = 1;  /* start with a failed exit code */
                editor_pid = fork();
                cksum = file_checksum(filename);
@@ -850,7 +902,7 @@ ME1:        switch (mode) {
                break;
        }
 
-MECR:  if (mode == 2) {
+MECR:  if (mode >= 2) {
                if (file_checksum(filename) == cksum) {
                        err_printf("*** Aborted message.\n");
                        e_ex_code = 1;
@@ -1002,6 +1054,7 @@ int entmsg(CtdlIPC *ipc,
        FILE *fp;
        char subject[SIZ];
        struct ctdlipcmessage message;
+       unsigned long *msgarr = NULL;
        int r;                  /* IPC response code */
 
        if (c > 0)
@@ -1091,12 +1144,11 @@ int entmsg(CtdlIPC *ipc,
         * 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++)
                        ;
        }
 
@@ -1127,27 +1179,30 @@ int entmsg(CtdlIPC *ipc,
                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.
@@ -1279,11 +1334,11 @@ void readmsgs(CtdlIPC *ipc,
                        ;
        }
 
-       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;
        }
@@ -1532,13 +1587,17 @@ RMSGREAD:       scr_flush();
                                  ((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);
@@ -1561,7 +1620,7 @@ RMSGREAD: scr_flush();
                        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':
@@ -1579,7 +1638,8 @@ RMSGREAD: scr_flush();
                 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"))