From 2fbf2fcb295f97f9eb6cb9393667c6fb8b2d315e Mon Sep 17 00:00:00 2001 From: pazz Date: Sat, 6 Aug 2011 14:46:18 +0100 Subject: open attachments according to mailcap issue #31 --- alot/command.py | 28 +++++++++++++++++++++++----- alot/message.py | 1 + alot/send.py | 1 - alot/settings.py | 7 ++++++- alot/widgets.py | 9 ++------- 5 files changed, 32 insertions(+), 14 deletions(-) (limited to 'alot') 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 diff --git a/alot/message.py b/alot/message.py index ca4c5a83..b9593fee 100644 --- a/alot/message.py +++ b/alot/message.py @@ -277,3 +277,4 @@ class Attachment: FILE = open(path, "w") FILE.write(self.part.get_payload(decode=True)) FILE.close() + return path diff --git a/alot/send.py b/alot/send.py index 02fdc683..c81b7947 100644 --- a/alot/send.py +++ b/alot/send.py @@ -50,7 +50,6 @@ class Sender: class SendmailSender(Sender): - def __init__(self, sendmail_cmd, mailbox=None): self.cmd = sendmail_cmd self.mailbox = mailbox diff --git a/alot/settings.py b/alot/settings.py index 048da3e0..e5c0987f 100644 --- a/alot/settings.py +++ b/alot/settings.py @@ -52,6 +52,8 @@ DEFAULTS = { 'header_fg': 'white', 'message_attachment_bg': 'dark gray', 'message_attachment_fg': 'light gray', + 'message_attachment_focussed_bg': 'light green', + 'message_attachment_focussed_fg': 'light gray', 'message_body_bg': 'default', 'message_body_fg': 'light gray', 'message_header_bg': 'dark gray', @@ -110,6 +112,7 @@ DEFAULTS = { 'footer': 'standout', 'header': 'standout', 'message_attachment': 'default', + 'message_attachment_focussed': 'underline', 'message_body': 'default', 'message_header': 'default', 'message_header_key': 'default', @@ -149,6 +152,8 @@ DEFAULTS = { 'header_fg': 'white', 'message_attachment_bg': 'dark gray', 'message_attachment_fg': 'light gray', + 'message_attachment_focussed_bg': 'light green', + 'message_attachment_focussed_fg': 'light gray', 'message_body_bg': 'default', 'message_body_fg': 'light gray', 'message_header_bg': 'dark gray', @@ -394,7 +399,7 @@ hooks = HookManager() mailcaps = mailcap.getcaps() -def get_mime_handler(mime_type, key, interactive=True): +def get_mime_handler(mime_type, key='view', interactive=True): if interactive: mc_tuple = mailcap.findmatch(mailcaps, mime_type, diff --git a/alot/widgets.py b/alot/widgets.py index 44e0accd..bcba017c 100644 --- a/alot/widgets.py +++ b/alot/widgets.py @@ -434,12 +434,6 @@ class MessageHeaderWidget(urwid.AttrMap): headerlines.append(line) return headerlines - def selectable(self): - return True - - def keypress(self, size, key): - return key - class MessageBodyWidget(urwid.AttrMap): """displays printable parts of an email""" @@ -459,7 +453,8 @@ class AttachmentWidget(urwid.WidgetWrap): def __init__(self, attachment): self.attachment = attachment widget = urwid.AttrMap(urwid.Text(unicode(attachment)), - 'message_attachment') + 'message_attachment', + 'message_attachment_focussed') urwid.WidgetWrap.__init__(self, widget) def get_attachment(self): -- cgit v1.2.3