When inserting headers into the message file due to $edit_headers being
set, do not add trailing spaces if $text_flowed is also set.  This
avoids the editor from treating the entire header section as a single
flowed paragraph and reformatting it.

Vim will do a passable job of editing messages to be sent as
format=flowed, if "a" and "w" are included in the formatoptions setting.
But, without this change that interacts badly with having the headers
available for editing as well, since any change there will cause much
of the header section to be reformatted, messing it up.
---
 sendlib.c |   50 ++++++++++++++++++++++++++++++++++++++------------
 1 file changed, 38 insertions(+), 12 deletions(-)

diff --git a/sendlib.c b/sendlib.c
index 249d6a1..3b948d2 100644
--- a/sendlib.c
+++ b/sendlib.c
@@ -1946,14 +1946,20 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, 
BODY *attach,
   {
     buffer[0] = 0;
     rfc822_write_address (buffer, sizeof (buffer), env->from, 0);
-    fprintf (fp, "From: %s\n", buffer);
+    if (option (OPTTEXTFLOWED) && buffer[0] == 0)
+      fprintf (fp, "From:\n");
+    else
+      fprintf (fp, "From: %s\n", buffer);
   }
 
   if (env->sender && !privacy)
   {
     buffer[0] = 0;
     rfc822_write_address (buffer, sizeof (buffer), env->sender, 0);
-    fprintf (fp, "Sender: %s\n", buffer);
+    if (option (OPTTEXTFLOWED) && buffer[0] == 0)
+      fprintf (fp, "Sender:\n");
+    else
+      fprintf (fp, "Sender: %s\n", buffer);
   }
 
   if (env->to)
@@ -1961,16 +1967,24 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, 
BODY *attach,
     fputs ("To: ", fp);
     mutt_write_address_list (env->to, fp, 4, 0);
   }
-  else if (mode > 0)
-    fputs ("To: \n", fp);
+  else if (mode > 0) {
+    if (option (OPTTEXTFLOWED))
+      fputs ("To", fp);
+    else
+      fputs ("To: \n", fp);
+  }
 
   if (env->cc)
   {
     fputs ("Cc: ", fp);
     mutt_write_address_list (env->cc, fp, 4, 0);
   }
-  else if (mode > 0)
-    fputs ("Cc: \n", fp);
+  else if (mode > 0) {
+    if (option (OPTTEXTFLOWED))
+      fputs ("Cc:\n", fp);
+    else
+      fputs ("Cc: \n", fp);
+  }
 
   if (env->bcc)
   {
@@ -1980,13 +1994,21 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, 
BODY *attach,
       mutt_write_address_list (env->bcc, fp, 5, 0);
     }
   }
-  else if (mode > 0)
-    fputs ("Bcc: \n", fp);
+  else if (mode > 0) {
+    if (option (OPTTEXTFLOWED))
+      fputs ("Bcc:\n", fp);
+    else
+      fputs ("Bcc: \n", fp);
+  }
 
   if (env->subject)
     mutt_write_one_header (fp, "Subject", env->subject, NULL, 0, 0);
-  else if (mode == 1)
-    fputs ("Subject: \n", fp);
+  else if (mode == 1) {
+    if (option (OPTTEXTFLOWED))
+      fputs ("Subject:\n", fp);
+    else
+      fputs ("Subject: \n", fp);
+  }
 
   /* save message id if the user has set it */
   if (env->message_id && !privacy)
@@ -1997,8 +2019,12 @@ int mutt_write_rfc822_header (FILE *fp, ENVELOPE *env, 
BODY *attach,
     fputs ("Reply-To: ", fp);
     mutt_write_address_list (env->reply_to, fp, 10, 0);
   }
-  else if (mode > 0)
-    fputs ("Reply-To: \n", fp);
+  else if (mode > 0) {
+    if (option (OPTTEXTFLOWED))
+      fputs ("Reply-To:\n", fp);
+    else
+      fputs ("Reply-To: \n", fp);
+  }
 
   if (env->mail_followup_to)
   {
-- 
1.7.10.4

Reply via email to