diff options
author | Patrick Totzke <patricktotzke@gmail.com> | 2011-08-20 16:03:49 +0100 |
---|---|---|
committer | Patrick Totzke <patricktotzke@gmail.com> | 2011-08-20 16:03:49 +0100 |
commit | 744e86bbaa5f521908100f4fd3c8b8fc43a894f4 (patch) | |
tree | 1c2b7406f2b916c10d7fbc41b53bd2c93a39e471 /alot/command.py | |
parent | 7e17485e77441d0d9c27f77ff7d06c91c6e80a67 (diff) | |
parent | e6d68139f063c48a0b1cf29dfbe012e460b31ce8 (diff) |
Merge branch 'develop' into addressbook
Conflicts:
alot/account.py
alot/command.py
Diffstat (limited to 'alot/command.py')
-rw-r--r-- | alot/command.py | 77 |
1 files changed, 36 insertions, 41 deletions
diff --git a/alot/command.py b/alot/command.py index 28667770..8deea288 100644 --- a/alot/command.py +++ b/alot/command.py @@ -17,8 +17,8 @@ along with notmuch. If not, see <http://www.gnu.org/licenses/>. Copyright (C) 2011 Patrick Totzke <patricktotzke@gmail.com> """ import os -import glob import code +import glob import logging import threading import subprocess @@ -28,11 +28,7 @@ import mimetypes from email.parser import Parser from email import Charset from email.header import Header -from email import encoders from email.message import Message -from email.mime.audio import MIMEAudio -from email.mime.base import MIMEBase -from email.mime.image import MIMEImage from email.mime.text import MIMEText from email.mime.multipart import MIMEMultipart import urwid @@ -41,6 +37,7 @@ import buffer import settings import widgets import completion +import helper from db import DatabaseROError from db import DatabaseLockedError from completion import ContactsCompleter @@ -369,7 +366,7 @@ class ComposeCommand(Command): cmpl = AccountCompleter(ui.accountman) fromaddress = ui.prompt(prefix='From>', completer=cmpl, tab=1) validaddresses = [a.address for a in accounts] + [None] - while fromaddress not in validaddresses: + while fromaddress not in validaddresses: # TODO: not cool ui.notify('no account for this address. (<esc> cancels)') fromaddress = ui.prompt(prefix='From>', completer=cmpl) if not fromaddress: @@ -382,10 +379,16 @@ class ComposeCommand(Command): if 'To' not in self.mail: to = ui.prompt(prefix='To>', completer=ContactsCompleter(ui.accountman)) + if to == None: + ui.notify('canceled') + return self.mail['To'] = encode_header('to', to) if settings.config.getboolean('general', 'ask_subject') and \ not 'Subject' in self.mail: subject = ui.prompt(prefix='Subject>') + if subject == None: + ui.notify('canceled') + return self.mail['Subject'] = encode_header('subject', subject) ui.apply_command(EnvelopeEditCommand(mail=self.mail)) @@ -754,7 +757,8 @@ class EnvelopeEditCommand(Command): def openEnvelopeFromTmpfile(): f = open(tf.name) - editor_input = f.read().decode('utf-8') + enc = settings.config.get('general', 'editor_writes_encoding') + editor_input = f.read().decode(enc) #split editor out headertext, bodytext = editor_input.split('\n\n', 1) @@ -835,6 +839,21 @@ class EnvelopeSendCommand(Command): sname, saddr = email.Utils.parseaddr(frm) account = ui.accountman.get_account_by_address(saddr) if account: + # attach signature file if present + if account.signature: + sig = os.path.expanduser(account.signature) + if os.path.isfile(sig): + if account.signature_filename: + name = account.signature_filename + else: + name = None + helper.attach(sig, mail, filename=name) + else: + ui.notify('could not locate signature: %s' % sig, + priority='error') + if not ui.choice('send without signature') == 'yes': + return + clearme = ui.notify('sending..', timeout=-1, block=False) reason = account.send_mail(mail) ui.clear_notify([clearme]) @@ -850,11 +869,12 @@ class EnvelopeSendCommand(Command): class EnvelopeAttachCommand(Command): - def __init__(self, path=None, **kwargs): + def __init__(self, path=None, mail=None, **kwargs): Command.__init__(self, **kwargs) self.files = [] if path: self.files = glob.glob(os.path.expanduser(path)) + self.mail = mail def apply(self, ui): if not self.files: @@ -866,40 +886,15 @@ class EnvelopeAttachCommand(Command): ui.notify('no matches, abort') return logging.info(self.files) - msg = ui.current_buffer.get_email() + + msg = self.mail + if not msg: + msg = ui.current_buffer.get_email() for path in self.files: - ctype, encoding = mimetypes.guess_type(path) - if ctype is None or encoding is not None: - # No guess could be made, or the file is encoded (compressed), - # so use a generic bag-of-bits type. - ctype = 'application/octet-stream' - maintype, subtype = ctype.split('/', 1) - if maintype == 'text': - fp = open(path) - # Note: we should handle calculating the charset - part = MIMEText(fp.read(), _subtype=subtype) - fp.close() - elif maintype == 'image': - fp = open(path, 'rb') - part = MIMEImage(fp.read(), _subtype=subtype) - fp.close() - elif maintype == 'audio': - fp = open(path, 'rb') - part = MIMEAudio(fp.read(), _subtype=subtype) - fp.close() - else: - fp = open(path, 'rb') - part = MIMEBase(maintype, subtype) - part.set_payload(fp.read()) - fp.close() - # Encode the payload using Base64 - encoders.encode_base64(part) - # Set the filename parameter - part.add_header('Content-Disposition', 'attachment', - filename=os.path.basename(path)) - msg.attach(part) - - ui.current_buffer.set_email(msg) + helper.attach(path, msg) + + if not self.mail: # set the envelope msg iff we got it from there + ui.current_buffer.set_email(msg) # TAGLIST |