diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2011-10-19 19:30:41 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2011-10-19 19:30:41 +0100 |
commit | 9afb6d1488151b0c5ba0130a974bab380520a06e (patch) | |
tree | ba67bcb6cb8fde19f74f5983962409797da224a4 /alot | |
parent | 702898acc08bafe724b156a56c2e1dfa72f6e6d8 (diff) | |
parent | fdea26a8576be31687539cca81c947594e7def44 (diff) |
Merge branch 'master' of github.com:pazz/alot
Diffstat (limited to 'alot')
-rw-r--r-- | alot/commands/envelope.py | 29 | ||||
-rw-r--r-- | alot/commands/globals.py | 6 | ||||
-rw-r--r-- | alot/defaults/alot.rc | 8 |
3 files changed, 35 insertions, 8 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index 7d9a3232..e800278b 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -117,6 +117,19 @@ class EnvelopeEditCommand(Command): if not self.mail: self.mail = ui.current_buffer.get_email() + #determine editable headers + edit_headers = set(settings.config.getstringlist('general', + 'edit_headers_whitelist')) + if '*' in edit_headers: + edit_headers = set(self.mail.keys()) + blacklist = set(settings.config.getstringlist('general', + 'edit_headers_blacklist')) + if '*' in blacklist: + blacklist = set(self.mail.keys()) + ui.logger.debug('BLACKLIST: %s' % blacklist) + self.edit_headers = edit_headers - blacklist + ui.logger.info('editable headers: %s' % blacklist) + def openEnvelopeFromTmpfile(): # This parses the input from the tempfile. # we do this ourselves here because we want to be able to @@ -127,7 +140,11 @@ class EnvelopeEditCommand(Command): f = open(tf.name) enc = settings.config.get('general', 'editor_writes_encoding') editor_input = f.read().decode(enc) - headertext, bodytext = editor_input.split('\n\n', 1) + if self.edit_headers: + headertext, bodytext = editor_input.split('\n\n', 1) + else: + headertext = '' + bodytext = editor_input # call post-edit translate hook translate = settings.hooks.get('post_edit_translate') @@ -139,7 +156,7 @@ class EnvelopeEditCommand(Command): # go through multiline, utf-8 encoded headers key = value = None for line in headertext.splitlines(): - if re.match('\w+:', line): # new k/v pair + if re.match('[a-zA-Z0-9_-]+:', 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 @@ -166,9 +183,8 @@ class EnvelopeEditCommand(Command): ui.current_buffer.set_email(self.mail) # decode header - edit_headers = ['Subject', 'To', 'From'] headertext = u'' - for key in edit_headers: + for key in self.edit_headers: value = u'' if key in self.mail: value = decode_header(self.mail.get(key, '')) @@ -191,8 +207,9 @@ class EnvelopeEditCommand(Command): #write stuff to tempfile tf = tempfile.NamedTemporaryFile(delete=False) - content = '%s\n\n%s' % (headertext, - bodytext) + content = bodytext + if headertext: + content = '%s\n\n%s' % (headertext, content) tf.write(content.encode('utf-8')) tf.flush() tf.close() diff --git a/alot/commands/globals.py b/alot/commands/globals.py index 17b37ab2..71c5768d 100644 --- a/alot/commands/globals.py +++ b/alot/commands/globals.py @@ -177,7 +177,8 @@ class EditCommand(ExternalCommand): if thread != None: self.thread = thread else: - self.thread = settings.config.getboolean('general', 'editor_in_thread') + self.thread = settings.config.getboolean('general', + 'editor_in_thread') self.editor_cmd = None if os.path.isfile('/usr/bin/editor'): @@ -185,11 +186,12 @@ class EditCommand(ExternalCommand): self.editor_cmd = os.environ.get('EDITOR', self.editor_cmd) self.editor_cmd = settings.config.get('general', 'editor_cmd', fallback=self.editor_cmd) - logging.debug('using editor_cmd: %s' %self.editor_cmd) + logging.debug('using editor_cmd: %s' % self.editor_cmd) ExternalCommand.__init__(self, self.editor_cmd, path=self.path, spawn=self.spawn, thread=self.thread, **kwargs) + def apply(self, ui): if self.editor_cmd == None: ui.notify('no editor set', priority='error') diff --git a/alot/defaults/alot.rc b/alot/defaults/alot.rc index 4255bb86..fb980dfa 100644 --- a/alot/defaults/alot.rc +++ b/alot/defaults/alot.rc @@ -42,6 +42,14 @@ editor_spawn = False # will make alot non-blocking during edits editor_in_thread = False + +# Which header fields should be editable in your editor +# used are those that match the whitelist and don't macht the blacklist. +# in both cases '*' may be used to indicate all fields. +edit_headers_whitelist = * +edit_headers_blacklist = Content-Type,MIME-Version,References,In-Reply-To + + # timeout in secs after a failed attempt to flush is repeated flush_retry_timeout = 5 |