summaryrefslogtreecommitdiff
path: root/alot/command.py
diff options
context:
space:
mode:
authorpazz <patricktotzke@gmail.com>2011-08-06 14:46:18 +0100
committerpazz <patricktotzke@gmail.com>2011-08-06 14:46:18 +0100
commit2fbf2fcb295f97f9eb6cb9393667c6fb8b2d315e (patch)
treec543f4cb1d61b5a6d0ab157124d476e5907bfa1f /alot/command.py
parent45bd6174c34eb18128670b1acd62362d5f4b182e (diff)
open attachments according to mailcap
issue #31
Diffstat (limited to 'alot/command.py')
-rw-r--r--alot/command.py28
1 files changed, 23 insertions, 5 deletions
diff --git a/alot/command.py b/alot/command.py
index be895a86..dba61a4c 100644
--- a/alot/command.py
+++ b/alot/command.py
@@ -327,13 +327,15 @@ class ToggleThreadTagCommand(Command):
class ComposeCommand(Command):
"""compose a new email and open an envelope for it"""
- def __init__(self, mail=None, **kwargs):
+ def __init__(self, mail=None, headers={}, **kwargs):
+ Command.__init__(self, **kwargs)
if not mail:
self.mail = MIMEMultipart()
self.mail.attach(MIMEText('', 'plain', 'UTF-8'))
else:
self.mail = mail
- Command.__init__(self, **kwargs)
+ for key,value in headers.items():
+ self.mail[key] = encode_header(key, value)
def apply(self, ui):
# TODO: fill with default header (per account)
@@ -614,15 +616,28 @@ class FoldMessagesCommand(Command):
class OpenAttachmentCommand(Command):
+ """displays an attachment according to mailcap"""
def __init__(self, attachment, **kwargs):
Command.__init__(self, **kwargs)
self.attachment = attachment
def apply(self, ui):
+ logging.info('open attachment')
lines = []
-#save to tmpfile
-#find out mimehandler
-#eternalcommand
+ path = self.attachment.save(tempfile.gettempdir())
+ mimetype = self.attachment.get_content_type()
+ handler = settings.get_mime_handler(mimetype)
+ if handler:
+ if '%s' in handler:
+ cmd = handler % path
+ else:
+ cmd = '%s %s' % (handler, path)
+ def afterwards():
+ os.remove(path)
+ ui.apply_command(ExternalCommand(cmd, on_success=afterwards,
+ in_thread=True))
+ else:
+ ui.notify('unknown mime type')
class ThreadSelectCommand(Command):
def apply(self, ui):
@@ -630,7 +645,10 @@ class ThreadSelectCommand(Command):
if isinstance(focus, widgets.MessageSummaryWidget):
ui.apply_command(FoldMessagesCommand())
elif isinstance(focus, widgets.AttachmentWidget):
+ logging.info('open attachment')
ui.apply_command(OpenAttachmentCommand(focus.get_attachment()))
+ else:
+ logging.info('unknown widget %s' % focus)
### ENVELOPE