{"thread":{"id":"22630","subject":"[StGit PATCH] mail: Use space rather than tab for long header folding","startedAt":"2010-02-12T15:39:05Z","lastAt":"2010-02-12T16:15:19Z","messageCount":3,"participants":["Catalin Marinas","Karl Wiberg"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"134348","messageId":"20100212153905.11578.83879.stgit@pc1117.cambridge.arm.com","threadId":"22630","inReplyTo":null,"subject":"[StGit PATCH] mail: Use space rather than tab for long header folding","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@arm.com","sentAt":"2010-02-12T15:39:05Z","receivedAt":"2010-02-12T15:39:05Z","isPatch":true,"sender":{"key":"catalin.marinas@arm.com","avatar":null},"body":"The default Python implementation (at least 2.5 and earlier) fold long\ne-mail header lines by inserting \"\\n\\t\". This causes issues with some\ne-mail clients that remove both \"\\n\\t\". The RFC2822 shows that folding\nshould be done with \"\\n \". The Python workaround is to use a Header\nobject instead of a string when setting the message headers.\n\nSigned-off-by: Catalin Marinas <catalin.marinas@gmail.com>\n---\n stgit/commands/mail.py |    8 +++++---\n 1 files changed, 5 insertions(+), 3 deletions(-)\n\ndiff --git a/stgit/commands/mail.py b/stgit/commands/mail.py\nindex e1de847..34262d3 100644\n--- a/stgit/commands/mail.py\n+++ b/stgit/commands/mail.py\n@@ -170,7 +170,7 @@ def __get_sender():\n \n def __addr_list(msg, header):\n     return [addr for name, addr in\n-            email.Utils.getaddresses(msg.get_all(header, []))]\n+            email.Utils.getaddresses(map(str, msg.get_all(header, [])))]\n \n def __parse_addresses(msg):\n     \"\"\"Return a two elements tuple: (from, [to])\n@@ -304,7 +304,8 @@ def __send_message(type, tmpl, options, *args):\n \n def __update_header(msg, header, addr = '', ignore = ()):\n     def __addr_pairs(msg, header, extra):\n-        pairs = email.Utils.getaddresses(msg.get_all(header, []) + extra)\n+        pairs = email.Utils.getaddresses(map(str,\n+                                             msg.get_all(header, []) + extra))\n         # remove pairs without an address and resolve the aliases\n         return [address_or_alias(p) for p in pairs if p[1]]\n \n@@ -408,7 +409,8 @@ def __encode_message(msg):\n                 pass\n             words.append(email.Header.Header(uword).encode())\n         new_val = ' '.join(words)\n-        msg.replace_header(header, new_val)\n+        msg.replace_header(header,\n+                           email.Header.Header(new_val, header_name = header))\n \n     # encode the body and set the MIME and encoding headers\n     if msg.is_multipart():\n"},{"id":"134350","messageId":"b8197bcb1002120809q5eb458f7pa9e9b0562af6bcda@mail.gmail.com","threadId":"22630","inReplyTo":"20100212153905.11578.83879.stgit@pc1117.cambridge.arm.com","subject":"Re: [StGit PATCH] mail: Use space rather than tab for long header folding","fromName":"Karl Wiberg","fromEmail":"kha@treskal.com","sentAt":"2010-02-12T16:09:47Z","receivedAt":"2010-02-12T16:09:47Z","isPatch":true,"sender":{"key":"kha@treskal.com","avatar":"https://gravatar.com/avatar/f0120c734b5279b345075a28521e1ac66acb20c9913ffe9bf6ae97e53f7f3f13?d=mp&s=160"},"body":"On Fri, Feb 12, 2010 at 4:39 PM, Catalin Marinas\n<catalin.marinas@arm.com> wrote:\n\n> The default Python implementation (at least 2.5 and earlier) fold long\n> e-mail header lines by inserting \"\\n\\t\". This causes issues with some\n> e-mail clients that remove both \"\\n\\t\". The RFC2822 shows that folding\n> should be done with \"\\n \". The Python workaround is to use a Header\n> object instead of a string when setting the message headers.\n\nAha. If this works like I think it does, it'll eliminate the problem\nwhere patches with long subject lines pick up tab characters when\nimported from e-mails. But that's not the motivation you're\ndescribing, is it?\n\n-- \nKarl Wiberg, kha@treskal.com\n   subrabbit.wordpress.com\n   www.treskal.com/kalle\n"},{"id":"134353","messageId":"b0943d9e1002120815n69691e63p80146f9dcd5ff68c@mail.gmail.com","threadId":"22630","inReplyTo":"b8197bcb1002120809q5eb458f7pa9e9b0562af6bcda@mail.gmail.com","subject":"Re: [StGit PATCH] mail: Use space rather than tab for long header folding","fromName":"Catalin Marinas","fromEmail":"catalin.marinas@gmail.com","sentAt":"2010-02-12T16:15:19Z","receivedAt":"2010-02-12T16:15:19Z","isPatch":true,"sender":{"key":"catalin.marinas@gmail.com","avatar":null},"body":"On 12 February 2010 16:09, Karl Wiberg <kha@treskal.com> wrote:\n> On Fri, Feb 12, 2010 at 4:39 PM, Catalin Marinas\n> <catalin.marinas@arm.com> wrote:\n>\n>> The default Python implementation (at least 2.5 and earlier) fold long\n>> e-mail header lines by inserting \"\\n\\t\". This causes issues with some\n>> e-mail clients that remove both \"\\n\\t\". The RFC2822 shows that folding\n>> should be done with \"\\n \". The Python workaround is to use a Header\n>> object instead of a string when setting the message headers.\n>\n> Aha. If this works like I think it does, it'll eliminate the problem\n> where patches with long subject lines pick up tab characters when\n> imported from e-mails. But that's not the motivation you're\n> describing, is it?\n\nMy main motivation is only for sending e-mails as I have an Exchange\nserver here which removes the tab completely sticking two words\ntogether. If you import an e-mail sent by the patched StGit, yes, it\nwill solve this as well.\n\n-- \nCatalin\n"}]}