threads / patch / 22630

patchmail: Use space rather than tab for long header folding

Subject: [StGit PATCH] mail: Use space rather than tab for long header folding

## tl;dr

3 messages between Feb 12, 2010 and Feb 12, 2010. Diffs are folded; open one to read it.

replies: 2people: 3as markdown or json

Catalin Marinas· Feb 12, 2010, 15:39 UTC · lore

The default Python implementation (at least 2.5 and earlier) fold long e-mail header lines by inserting "\n\t". This causes issues with some e-mail clients that remove both "\n\t". The RFC2822 shows that folding should be done with "\n ". The Python workaround is to use a Header object instead of a string when setting the message headers.

Signed-off-by: Catalin Marinas <catalin.marinas@gmail.com>
---
 stgit/commands/mail.py |    8 +++++---
 1 files changed, 5 insertions(+), 3 deletions(-)
Show changes to stgit/commands/mail.py +5 −3
diff --git a/stgit/commands/mail.py b/stgit/commands/mail.py
index e1de847..34262d3 100644
--- a/stgit/commands/mail.py
+++ b/stgit/commands/mail.py
@@ -170,7 +170,7 @@ def __get_sender():
 
 def __addr_list(msg, header):
     return [addr for name, addr in
-            email.Utils.getaddresses(msg.get_all(header, []))]
+            email.Utils.getaddresses(map(str, msg.get_all(header, [])))]
 
 def __parse_addresses(msg):
     """Return a two elements tuple: (from, [to])
@@ -304,7 +304,8 @@ def __send_message(type, tmpl, options, *args):
 
 def __update_header(msg, header, addr = '', ignore = ()):
     def __addr_pairs(msg, header, extra):
-        pairs = email.Utils.getaddresses(msg.get_all(header, []) + extra)
+        pairs = email.Utils.getaddresses(map(str,
+                                             msg.get_all(header, []) + extra))
         # remove pairs without an address and resolve the aliases
         return [address_or_alias(p) for p in pairs if p[1]]
 
@@ -408,7 +409,8 @@ def __encode_message(msg):
                 pass
             words.append(email.Header.Header(uword).encode())
         new_val = ' '.join(words)
-        msg.replace_header(header, new_val)
+        msg.replace_header(header,
+                           email.Header.Header(new_val, header_name = header))
 
     # encode the body and set the MIME and encoding headers
     if msg.is_multipart():
Karl Wiberg· Feb 12, 2010, 16:09 UTC · re: Catalin Marinas · lore

Re: [StGit PATCH] mail: Use space rather than tab for long header folding

On Fri, Feb 12, 2010 at 4:39 PM, Catalin Marinas <catalin.marinas@arm.com> wrote:

Show 5 quoted lines
> The default Python implementation (at least 2.5 and earlier) fold long
> e-mail header lines by inserting "\n\t". This causes issues with some
> e-mail clients that remove both "\n\t". The RFC2822 shows that folding
> should be done with "\n ". The Python workaround is to use a Header
> object instead of a string when setting the message headers.

Aha. If this works like I think it does, it'll eliminate the problem where patches with long subject lines pick up tab characters when imported from e-mails. But that's not the motivation you're describing, is it?

-- 
Karl Wiberg, kha@treskal.com
   subrabbit.wordpress.com
   www.treskal.com/kalle
Catalin Marinas· Feb 12, 2010, 16:15 UTC · re: Karl Wiberg · lore

Re: [StGit PATCH] mail: Use space rather than tab for long header folding

On 12 February 2010 16:09, Karl Wiberg <kha@treskal.com> wrote:
Show 13 quoted lines
> On Fri, Feb 12, 2010 at 4:39 PM, Catalin Marinas
> <catalin.marinas@arm.com> wrote:
>
>> The default Python implementation (at least 2.5 and earlier) fold long
>> e-mail header lines by inserting "\n\t". This causes issues with some
>> e-mail clients that remove both "\n\t". The RFC2822 shows that folding
>> should be done with "\n ". The Python workaround is to use a Header
>> object instead of a string when setting the message headers.
>
> Aha. If this works like I think it does, it'll eliminate the problem
> where patches with long subject lines pick up tab characters when
> imported from e-mails. But that's not the motivation you're
> describing, is it?

My main motivation is only for sending e-mails as I have an Exchange server here which removes the tab completely sticking two words together. If you import an e-mail sent by the patched StGit, yes, it will solve this as well.

-- 
Catalin

← back to recent threads