diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2011-08-26 22:05:09 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2011-08-26 22:05:09 +0100 |
commit | f067867daaaefdc48bfe1c2a66b0c5095cc82036 (patch) | |
tree | 391a9fcc0ff47ec476576dd5ec509ec973bf74b6 /alot | |
parent | 160515b8bbfc6f86287fa2e3ea90bb1258b4abf0 (diff) |
parse multiline headers from editor input
The input still contains utf-8 encoded stuff tped in by the user (in headers and body), that needs
to be recoded to mime format. Hence we do it ourselves.
This adds handling for multiline header values and fixes issue #31
Diffstat (limited to 'alot')
-rw-r--r-- | alot/command.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/alot/command.py b/alot/command.py index 71618672..c5af8d35 100644 --- a/alot/command.py +++ b/alot/command.py @@ -17,6 +17,7 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>. Copyright (C) 2011 Patrick Totzke <patricktotzke@gmail.com> """ import os +import re import code import glob import logging @@ -751,17 +752,29 @@ class EnvelopeEditCommand(Command): self.mail = ui.current_buffer.get_email() def openEnvelopeFromTmpfile(): + # This parses the input from the tempfile. + # we do this ourselves here because we want to be able to + # just type utf-8 encoded stuff into the tempfile and let alot worry + # about encodings. + + # get input f = open(tf.name) enc = settings.config.get('general', 'editor_writes_encoding') editor_input = f.read().decode(enc) - - #split editor out headertext, bodytext = editor_input.split('\n\n', 1) + # go through multiline, utf-8 encoded headers + key = value = None for line in headertext.splitlines(): - key, value = line.strip().split(':', 1) - value = value.strip() - del self.mail[key] # ensure there is only one + if re.match('\w+:', line): #new k/v pair + if key and value: # save old one from stack + del self.mail[key] # ensure unique values in mails + self.mail[key] = encode_header(key, value) # save + key, value = line.strip().split(':', 1) # parse new pair + elif key and value: # append new line without key prefix to value + value += line + if key and value: # save last one if present + del self.mail[key] self.mail[key] = encode_header(key, value) if self.mail.is_multipart(): @@ -785,7 +798,7 @@ class EnvelopeEditCommand(Command): for key in edit_headers: value = u'' if key in self.mail: - value = decode_header(self.mail[key]) + value = decode_header(self.mail.get(key, '')) headertext += '%s: %s\n' % (key, value) if self.mail.is_multipart(): |