Do not add Message-ID for draft, unless it already has one.
authorAndrej Kacian <ticho@claws-mail.org>
Sat, 1 Oct 2016 21:41:19 +0000 (23:41 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Sat, 1 Oct 2016 21:41:19 +0000 (23:41 +0200)
We now add a Message-ID header only when queuing a message,
and we honor existing Message-ID and References headers in
drafts, if there are any.

src/compose.c

index c9cd93c8bb88011910a53e2ce10a2c22afccb778..5554b668008f9dbb585d9a83c86c65b2f7a95b01 100644 (file)
@@ -2971,27 +2971,39 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
        if (compose->mode == COMPOSE_REEDIT) {
                if (msginfo->inreplyto && *msginfo->inreplyto)
                        compose->inreplyto = g_strdup(msginfo->inreplyto);
-               return 0;
-       }
 
-       if (msginfo->msgid && *msginfo->msgid)
-               compose->inreplyto = g_strdup(msginfo->msgid);
+               if (msginfo->msgid && *msginfo->msgid)
+                       compose->msgid = g_strdup(msginfo->msgid);
 
-       if (!compose->references) {
-               if (msginfo->msgid && *msginfo->msgid) {
-                       if (msginfo->inreplyto && *msginfo->inreplyto)
-                               compose->references =
-                                       g_strdup_printf("<%s>\n\t<%s>",
-                                                       msginfo->inreplyto,
-                                                       msginfo->msgid);
-                       else
+               if (msginfo->references != NULL) {
+                       GString *refs = g_string_new(NULL);
+                       GSList *r = msginfo->references;
+                       while (r != NULL) {
+                               g_string_append_printf(refs, "<%s>%s", (gchar *)r->data,
+                                               (g_slist_next(r) ? "\n\t" : ""));
+                               r = g_slist_next(r);
+                       }
+               }
+       } else {
+               if (msginfo->msgid && *msginfo->msgid)
+                       compose->inreplyto = g_strdup(msginfo->msgid);
+
+               if (!compose->references) {
+                       if (msginfo->msgid && *msginfo->msgid) {
+                               if (msginfo->inreplyto && *msginfo->inreplyto)
+                                       compose->references =
+                                               g_strdup_printf("<%s>\n\t<%s>",
+                                                               msginfo->inreplyto,
+                                                               msginfo->msgid);
+                               else
+                                       compose->references =
+                                               g_strconcat("<", msginfo->msgid, ">",
+                                                           NULL);
+                       } else if (msginfo->inreplyto && *msginfo->inreplyto) {
                                compose->references =
-                                       g_strconcat("<", msginfo->msgid, ">",
+                                       g_strconcat("<", msginfo->inreplyto, ">",
                                                    NULL);
-               } else if (msginfo->inreplyto && *msginfo->inreplyto) {
-                       compose->references =
-                               g_strconcat("<", msginfo->inreplyto, ">",
-                                           NULL);
+                       }
                }
        }
 
@@ -5534,9 +5546,17 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        gchar *from_name = NULL;
        FolderItem *outbox;
 
-       if (action == COMPOSE_WRITE_FOR_SEND)
+       if (action == COMPOSE_WRITE_FOR_SEND) {
                attach_parts = TRUE;
 
+               /* We're sending the message, generate a Message-ID
+                * if necessary. */
+               if (compose->msgid == NULL &&
+                               compose->account->gen_msgid) {
+                       compose->msgid = prefs_account_generate_msgid(compose->account);
+               }
+       }
+
        /* create message MimeInfo */
        mimemsg = procmime_mimeinfo_new();
         mimemsg->type = MIMETYPE_MESSAGE;
@@ -5545,6 +5565,8 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
        mimemsg->tmp = TRUE; /* must free content later */
        mimemsg->data.mem = compose_get_header(compose);
 
+       debug_print(mimemsg->data.mem);
+
        /* Create text part MimeInfo */
        /* get all composed text */
        buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(compose->text));
@@ -6546,14 +6568,9 @@ static gchar *compose_get_header(Compose *compose)
        g_free(str);
 
        /* Message-ID */
-       if (compose->account->gen_msgid) {
-               gchar *addr = prefs_account_generate_msgid(compose->account);
-               g_string_append_printf(header, "Message-ID: <%s>\n", addr);
-               if (compose->msgid)
-                       g_free(compose->msgid);
-               compose->msgid = addr;
-       } else {
-               compose->msgid = NULL;
+       if (compose->msgid != NULL && strlen(compose->msgid) > 0) {
+               g_string_append_printf(header, "Message-ID: <%s>\n",
+                               compose->msgid);
        }
 
        if (compose->remove_references == FALSE) {