summaryrefslogtreecommitdiff
path: root/alot
diff options
context:
space:
mode:
authorMichael Stapelberg <michael@stapelberg.de>2012-05-11 23:09:51 +0200
committerMichael Stapelberg <michael@stapelberg.de>2012-05-11 23:24:49 +0200
commit30f484341070ac7905c8f82a1ee85fcc2d964afa (patch)
tree63cbeafbe9bafcc844793141231e8998d1576b1c /alot
parent9bcd918748f9d83e688833814c488bce05e41922 (diff)
add sign_by_default account setting to enable GPG signatures by default, use existing gpg_key setting
Diffstat (limited to 'alot')
-rw-r--r--alot/account.py3
-rw-r--r--alot/commands/globals.py10
-rw-r--r--alot/commands/thread.py12
-rw-r--r--alot/db/envelope.py19
4 files changed, 39 insertions, 5 deletions
diff --git a/alot/account.py b/alot/account.py
index 7549a705..b65bf3cb 100644
--- a/alot/account.py
+++ b/alot/account.py
@@ -48,7 +48,7 @@ class Account(object):
gpg_key=None, signature=None, signature_filename=None,
signature_as_attachment=False, sent_box=None,
sent_tags=['sent'], draft_box=None, draft_tags=['draft'],
- abook=None, **rest):
+ abook=None, sign_by_default=False, **rest):
self.address = address
self.aliases = aliases
self.realname = realname
@@ -56,6 +56,7 @@ class Account(object):
self.signature = signature
self.signature_filename = signature_filename
self.signature_as_attachment = signature_as_attachment
+ self.sign_by_default = sign_by_default
self.sent_box = sent_box
self.sent_tags = sent_tags
self.draft_box = draft_box
diff --git a/alot/commands/globals.py b/alot/commands/globals.py
index f99aec25..32af400d 100644
--- a/alot/commands/globals.py
+++ b/alot/commands/globals.py
@@ -594,12 +594,14 @@ class ComposeCommand(Command):
select='yes', cancel='no')) == 'no':
return
+ # Figure out whether we should GPG sign messages by default
+ sender = self.envelope.get('From')
+ name, addr = email.Utils.parseaddr(sender)
+ account = settings.get_account_by_address(addr)
+ self.envelope.apply_account_crypto_settings(account, ui)
+
# get missing To header
if 'To' not in self.envelope.headers:
- sender = self.envelope.get('From')
- name, addr = email.Utils.parseaddr(sender)
- account = settings.get_account_by_address(addr)
-
allbooks = not settings.get('complete_matching_abook_only')
logging.debug(allbooks)
if account is not None:
diff --git a/alot/commands/thread.py b/alot/commands/thread.py
index 45734b21..ba6400e2 100644
--- a/alot/commands/thread.py
+++ b/alot/commands/thread.py
@@ -122,6 +122,10 @@ class ReplyCommand(Command):
realname, address = recipient_to_from(mail, my_accounts)
envelope.add('From', '%s <%s>' % (realname, address))
+ # set GPG sign from the account default setting
+ account = settings.get_account_by_address(address)
+ envelope.apply_account_crypto_settings(account, ui)
+
# set To
sender = mail['Reply-To'] or mail['From']
recipients = [sender]
@@ -232,6 +236,10 @@ class ForwardCommand(Command):
realname, address = recipient_to_from(mail, my_accounts)
envelope.add('From', '%s <%s>' % (realname, address))
+ # set GPG sign from the account default setting
+ account = settings.get_account_by_address(address)
+ envelope.apply_account_crypto_settings(account, ui)
+
# continue to compose
ui.apply_command(ComposeCommand(envelope=envelope,
spawn=self.force_spawn))
@@ -262,6 +270,10 @@ class EditNewCommand(Command):
mailcontent = self.message.accumulate_body()
envelope = Envelope(bodytext=mailcontent)
+ # set GPG sign from the account default setting
+ account = settings.get_account_by_address(address)
+ envelope.apply_account_crypto_settings(account, ui)
+
# copy selected headers
to_copy = ['Subject', 'From', 'To', 'Cc', 'Bcc', 'In-Reply-To',
'References']
diff --git a/alot/db/envelope.py b/alot/db/envelope.py
index 9d8e2599..f75e9dd1 100644
--- a/alot/db/envelope.py
+++ b/alot/db/envelope.py
@@ -137,6 +137,25 @@ class Envelope(object):
if self.sent_time:
self.modified_since_sent = True
+ def apply_account_crypto_settings(self, account, ui):
+ """
+ initializes sign and sign_key from the account settings.
+ """
+ if account is None:
+ return
+
+ self.sign = account.sign_by_default
+
+ if account.gpg_key is None:
+ return
+
+ try:
+ key = crypto.CryptoContext().get_key(str(account.gpg_key))
+ except GPGProblem, e:
+ ui.notify(e.message, priority='error')
+ return
+ self.sign_key = key
+
def construct_mail(self):
"""
compiles the information contained in this envelope into a