summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--NEWS1
-rw-r--r--README.md2
-rw-r--r--USAGE2
-rw-r--r--alot/command.py57
-rw-r--r--alot/settings.py3
-rw-r--r--data/example.full.rc5
6 files changed, 69 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index c5bc1ee0..5b56780e 100644
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,7 @@ hacking on a thread view rewrite.
* signatures for outgoing mails per account
* optional display of message content in search results
* config option for strftime formating of timestamps
+* printing
* fix parse multiline headers from edited tempfile
* fix reply to unusually formated mails (e.g. no recipient)
diff --git a/README.md b/README.md
index dddea179..6e8ca745 100644
--- a/README.md
+++ b/README.md
@@ -23,12 +23,12 @@ Current features include:
* priorizable notification popups
* database manager that manages a write queue to the notmuch index
* user configurable keyboard maps
+ * printing
Soonish to be addressed non-features:
-------------------------------------
* encryption/decryption for messages
* search for strings in displayed buffer
- * print command
* folding for message parts
* undo for commands
* addressbook integration
diff --git a/USAGE b/USAGE
index b0edf3d0..e537956b 100644
--- a/USAGE
+++ b/USAGE
@@ -47,10 +47,12 @@ in the config file. These are the default keymaps:
C = fold --all
E = unfold --all
H = toggleheaders
+ P = print --all
a = toggletag inbox
enter = select
f = forward
g = groupreply
+ p = print
r = reply
Config
diff --git a/alot/command.py b/alot/command.py
index c5af8d35..942d7797 100644
--- a/alot/command.py
+++ b/alot/command.py
@@ -23,6 +23,7 @@ import glob
import logging
import threading
import subprocess
+import shlex
import email
import tempfile
import mimetypes
@@ -651,6 +652,57 @@ class ToggleHeaderCommand(Command):
msgw.toggle_full_header()
+class PrintCommand(Command):
+ def __init__(self, all=False, separately=False, confirm=True, **kwargs):
+ Command.__init__(self, **kwargs)
+ self.all = all
+ self.separately = separately
+ self.confirm = confirm
+
+ def apply(self, ui):
+ # get messages to print
+ if self.all:
+ thread = ui.current_buffer.get_selected_thread()
+ to_print = thread.get_messages().keys()
+ confirm_msg = 'print all messages in thread?'
+ ok_msg = 'printed thread: %s' % str(thread)
+ else:
+ to_print = [ui.current_buffer.get_selected_message()]
+ confirm_msg = 'print this message?'
+ ok_msg = 'printed message: %s' % str(to_print[0])
+
+ # ask for confirmation if needed
+ if self.confirm:
+ if not ui.choice(confirm_msg) == 'yes':
+ return
+
+ # prepare message sources
+ mailstrings = [m.get_email().as_string() for m in to_print]
+ if not self.separately:
+ mailstrings = ['\n\n'.join(mailstrings)]
+
+ # get print command
+ cmd = settings.config.get('general', 'print_cmd')
+ args = shlex.split(cmd.encode('ascii'))
+
+ # print
+ try:
+ for mail in mailstrings:
+ proc = subprocess.Popen(args, stdin=subprocess.PIPE,
+ stdout=subprocess.PIPE,
+ stderr=subprocess.PIPE)
+ out, err = proc.communicate(mail)
+ if proc.poll(): # returncode is not 0
+ raise OSError(err)
+ except OSError, e: # handle errors
+ ui.notify(str(e), priority='error')
+ return
+
+ # display 'done' message
+ ui.notify(ok_msg)
+
+
+
class SaveAttachmentCommand(Command):
def __init__(self, all=False, path=None, **kwargs):
Command.__init__(self, **kwargs)
@@ -940,6 +992,7 @@ COMMANDS = {
'groupreply': (ReplyCommand, {'groupreply': True}),
'forward': (ForwardCommand, {}),
'fold': (FoldMessagesCommand, {'visible': False}),
+ 'print': (PrintCommand, {}),
'unfold': (FoldMessagesCommand, {'visible': True}),
'select': (ThreadSelectCommand, {}),
'save': (SaveAttachmentCommand, {}),
@@ -1055,6 +1108,10 @@ def interpret_commandline(cmdline, mode):
filepath = os.path.expanduser(params)
if os.path.isfile(filepath):
return commandfactory(cmd, mode=mode, path=filepath)
+ elif cmd == 'print':
+ args = [a.strip() for a in params.split()]
+ return commandfactory(cmd, mode=mode, all=('--all' in args),
+ separately=('--separately' in args))
elif not params and cmd in ['exit', 'flush', 'pyshell', 'taglist',
'bclose', 'compose', 'openfocussed',
diff --git a/alot/settings.py b/alot/settings.py
index 5a6e992a..ef3babff 100644
--- a/alot/settings.py
+++ b/alot/settings.py
@@ -41,6 +41,7 @@ DEFAULTS = {
'hooksfile': '~/.alot.py',
'bug_on_exit': 'False',
'timestamp_format': '',
+ 'print_cmd': 'muttprint',
},
'16c-theme': {
'bufferlist_focus_bg': 'dark gray',
@@ -242,10 +243,12 @@ DEFAULTS = {
'C': 'fold --all',
'E': 'unfold --all',
'H': 'toggleheaders',
+ 'P': 'print --all',
'a': 'toggletag inbox',
'enter': 'select',
'f': 'forward',
'g': 'groupreply',
+ 'p': 'print',
'r': 'reply',
},
'taglist-maps': {
diff --git a/data/example.full.rc b/data/example.full.rc
index 38577d00..71ae8301 100644
--- a/data/example.full.rc
+++ b/data/example.full.rc
@@ -44,6 +44,9 @@ terminal_cmd = x-terminal-emulator -e
# http://docs.python.org/library/datetime.html#strftime-strptime-behavior
timestamp_format = ''
+#how to print messages:
+print_cmd = muttprint
+
[global-maps]
$ = flush
@@ -88,10 +91,12 @@ enter = select
C = fold --all
E = unfold --all
H = toggleheaders
+P = print --all
a = toggletag inbox
enter = select
f = forward
g = groupreply
+p = print
r = reply
[command-aliases]