Re: [notmuch] [PATCH] notmuch-reply: Use a shorter 'On, X Y wrote:' line

Subject: Re: [notmuch] [PATCH] notmuch-reply: Use a shorter 'On, X Y wrote:' line

Date: Thu, 04 Mar 2010 15:41:46 +0100

To: Sebastian Spaeth, notmuch@notmuchmail.org

Cc:

From: Michal Sojka


Hi again,

On Tue, 02 Mar 2010, Sebastian Spaeth wrote:
> Previously, we would output:
> 'On Thu, 25 Feb 2010 14:32:54 +0100, Sebastian Spaeth <Sebastian@SSpaeth.de> wrote:' now it is:
> 'On 2010-02-25, Sebastian Spaeth wrote:'
> 
> In case we don't find a '<' (as indicator for 'Realname <email>'), we still use the whole from address.
> 
> Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>
> ---
> This probably shows my lack of C skills quite nicely but it does the job for me.
> 
>  notmuch-reply.c |   21 ++++++++++++++++++---
>  1 files changed, 18 insertions(+), 3 deletions(-)
> 
> diff --git a/notmuch-reply.c b/notmuch-reply.c
> index 98f6442..929572f 100644
> --- a/notmuch-reply.c
> +++ b/notmuch-reply.c
> @@ -288,9 +288,12 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
>      GMimeMessage *reply;
>      notmuch_messages_t *messages;
>      notmuch_message_t *message;
> -    const char *subject, *from_addr = NULL;
> +    const char *subject, *from_addr = NULL, *short_from;
>      const char *in_reply_to, *orig_references, *references;
>      char *reply_headers;
> +    time_t date;
> +    struct tm *datetm;
> +    char *datestr;
>  
>      for (messages = notmuch_query_search_messages (query);
>  	 notmuch_messages_has_more (messages);
> @@ -346,10 +349,21 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_

I tried your patch. The first problem is that it doesn't apply. I had to
change the number 10 to 9 in the line above.

> +	/* If from contains '<' (not as first char),
> +	 * only use the preceding real name */
> +	short_from = talloc_strdup(ctx, from_addr);
> +	if (strstr(short_from, "<") > short_from) {
> +	  *(strstr(short_from, "<")-1) = 0;
> +	}
> +
>  	printf ("On %s, %s wrote:\n",
> -		notmuch_message_get_header (message, "date"),
> -		notmuch_message_get_header (message, "from"));
> +		datestr,
> +		short_from);

The second problem is that the value of from_addr doesn't (always?)
contain sender's addres. When I wanded to reply to this email with you
patch applied, I got: "On 2010-03-02, Michal Sojka wrote:". So I fixed
that in your patch and added removal of "" around name.

>From 0555ba560fdaad3780c186b01b102670451585fb Mon Sep 17 00:00:00 2001
From: Sebastian Spaeth <Sebastian@SSpaeth.de>
Date: Tue, 2 Mar 2010 13:37:42 +0100
Subject: [PATCH] notmuch-reply: Use a shorter 'On, X Y wrote:' line

Previously, we would output:
'On Thu, 25 Feb 2010 14:32:54 +0100, Sebastian Spaeth <Sebastian@SSpaeth.de> wrote:' now it is:
'On 2010-02-25, Sebastian Spaeth wrote:'

In case we don't find a '<' (as indicator for 'Realname <email>'), we still use the whole from address.

Signed-off-by: Sebastian Spaeth <Sebastian@SSpaeth.de>

Modified to use proper From header and strip "".
Signed-off-by: Michal Sojka <sojkam1@fel.cvut.cz>
---
 notmuch-reply.c |   28 +++++++++++++++++++++++++---
 1 files changed, 25 insertions(+), 3 deletions(-)

diff --git a/notmuch-reply.c b/notmuch-reply.c
index 98f6442..0ef4954 100644
--- a/notmuch-reply.c
+++ b/notmuch-reply.c
@@ -288,9 +288,12 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
     GMimeMessage *reply;
     notmuch_messages_t *messages;
     notmuch_message_t *message;
-    const char *subject, *from_addr = NULL;
+    const char *subject, *from_addr = NULL, *short_from;
     const char *in_reply_to, *orig_references, *references;
     char *reply_headers;
+    time_t date;
+    struct tm *datetm;
+    char *datestr, *angle;
 
     for (messages = notmuch_query_search_messages (query);
 	 notmuch_messages_has_more (messages);
@@ -346,9 +349,28 @@ notmuch_reply_format_default(void *ctx, notmuch_config_t *config, notmuch_query_
 	g_object_unref (G_OBJECT (reply));
 	reply = NULL;
 
+	date = notmuch_message_get_date(message);
+	datetm = gmtime( &date );
+	datestr = talloc_array(ctx, char, 11);
+	strftime(datestr, 11, "%Y-%m-%d", datetm);
+
+	/* If from contains '<' (not as first char), only use the
+	 * preceding real name without "" (if present). */
+	short_from = notmuch_message_get_header (message, "from");
+	if ((angle = strchr(short_from, '<')) > short_from) {
+	    while (angle-1 >= short_from && *(angle-1) == ' ')
+		angle--;
+	    *angle = '\0';
+	    if (*short_from == '"' && *(angle-1) == '"' &&
+		angle-1 > short_from) {
+		short_from++;
+		*(angle-1) = '\0';
+	    }
+	}
+
 	printf ("On %s, %s wrote:\n",
-		notmuch_message_get_header (message, "date"),
-		notmuch_message_get_header (message, "from"));
+		datestr,
+		short_from);
 
 	show_message_body (notmuch_message_get_filename (message), reply_part);
 
-- 
1.7.0


Thread: