summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorpazz <patricktotzke@gmail.com>2011-08-06 15:57:38 +0100
committerpazz <patricktotzke@gmail.com>2011-08-06 15:57:38 +0100
commitc747d0c845ca6cb2ec943249b8ce65012dae3705 (patch)
tree774cc8b0990f82e54ae8057833453599e0dfb957
parent622627f3fd3c20cc2ca2407f33a516c539bcc35d (diff)
save attachments
-rw-r--r--alot/command.py62
-rw-r--r--alot/settings.py4
2 files changed, 59 insertions, 7 deletions
diff --git a/alot/command.py b/alot/command.py
index dba61a4c..7f7ade36 100644
--- a/alot/command.py
+++ b/alot/command.py
@@ -32,6 +32,7 @@ from email.header import Header
import buffer
import settings
import widgets
+import completion
from db import DatabaseROError
from db import DatabaseLockedError
from completion import ContactsCompleter
@@ -615,6 +616,46 @@ class FoldMessagesCommand(Command):
widget.fold(visible=False)
+class SaveAttachmentCommand(Command):
+ def __init__(self, all=False, path=None, **kwargs):
+ Command.__init__(self, **kwargs)
+ self.all = all
+ self.path = path
+
+ def apply(self, ui):
+ pcomplete = completion.PathCompleter()
+ if self.all:
+ msg = ui.current_buffer.get_selected_message()
+ if not self.path:
+ self.path = ui.prompt(prefix='save attachments to:', text =
+ os.path.join('~', ''),
+ completer=pcomplete)
+ if self.path:
+ self.path = os.path.expanduser(self.path)
+ if os.path.isdir(self.path):
+ for a in msg.get_attachments():
+ dest = a.save(self.path)
+ ui.notify('saved attachment as: %s' % dest)
+ else:
+ ui.notify('not a directory: %s' % self.path)
+ else:
+ ui.notify('canceled')
+ else: # save focussed attachment
+ focus = ui.get_deep_focus()
+ if isinstance(focus, widgets.AttachmentWidget):
+ attachment = focus.get_attachment()
+ filename = attachment.get_filename()
+ if not self.path:
+ self.path = ui.prompt(prefix='save attachment as:',
+ text=os.path.join('~', filename),
+ completer=pcomplete)
+ if self.path:
+ attachment.save(os.path.expanduser(self.path))
+ ui.notify('saved attachment as: %s' % self.path)
+ else:
+ ui.notify('canceled')
+
+
class OpenAttachmentCommand(Command):
"""displays an attachment according to mailcap"""
def __init__(self, attachment, **kwargs):
@@ -623,15 +664,14 @@ class OpenAttachmentCommand(Command):
def apply(self, ui):
logging.info('open attachment')
- lines = []
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
+ cmd = handler % path.replace(' ', '\ ')
else:
- cmd = '%s %s' % (handler, path)
+ cmd = '%s %s' % (handler, path.replace(' ', '\ '))
def afterwards():
os.remove(path)
ui.apply_command(ExternalCommand(cmd, on_success=afterwards,
@@ -808,6 +848,7 @@ COMMANDS = {
'fold': (FoldMessagesCommand, {'visible': False}),
'unfold': (FoldMessagesCommand, {'visible': True}),
'select': (ThreadSelectCommand, {}),
+ 'save': (SaveAttachmentCommand, {}),
},
'global': {
'bnext': (BufferFocusCommand, {'offset': 1}),
@@ -894,9 +935,20 @@ def interpret_commandline(cmdline, mode):
elif cmd == 'toggletag':
return commandfactory(cmd, mode=mode, tag=params)
elif cmd == 'fold':
- return commandfactory(cmd, mode=mode, all=(params=='all'))
+ return commandfactory(cmd, mode=mode, all=(params=='--all'))
elif cmd == 'unfold':
- return commandfactory(cmd, mode=mode, all=(params=='all'))
+ return commandfactory(cmd, mode=mode, all=(params=='--all'))
+ elif cmd == 'save':
+ args = params.split(' ')
+ allset = False
+ pathset = None
+ if args:
+ if args[0] == '--all':
+ allset = True
+ pathset = ' '.join(args[1:])
+ else:
+ pathset = params
+ return commandfactory(cmd, mode=mode, all=allset, path=pathset)
elif cmd == 'edit':
filepath = os.path.expanduser(params)
if os.path.isfile(filepath):
diff --git a/alot/settings.py b/alot/settings.py
index e5c0987f..296dce7f 100644
--- a/alot/settings.py
+++ b/alot/settings.py
@@ -234,8 +234,8 @@ DEFAULTS = {
'f': 'forward',
'g': 'groupreply',
'r': 'reply',
- 'R': 'unfold all',
- 'M': 'fold all',
+ 'C': 'fold --all',
+ 'E': 'unfold --all',
'enter': 'select',
},
'taglist-maps': {