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

3 messages from 2010-02-12 to 2010-02-12. Participants: Catalin Marinas, Karl Wiberg.
Thread: https://gitlist.dev/t/22630

## Catalin Marinas, 2010-02-12 15:39

Subject: [StGit PATCH] mail: Use space rather than tab for long header folding
Message-ID: <20100212153905.11578.83879.stgit@pc1117.cambridge.arm.com>
URL: https://gitlist.dev/e/20100212153905.11578.83879.stgit%40pc1117.cambridge.arm.com

```
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(-)

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, 2010-02-12 16:09

Subject: Re: [StGit PATCH] mail: Use space rather than tab for long header folding
Message-ID: <b8197bcb1002120809q5eb458f7pa9e9b0562af6bcda@mail.gmail.com>
URL: https://gitlist.dev/e/b8197bcb1002120809q5eb458f7pa9e9b0562af6bcda%40mail.gmail.com
In-Reply-To: <20100212153905.11578.83879.stgit@pc1117.cambridge.arm.com>

```
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?

-- 
Karl Wiberg, kha@treskal.com
   subrabbit.wordpress.com
   www.treskal.com/kalle

```

## Catalin Marinas, 2010-02-12 16:15

Subject: Re: [StGit PATCH] mail: Use space rather than tab for long header folding
Message-ID: <b0943d9e1002120815n69691e63p80146f9dcd5ff68c@mail.gmail.com>
URL: https://gitlist.dev/e/b0943d9e1002120815n69691e63p80146f9dcd5ff68c%40mail.gmail.com
In-Reply-To: <b8197bcb1002120809q5eb458f7pa9e9b0562af6bcda@mail.gmail.com>

```
On 12 February 2010 16:09, Karl Wiberg <kha@treskal.com> wrote:
> 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

```
