Skip to content

Commit

Permalink
print command for thread view bound to p and P
Browse files Browse the repository at this point in the history
  • Loading branch information
pazz committed Aug 27, 2011
1 parent cfb2c87 commit 8014a37
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 1 deletion.
1 change: 1 addition & 0 deletions NEWS
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions USAGE
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
57 changes: 57 additions & 0 deletions alot/command.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import logging
import threading
import subprocess
import shlex
import email
import tempfile
import mimetypes
Expand Down Expand Up @@ -651,6 +652,57 @@ def apply(self, ui):
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)
Expand Down Expand Up @@ -940,6 +992,7 @@ def apply(self, ui):
'groupreply': (ReplyCommand, {'groupreply': True}),
'forward': (ForwardCommand, {}),
'fold': (FoldMessagesCommand, {'visible': False}),
'print': (PrintCommand, {}),
'unfold': (FoldMessagesCommand, {'visible': True}),
'select': (ThreadSelectCommand, {}),
'save': (SaveAttachmentCommand, {}),
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 3 additions & 0 deletions alot/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
'hooksfile': '~/.alot.py',
'bug_on_exit': 'False',
'timestamp_format': '',
'print_cmd': 'muttprint',
},
'16c-theme': {
'bufferlist_focus_bg': 'dark gray',
Expand Down Expand Up @@ -242,10 +243,12 @@
'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': {
Expand Down
5 changes: 5 additions & 0 deletions data/example.full.rc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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]
Expand Down

0 comments on commit 8014a37

Please sign in to comment.