diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2015-12-16 16:10:39 +0000 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2015-12-16 16:10:39 +0000 |
commit | 81b010380a373ee11454f3baeac718a545239a08 (patch) | |
tree | 099ca54965abee0d36d563b30ccd177310bf79a2 | |
parent | 96126036a672b75b071a7d6c5aef8e4aced10eee (diff) | |
parent | 0042fc710dfcc93d9c09891c388fae2797ce052f (diff) |
Merge branch '0.3.6-feature-sanitize-attachments-811'
-rw-r--r-- | alot/commands/thread.py | 7 | ||||
-rw-r--r-- | docs/source/configuration/hooks.rst | 16 |
2 files changed, 23 insertions, 0 deletions
diff --git a/alot/commands/thread.py b/alot/commands/thread.py index 67888255..6349fe2b 100644 --- a/alot/commands/thread.py +++ b/alot/commands/thread.py @@ -926,6 +926,13 @@ class OpenAttachmentCommand(Command): if '%s' in handler_raw_commandstring: nametemplate = entry.get('nametemplate', '%s') prefix, suffix = parse_mailcap_nametemplate(nametemplate) + + fn_hook = settings.get_hook('sanitize_attachment_filename') + if fn_hook: + # get filename + filename = self.attachment.get_filename() + prefix, suffix = fn_hook(filename, prefix, suffix) + tmpfile = tempfile.NamedTemporaryFile(delete=False, prefix=prefix, suffix=suffix) diff --git a/docs/source/configuration/hooks.rst b/docs/source/configuration/hooks.rst index 1709df68..a384d73e 100644 --- a/docs/source/configuration/hooks.rst +++ b/docs/source/configuration/hooks.rst @@ -178,3 +178,19 @@ Apart from command pre- and posthooks, the following hooks will be interpreted: .. py:function:: exit() run just before the program exits + +.. py:function:: sanitize_attachment_filename(filename=None, prefix='', suffix='') + + returns `prefix` and `suffix` for a sanitized filename to use while + opening an attachment. + The `prefix` and `suffix` are used to open a file named + `prefix` + `XXXXXX` + `suffix` in a temporary directory. + + :param filename: filename provided in the email (can be None) + :type filename: str or None + :param prefix: prefix string as found on mailcap + :type prefix: str + :param suffix: suffix string as found on mailcap + :type suffix: str + :returns: tuple of `prefix` and `suffix` + :rtype: (str, str) |