]> 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 a8cf2d1eb764a35d8eb5b61842ad4c266da110f6..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;
@@ -87,6 +88,8 @@ 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)
 {
@@ -361,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);
@@ -586,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
         */
@@ -593,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 */
@@ -722,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 */
@@ -756,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,
@@ -1542,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);
@@ -1571,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':
@@ -1589,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"))