summaryrefslogtreecommitdiff
path: root/alot
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
parent45bd6174c34eb18128670b1acd62362d5f4b182e (diff)
open attachments according to mailcap
issue #31
Diffstat (limited to 'alot')
-rw-r--r--alot/command.py28
-rw-r--r--alot/message.py1
-rw-r--r--alot/send.py1
-rw-r--r--alot/settings.py7
-rw-r--r--alot/widgets.py9
5 files changed, 32 insertions, 14 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
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):