Mercurial > p > roundup > code
comparison roundup/mailer.py @ 5494:b7fa56ced601
use gpg module instead of pyme module for PGP encryption
| author | Christof Meerwald <cmeerw@cmeerw.org> |
|---|---|
| date | Sun, 12 Aug 2018 16:17:14 +0100 |
| parents | 725266c03eab |
| children | bd245858c823 |
comparison
equal
deleted
inserted
replaced
| 5493:725266c03eab | 5494:b7fa56ced601 |
|---|---|
| 19 | 19 |
| 20 from roundup.anypy import email_ | 20 from roundup.anypy import email_ |
| 21 from roundup.anypy.strings import b2s, s2b, s2u | 21 from roundup.anypy.strings import b2s, s2b, s2u |
| 22 | 22 |
| 23 try: | 23 try: |
| 24 import pyme, pyme.core | 24 import gpg, gpg.core |
| 25 except ImportError: | 25 except ImportError: |
| 26 pyme = None | 26 gpg = None |
| 27 | 27 |
| 28 | 28 |
| 29 class MessageSendError(RuntimeError): | 29 class MessageSendError(RuntimeError): |
| 30 pass | 30 pass |
| 31 | 31 |
| 203 # problem (even though the vast majority of bounce errors are | 203 # problem (even though the vast majority of bounce errors are |
| 204 # because of spam) | 204 # because of spam) |
| 205 self.logger.debug("MessageSendError: %s", str(e)) | 205 self.logger.debug("MessageSendError: %s", str(e)) |
| 206 pass | 206 pass |
| 207 if crypt_to: | 207 if crypt_to: |
| 208 plain = pyme.core.Data(message.as_string()) | 208 plain = gpg.core.Data(message.as_string()) |
| 209 cipher = pyme.core.Data() | 209 cipher = gpg.core.Data() |
| 210 ctx = pyme.core.Context() | 210 ctx = gpg.core.Context() |
| 211 ctx.set_armor(1) | 211 ctx.set_armor(1) |
| 212 keys = [] | 212 keys = [] |
| 213 adrs = [] | 213 adrs = [] |
| 214 for adr in crypt_to: | 214 for adr in crypt_to: |
| 215 ctx.op_keylist_start(adr, 0) | 215 ctx.op_keylist_start(adr, 0) |
| 233 part.set_payload("Version: 1\r\n") | 233 part.set_payload("Version: 1\r\n") |
| 234 message.attach(part) | 234 message.attach(part) |
| 235 part=MIMEBase('application', 'octet-stream') | 235 part=MIMEBase('application', 'octet-stream') |
| 236 part.set_payload(cipher.read()) | 236 part.set_payload(cipher.read()) |
| 237 message.attach(part) | 237 message.attach(part) |
| 238 except pyme.GPGMEError: | 238 except gpg.GPGMEError: |
| 239 self.logger.debug("bounce_message: Cannot encrypt to %s", | 239 self.logger.debug("bounce_message: Cannot encrypt to %s", |
| 240 str(crypto_to)) | 240 str(crypto_to)) |
| 241 crypt_to = None | 241 crypt_to = None |
| 242 if crypt_to: | 242 if crypt_to: |
| 243 self.set_message_attributes(message, crypt_to, subject) | 243 self.set_message_attributes(message, crypt_to, subject) |
