summaryrefslogtreecommitdiff
path: root/memoryhole/protection.py
diff options
context:
space:
mode:
authorRuben Pollan <meskio@sindominio.net>2016-07-06 15:59:10 +0200
committerRuben Pollan <meskio@sindominio.net>2016-07-06 15:59:10 +0200
commitc0ae8b109a21fad1c2ff56db0768c16b78f6a5f7 (patch)
treef05e2e0951a5e8d8a904e3c4e6cd77229f6fd2f9 /memoryhole/protection.py
parent2bf3ef57a1f2841116268010cd80984208725f45 (diff)
[feat] discover encr and sign address
Diffstat (limited to 'memoryhole/protection.py')
-rw-r--r--memoryhole/protection.py17
1 files changed, 15 insertions, 2 deletions
diff --git a/memoryhole/protection.py b/memoryhole/protection.py
index b179614..b064f47 100644
--- a/memoryhole/protection.py
+++ b/memoryhole/protection.py
@@ -30,13 +30,14 @@ def protect(msg, openpgp=Gnupg(), encrypt=True, obscure=True):
def _encrypt_mime(msg, openpgp):
+ encraddr = _recipient_addresses(msg)
+ signaddr = _from_address(msg)
+
newmsg = MultipartEncrypted('application/pgp-encrypted')
for hkey, hval in msg.items():
newmsg.add_header(hkey, hval)
del(msg[hkey])
- encraddr = "" # TODO
- signaddr = "" # TODO
encstr = openpgp.encrypt(msg.as_string(unixfrom=False),
encraddr, signaddr)
encmsg = MIMEApplication(
@@ -51,3 +52,15 @@ def _encrypt_mime(msg, openpgp):
newmsg.attach(metamsg)
newmsg.attach(encmsg)
return newmsg
+
+
+def _recipient_addresses(msg):
+ recipients = []
+ for header in ('to', 'cc', 'bcc'):
+ recipients += msg.get_all(header, [])
+ return [r[1] for r in getaddresses(recipients)]
+
+
+def _from_address(msg):
+ frm = msg.get_all('From', [])
+ return parseaddr(frm)[1]