From: Carl Worth Date: Wed, 11 Nov 2009 02:46:26 +0000 (-0800) Subject: notmuch reply: Process headers a bit more accurately. X-Git-Tag: 0.1~540 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=dfc0780cbab2106a9d8fca69cefae02d4102f397;p=notmuch.git notmuch reply: Process headers a bit more accurately. We know take the original From: and all recipients and put them on the To: line. We also add a "Re: " to the subject, and we add In-Reply-To: and References: headers. --- diff --git a/notmuch-reply.c b/notmuch-reply.c index 0c3ea13f..40ef4c64 100644 --- a/notmuch-reply.c +++ b/notmuch-reply.c @@ -81,13 +81,8 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) notmuch_messages_t *messages; notmuch_message_t *message; int ret = 0; - - const char *headers[] = { - "Subject", "From", "To", "Cc", "Bcc", "Date", - "In-Reply-To", "References" - }; - const char *name, *value; - unsigned int i; + int has_recipient; + const char *subject, *to, *references; notmuch = notmuch_database_open (NULL); if (notmuch == NULL) { @@ -115,12 +110,58 @@ notmuch_reply_command (void *ctx, int argc, char *argv[]) { message = notmuch_messages_get (messages); - for (i = 0; i < ARRAY_SIZE (headers); i++) { - name = headers[i]; - value = notmuch_message_get_header (message, name); - if (value) - printf ("%s: %s\n", name, value); + subject = notmuch_message_get_header (message, "subject"); + + /* XXX: Should have the user's email address(es) configured + * somewhere, and should fish it out of any recipient headers + * to reply by default from the same address that the original + * email was sent to */ + printf ("From: \n"); + + /* XXX: Should fold long recipient lists. */ + printf ("To:"); + has_recipient = 0; + + to = notmuch_message_get_header (message, "from"); + if (to) { + printf (" %s", to); + has_recipient = 1; + } + to = notmuch_message_get_header (message, "to"); + if (to) { + printf ("%s%s", + has_recipient ? ", " : " ", to); + has_recipient = 1; + } + to = notmuch_message_get_header (message, "cc"); + if (to) { + printf ("%s%s", + has_recipient ? ", " : " ", to); + has_recipient = 1; } + to = notmuch_message_get_header (message, "bcc"); + if (to) { + printf ("%s%s", + has_recipient ? ", " : " ", to); + has_recipient = 1; + } + + printf ("\n"); + + if (strncasecmp (subject, "Re:", 3)) + subject = talloc_asprintf (ctx, "Re: %s", subject); + printf ("Subject: %s\n", subject); + + printf ("In-Reply-To: <%s>\n", + notmuch_message_get_message_id (message)); + + /* XXX: Should fold long references lists. */ + references = notmuch_message_get_header (message, "references"); + printf ("References: %s <%s>\n", + references ? references : "", + notmuch_message_get_message_id (message)); + + printf ("--text follows this line--\n"); show_message_body (notmuch_message_get_filename (message), reply_part);