Skip to content

Commit d6b2636

Browse files
committed
flake8 fixes: fix typoed variable; remove unused imports; format fixes
fix typo: crypto_to type -> crypt_to other format fixes
1 parent a8b1f6f commit d6b2636

File tree

1 file changed

+23
-19
lines changed

1 file changed

+23
-19
lines changed

roundup/mailer.py

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,23 +2,22 @@
22
"""
33
__docformat__ = 'restructuredtext'
44

5-
import time, quopri, os, socket, smtplib, re, sys, traceback, email, logging
5+
import time, os, socket, smtplib, sys, traceback, logging
66

77
from roundup import __version__
88
from roundup.date import get_timezone, Date
99

1010
from email import charset
11-
from email.utils import formatdate, formataddr, specialsre, escapesre
11+
from email.utils import formatdate, specialsre, escapesre
1212
from email.charset import Charset
13-
from email.message import Message
1413
from email.header import Header
1514
from email.mime.base import MIMEBase
1615
from email.mime.text import MIMEText
1716
from email.mime.multipart import MIMEMultipart
1817
from email.mime.nonmultipart import MIMENonMultipart
1918

2019
from roundup.anypy import email_
21-
from roundup.anypy.strings import b2s, s2b, s2u
20+
from roundup.anypy.strings import b2s, s2u
2221

2322
try:
2423
import gpg, gpg.core
@@ -29,6 +28,7 @@
2928
class MessageSendError(RuntimeError):
3029
pass
3130

31+
3232
def nice_sender_header(name, address, charset):
3333
# construct an address header so it's as human-readable as possible
3434
# even in the presence of a non-ASCII name part
@@ -42,11 +42,12 @@ def nice_sender_header(name, address, charset):
4242

4343
# the important bits of formataddr()
4444
if specialsre.search(encname):
45-
encname = '"%s"'%escapesre.sub(r'\\\g<0>', encname)
45+
encname = '"%s"' % escapesre.sub(r'\\\g<0>', encname)
4646

4747
# now format the header as a string - don't return a Header as anonymous
4848
# headers play poorly with Messages (eg. won't get wrapped properly)
49-
return '%s <%s>'%(encname, address)
49+
return '%s <%s>' % (encname, address)
50+
5051

5152
class Mailer:
5253
"""Roundup-specific mail sending."""
@@ -127,7 +128,8 @@ def get_standard_message(self, multipart=False):
127128
if multipart:
128129
message = MIMEMultipart()
129130
else:
130-
message = self.get_text_message(getattr(self.config, 'EMAIL_CHARSET', 'utf-8'))
131+
message = self.get_text_message(getattr(self.config,
132+
'EMAIL_CHARSET', 'utf-8'))
131133

132134
return message
133135

@@ -169,7 +171,7 @@ def bounce_message(self, bounced_message, to, error,
169171
to = None
170172
# see whether we should send to the dispatcher or not
171173
dispatcher_email = getattr(self.config, "DISPATCHER_EMAIL",
172-
getattr(self.config, "ADMIN_EMAIL"))
174+
getattr(self.config, "ADMIN_EMAIL"))
173175
error_messages_to = getattr(self.config, "ERROR_MESSAGES_TO", "user")
174176
if error_messages_to == "dispatcher":
175177
to = [dispatcher_email]
@@ -227,18 +229,19 @@ def bounce_message(self, bounced_message, to, error,
227229
if crypt_to:
228230
try:
229231
ctx.op_encrypt(keys, 1, plain, cipher)
230-
cipher.seek(0,0)
231-
message=MIMEMultipart('encrypted', boundary=None,
232-
_subparts=None, protocol="application/pgp-encrypted")
233-
part=MIMEBase('application', 'pgp-encrypted')
232+
cipher.seek(0, 0)
233+
message = MIMEMultipart('encrypted', boundary=None,
234+
_subparts=None,
235+
protocol="application/pgp-encrypted")
236+
part = MIMEBase('application', 'pgp-encrypted')
234237
part.set_payload("Version: 1\r\n")
235238
message.attach(part)
236-
part=MIMEBase('application', 'octet-stream')
239+
part = MIMEBase('application', 'octet-stream')
237240
part.set_payload(cipher.read())
238241
message.attach(part)
239242
except gpg.GPGMEError:
240243
self.logger.debug("bounce_message: Cannot encrypt to %s",
241-
str(crypto_to))
244+
str(crypt_to))
242245
crypt_to = None
243246
if crypt_to:
244247
self.set_message_attributes(message, crypt_to, subject)
@@ -253,7 +256,7 @@ def exception_message(self):
253256
'''Send a message to the admins with information about the latest
254257
traceback.
255258
'''
256-
subject = '%s: %s'%(self.config.TRACKER_NAME, sys.exc_info()[1])
259+
subject = '%s: %s' % (self.config.TRACKER_NAME, sys.exc_info()[1])
257260
to = [self.config.ADMIN_EMAIL]
258261
content = '\n'.join(traceback.format_exception(*sys.exc_info()))
259262
self.standard_message(to, subject, content)
@@ -274,7 +277,7 @@ def smtp_send(self, to, message, sender=None):
274277
# don't send - just write to a file, use unix from line so
275278
# that resulting file can be openened in a mailer
276279
fmt = '%a %b %m %H:%M:%S %Y'
277-
unixfrm = 'From %s %s' % (sender, Date ('.').pretty (fmt))
280+
unixfrm = 'From %s %s' % (sender, Date('.').pretty(fmt))
278281
open(self.debug, 'a').write('%s\nFROM: %s\nTO: %s\n%s\n\n' %
279282
(unixfrm, sender,
280283
', '.join(to), message))
@@ -287,9 +290,10 @@ def smtp_send(self, to, message, sender=None):
287290
smtp.sendmail(sender, to, message)
288291
except socket.error as value:
289292
raise MessageSendError("Error: couldn't send email: "
290-
"mailhost %s"%value)
293+
"mailhost %s" % value)
291294
except smtplib.SMTPException as msg:
292-
raise MessageSendError("Error: couldn't send email: %s"%msg)
295+
raise MessageSendError("Error: couldn't send email: %s" % msg)
296+
293297

294298
class SMTPConnection(smtplib.SMTP):
295299
''' Open an SMTP connection to the mailhost specified in the config
@@ -302,7 +306,7 @@ def __init__(self, config):
302306
if config["MAIL_TLS"]:
303307
self.ehlo()
304308
self.starttls(config["MAIL_TLS_KEYFILE"],
305-
config["MAIL_TLS_CERTFILE"])
309+
config["MAIL_TLS_CERTFILE"])
306310

307311
# ok, now do we also need to log in?
308312
mailuser = config["MAIL_USERNAME"]

0 commit comments

Comments
 (0)