comparison roundup/mailer.py @ 6963:3cd43c34c095

flake8 fixes.
author John Rouillard <rouilj@ieee.org>
date Mon, 12 Sep 2022 23:50:25 -0400
parents 087cae2fbcea
children d7e79f8eb943
comparison
equal deleted inserted replaced
6962:ff879aa00987 6963:3cd43c34c095
1 """Sending Roundup-specific mail over SMTP. 1 """Sending Roundup-specific mail over SMTP.
2 """ 2 """
3 __docformat__ = 'restructuredtext' 3 __docformat__ = 'restructuredtext'
4 4
5 import time, os, socket, smtplib, sys, traceback, logging 5 import logging
6 6 import os
7 from roundup import __version__ 7 import smtplib
8 from roundup.date import get_timezone, Date 8 import socket
9 import sys
10 import time
11 import traceback
9 12
10 from email import charset 13 from email import charset
11 from email.utils import formatdate, specialsre, escapesre
12 from email.charset import Charset 14 from email.charset import Charset
13 from email.header import Header 15 from email.header import Header
14 from email.mime.base import MIMEBase 16 from email.mime.base import MIMEBase
15 from email.mime.text import MIMEText
16 from email.mime.multipart import MIMEMultipart 17 from email.mime.multipart import MIMEMultipart
17 from email.mime.nonmultipart import MIMENonMultipart 18 from email.mime.nonmultipart import MIMENonMultipart
18 19 from email.mime.text import MIMEText
19 from roundup.anypy import email_ 20 from email.utils import formatdate, specialsre, escapesre
21
22 from roundup.anypy import email_ # noqa: F401 defines functions
20 from roundup.anypy.strings import b2s, s2u 23 from roundup.anypy.strings import b2s, s2u
24 from roundup import __version__
25 from roundup.date import get_timezone, Date
21 26
22 try: 27 try:
23 import gpg, gpg.core 28 import gpg, gpg.core # noqa: E401
24 except ImportError: 29 except ImportError:
25 gpg = None 30 gpg = None
26 31
27 32
28 class MessageSendError(RuntimeError): 33 class MessageSendError(RuntimeError):
169 if crypt: 174 if crypt:
170 crypt_to = to 175 crypt_to = to
171 to = None 176 to = None
172 # see whether we should send to the dispatcher or not 177 # see whether we should send to the dispatcher or not
173 dispatcher_email = getattr(self.config, "DISPATCHER_EMAIL", 178 dispatcher_email = getattr(self.config, "DISPATCHER_EMAIL",
174 getattr(self.config, "ADMIN_EMAIL")) 179 self.config.ADMIN_EMAIL)
175 error_messages_to = getattr(self.config, "ERROR_MESSAGES_TO", "user") 180 error_messages_to = getattr(self.config, "ERROR_MESSAGES_TO", "user")
176 if error_messages_to == "dispatcher": 181 if error_messages_to == "dispatcher":
177 to = [dispatcher_email] 182 to = [dispatcher_email]
178 crypt = False 183 crypt = False
179 crypt_to = None 184 crypt_to = None
278 # that resulting file can be openened in a mailer 283 # that resulting file can be openened in a mailer
279 fmt = '%a %b %m %H:%M:%S %Y' 284 fmt = '%a %b %m %H:%M:%S %Y'
280 unixfrm = 'From %s %s' % (sender, Date('.').pretty(fmt)) 285 unixfrm = 'From %s %s' % (sender, Date('.').pretty(fmt))
281 debug_fh = open(self.debug, 'a') 286 debug_fh = open(self.debug, 'a')
282 debug_fh.write('%s\nFROM: %s\nTO: %s\n%s\n\n' % 287 debug_fh.write('%s\nFROM: %s\nTO: %s\n%s\n\n' %
283 (unixfrm, sender, 288 (unixfrm, sender,
284 ', '.join(to), message)) 289 ', '.join(to), message))
285 debug_fh.close() 290 debug_fh.close()
286 else: 291 else:
287 # now try to send the message 292 # now try to send the message
288 try: 293 try:
289 # send the message as admin so bounces are sent there 294 # send the message as admin so bounces are sent there

Roundup Issue Tracker: http://roundup-tracker.org/