diff options
author | Michael Stapelberg <michael@stapelberg.de> | 2012-04-23 23:07:40 +0200 |
---|---|---|
committer | Michael Stapelberg <michael@stapelberg.de> | 2012-04-23 23:07:40 +0200 |
commit | 31a0194e1629815ab6553aca3b7bb77e8c050158 (patch) | |
tree | f872b0624e1648575e984cd94c5823ddc19dd307 /alot | |
parent | 98a4dd699ef5eee274c001752e994591526c6d5f (diff) |
Properly handle GPG errors
Diffstat (limited to 'alot')
-rw-r--r-- | alot/commands/envelope.py | 8 | ||||
-rw-r--r-- | alot/db/__init__.py | 5 | ||||
-rw-r--r-- | alot/db/envelope.py | 18 |
3 files changed, 24 insertions, 7 deletions
diff --git a/alot/commands/envelope.py b/alot/commands/envelope.py index 06d83e9e..79c27b0d 100644 --- a/alot/commands/envelope.py +++ b/alot/commands/envelope.py @@ -8,6 +8,7 @@ from twisted.internet.defer import inlineCallbacks import datetime from alot.account import SendingMailFailed +from alot.db import ConstructMailError from alot import buffers from alot import commands from alot.commands import Command, registerCommand @@ -133,9 +134,10 @@ class SendCommand(Command): # send clearme = ui.notify('sending..', timeout=-1) - mail = envelope.construct_mail(ui) - - if mail is None: + try: + mail = envelope.construct_mail() + except ConstructMailError, e: + ui.notify(e.message, priority='error') return def afterwards(returnvalue): diff --git a/alot/db/__init__.py b/alot/db/__init__.py index c6a83064..f8094706 100644 --- a/alot/db/__init__.py +++ b/alot/db/__init__.py @@ -333,3 +333,8 @@ class DBManager(object): raise errors.DatabaseROError() path = message.get_filename() self.writequeue.append(('remove', afterwards, path)) + + +class ConstructMailError(Exception): + """could not construct mail (GPG problem?)""" + pass diff --git a/alot/db/envelope.py b/alot/db/envelope.py index 54d5b3f0..393d5985 100644 --- a/alot/db/envelope.py +++ b/alot/db/envelope.py @@ -17,6 +17,7 @@ import logging import alot.helper as helper import alot.crypto as crypto from alot.settings import settings +from alot.db import ConstructMailError from attachment import Attachment from utils import encode_header @@ -135,7 +136,7 @@ class Envelope(object): if self.sent_time: self.modified_since_sent = True - def construct_mail(self, ui): + def construct_mail(self): """ compiles the information contained in this envelope into a :class:`email.Message`. @@ -165,10 +166,19 @@ class Envelope(object): try: result, signature_str = context.detached_signature_for(plaintext) if len(result.signatures) != 1: - return None + raise ConstructMailError(("Could not sign message " + "(GPGME did not return a signature)")) except pyme.errors.GPGMEError as e: - ui.notify('GPG Error: ' + str(e), priority='error') - return None + # 11 == GPG_ERR_BAD_PASSPHRASE + if e.getcode() == 11: + if not os.environ['GPG_AGENT_INFO']: + raise ConstructMailError(("Bad passphrase and " + "GPG_AGENT_INFO not set. Please setup " + "gpg-agent.")) + else: + raise ConstructMailError(("Bad passphrase. Is " + "gpg-agent running?")) + raise ConstructMailError(str(e)) micalg = crypto.RFC3156_micalg_from_result(result) outer_msg = MIMEMultipart('signed', micalg=micalg, |