Skip to content

Commit 4fa0384

Browse files
committed
python3 fixes
1 parent 8df31c3 commit 4fa0384

10 files changed

Lines changed: 51 additions & 46 deletions

File tree

Mailman/Archiver/HyperArch.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ def decode_headers(self):
419419
i18n.set_language(self._lang)
420420
atmark = _(' at ')
421421
subject = re.sub(r'([-+,.\w]+)@([-+.\w]+)',
422-
'\g<1>' + atmark + '\g<2>', subject)
422+
r'\g<1>' + atmark + r'\g<2>', subject)
423423
finally:
424424
i18n.set_translation(otrans)
425425
self.decoded['subject'] = subject
@@ -436,10 +436,10 @@ def strip_subject(self, subject):
436436
subject = re.sub(prefix_pat, '', subject)
437437
subject = subject.lstrip()
438438
# MAS Should we strip FW and FWD too?
439-
strip_pat = re.compile('^((RE|AW|SV|VS)(\[\d+\])?:\s*)+', re.I)
439+
strip_pat = re.compile(r'^((RE|AW|SV|VS)(\[\d+\])?:\s*)+', re.I)
440440
stripped = strip_pat.sub('', subject)
441441
# Also remove whitespace to avoid folding/unfolding differences
442-
stripped = re.sub('\s', '', stripped)
442+
stripped = re.sub(r'\s', '', stripped)
443443
return stripped
444444

445445
def decode_charset(self, field):
@@ -589,7 +589,7 @@ def as_text(self):
589589
if isinstance(atmark, bytes):
590590
atmark = str(atmark, cset)
591591
body = re.sub(r'([-+,.\w]+)@([-+.\w]+)',
592-
'\g<1>' + atmark + '\g<2>', body)
592+
r'\g<1>' + atmark + r'\g<2>', body)
593593
finally:
594594
i18n.set_translation(otrans)
595595

Mailman/Bouncers/SimpleMatch.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,11 @@ def _c(pattern):
4949
# robanal.demon.co.uk
5050
(_c('this message was created automatically by mail delivery software'),
5151
_c('original message follows'),
52-
_c('rcpt to:\s*<(?P<addr>[^>]*)>')),
52+
_c(r'rcpt to:\s*<(?P<addr>[^>]*)>')),
5353
# s1.com (InterScan E-Mail VirusWall NT ???)
5454
(_c('message from interscan e-mail viruswall nt'),
5555
_c('end of message'),
56-
_c('rcpt to:\s*<(?P<addr>[^>]*)>')),
56+
_c(r'rcpt to:\s*<(?P<addr>[^>]*)>')),
5757
# Smail
5858
(_c('failed addresses follow:'),
5959
_c('message text follows:'),
@@ -65,35 +65,35 @@ def _c(pattern):
6565
# turbosport.com runs something called `MDaemon 3.5.2' ???
6666
(_c('The following addresses did NOT receive a copy of your message:'),
6767
_c('--- Session Transcript ---'),
68-
_c('[>]\s*(?P<addr>.*)$')),
68+
_c(r'[>]\s*(?P<addr>.*)$')),
6969
# usa.net
70-
(_c('Intended recipient:\s*(?P<addr>.*)$'),
70+
(_c(r'Intended recipient:\s*(?P<addr>.*)$'),
7171
_c('--------RETURNED MAIL FOLLOWS--------'),
72-
_c('Intended recipient:\s*(?P<addr>.*)$')),
72+
_c(r'Intended recipient:\s*(?P<addr>.*)$')),
7373
# hotpop.com
74-
(_c('Undeliverable Address:\s*(?P<addr>.*)$'),
74+
(_c(r'Undeliverable Address:\s*(?P<addr>.*)$'),
7575
_c('Original message attached'),
76-
_c('Undeliverable Address:\s*(?P<addr>.*)$')),
76+
_c(r'Undeliverable Address:\s*(?P<addr>.*)$')),
7777
# Another demon.co.uk format
7878
(_c('This message was created automatically by mail delivery'),
7979
_c('^---- START OF RETURNED MESSAGE ----'),
8080
_c("addressed to '(?P<addr>[^']*)'")),
8181
# Prodigy.net full mailbox
8282
(_c("User's mailbox is full:"),
8383
_c('Unable to deliver mail.'),
84-
_c("User's mailbox is full:\s*<(?P<addr>[^>]*)>")),
84+
_c(r"User's mailbox is full:\s*<(?P<addr>[^>]*)>")),
8585
# Microsoft SMTPSVC
8686
(_c('The email below could not be delivered to the following user:'),
8787
_c('Old message:'),
8888
_c('<(?P<addr>[^>]*)>')),
8989
# Yahoo on behalf of other domains like sbcglobal.net
90-
(_c('Unable to deliver message to the following address\(es\)\.'),
91-
_c('--- Original message follows\.'),
90+
(_c(r'Unable to deliver message to the following address\(es\)\.'),
91+
_c(r'--- Original message follows\.'),
9292
_c('<(?P<addr>[^>]*)>:')),
9393
# googlemail.com
9494
(_c('Delivery to the following recipient(s)? failed'),
9595
_c('----- Original message -----'),
96-
_c('^\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
96+
_c(r'^\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
9797
# kundenserver.de, mxlogic.net
9898
(_c('A message that you( have)? sent could not be delivered'),
9999
_c('^---'),
@@ -108,39 +108,39 @@ def _c(pattern):
108108
# unique to stop on, so stop on the first line of at least 3 characters
109109
# that doesn't start with 'D' (to not stop immediately) and has no '@'.
110110
_c('^[^D][^@]{2,}$'),
111-
_c('^\s*(. )?(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
111+
_c(r'^\s*(. )?(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
112112
# and another thehartfod.com/hartfordlife.com
113-
(_c('^Your message\s*$'),
113+
(_c(r'^Your message\s*$'),
114114
_c('^because:'),
115-
_c('^\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
115+
_c(r'^\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
116116
# kviv.be (InterScan NT)
117117
(_c('^Unable to deliver message to'),
118118
_c(r'\*+\s+End of message\s+\*+'),
119119
_c('<(?P<addr>[^>]*)>')),
120120
# earthlink.net supported domains
121121
(_c('^Sorry, unable to deliver your message to'),
122122
_c('^A copy of the original message'),
123-
_c('\s*(?P<addr>[^\s@]+@[^\s@]+)\s+')),
123+
_c(r'\s*(?P<addr>[^\s@]+@[^\s@]+)\s+')),
124124
# ademe.fr
125125
(_c('^A message could not be delivered to:'),
126126
_c('^Subject:'),
127-
_c('^\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
127+
_c(r'^\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
128128
# andrew.ac.jp
129129
(_c('^Invalid final delivery userid:'),
130130
_c('^Original message follows.'),
131-
_c('\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
131+
_c(r'\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
132132
# E500_SMTP_Mail_Service@lerctr.org and similar
133133
(_c('---- Failed Recipients ----'),
134134
_c(' Mail ----'),
135135
_c('<(?P<addr>[^>]*)>')),
136136
# cynergycom.net
137137
(_c('A message that you sent could not be delivered'),
138138
_c('^---'),
139-
_c('(?P<addr>[^\s@]+@[^\s@)]+)')),
139+
_c(r'(?P<addr>[^\s@]+@[^\s@)]+)')),
140140
# LSMTP for Windows
141-
(_c('^--> Error description:\s*$'),
141+
(_c(r'^--> Error description:\s*$'),
142142
_c('^Error-End:'),
143-
_c('^Error-for:\s+(?P<addr>[^\s@]+@[^\s@]+)')),
143+
_c(r'^Error-for:\s+(?P<addr>[^\s@]+@[^\s@]+)')),
144144
# Qmail with a tri-language intro beginning in spanish
145145
(_c('Your message could not be delivered'),
146146
_c('^-'),
@@ -152,49 +152,49 @@ def _c(pattern):
152152
# dadoservice.it
153153
(_c('Your message has encountered delivery problems'),
154154
_c('Your message reads'),
155-
_c('addressed to\s*(?P<addr>[^\s@]+@[^\s@)]+)')),
155+
_c(r'addressed to\s*(?P<addr>[^\s@]+@[^\s@)]+)')),
156156
# gomaps.com
157157
(_c('Did not reach the following recipient'),
158158
_c('^\s*$'),
159-
_c('\s(?P<addr>[^\s@]+@[^\s@]+)')),
159+
_c(r'\s(?P<addr>[^\s@]+@[^\s@]+)')),
160160
# EYOU MTA SYSTEM
161161
(_c('This is the deliver program at'),
162162
_c('^-'),
163163
_c('^(?P<addr>[^\s@]+@[^\s@<>]+)')),
164164
# A non-standard qmail at ieo.it
165165
(_c('this is the email server at'),
166166
_c('^-'),
167-
_c('\s(?P<addr>[^\s@]+@[^\s@]+)[\s,]')),
167+
_c(r'\s(?P<addr>[^\s@]+@[^\s@]+)[\s,]')),
168168
# pla.net.py (MDaemon.PRO ?)
169169
(_c('- no such user here'),
170170
_c('There is no user'),
171-
_c('^(?P<addr>[^\s@]+@[^\s@]+)\s')),
171+
_c(r'^(?P<addr>[^\s@]+@[^\s@]+)\s')),
172172
# fastdnsservers.com
173173
(_c('The following recipient.*could not be reached'),
174174
_c('bogus stop pattern'),
175-
_c('^(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
175+
_c(r'^(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
176176
# lttf.com
177177
(_c('Could not deliver message to'),
178178
_c('^\s*--'),
179-
_c('^Failed Recipient:\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
179+
_c(r'^Failed Recipient:\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
180180
# uci.edu
181181
(_c('--------Message not delivered'),
182182
_c('--------Error Detail'),
183-
_c('^\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
183+
_c(r'^\s*(?P<addr>[^\s@]+@[^\s@]+)\s*$')),
184184
# Dovecot LDA Over quota MDN (bogus - should be DSN).
185185
(_c('^Your message'),
186186
_c('^Reporting'),
187187
_c(
188-
'Your message to (?P<addr>[^\s@]+@[^\s@]+) was automatically rejected'
188+
r'Your message to (?P<addr>[^\s@]+@[^\s@]+) was automatically rejected'
189189
)),
190190
# mail.ru
191191
(_c('A message that you sent was rejected'),
192192
_c('This is a copy of your message'),
193-
_c('\s(?P<addr>[^\s@]+@[^\s@]+)')),
193+
_c(r'\s(?P<addr>[^\s@]+@[^\s@]+)')),
194194
# MailEnable
195195
(_c('Message could not be delivered to some recipients.'),
196196
_c('Message headers follow'),
197-
_c('Recipient: \[SMTP:(?P<addr>[^\s@]+@[^\s@]+)\]')),
197+
_c(r'Recipient: \[SMTP:(?P<addr>[^\s@]+@[^\s@]+)\]')),
198198
# This one is from Yahoo but dosen't fit the yahoo recognizer format
199199
(_c(r'wasn\'t able to deliver the following message'),
200200
_c(r'---Below this line is a copy of the message.'),

Mailman/Handlers/Approve.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ def process(mlist, msg, msgdata):
122122
# If we don't find the pattern in the decoded part, but we do
123123
# find it after stripping HTML tags, we don't know how to remove
124124
# it, so we just reject the post.
125-
pattern = name + ':(\xA0|\s|&nbsp;)*' + re.escape(passwd)
125+
pattern = name + r':(\xA0|\s|&nbsp;)*' + re.escape(passwd)
126126
for part in typed_subpart_iterator(msg, 'text'):
127127
if part is not None and part.get_payload() is not None:
128128
lines = part.get_payload(decode=True)

Mailman/Handlers/CookHeaders.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
COMMASPACE = ', '
3939
MAXLINELEN = 78
4040

41-
nonascii = re.compile('[^\s!-~]')
41+
nonascii = re.compile(r'[^\s!-~]')
4242

4343
def uheader(mlist, s, header_name=None, continuation_ws=' ', maxlinelen=None):
4444
# Get the charset to encode the string in. Then search if there is any
@@ -183,7 +183,7 @@ def process(mlist, msg, msgdata):
183183
uvia = str(via, lcs, errors='replace')
184184

185185
# Replace the dummy replacements.
186-
uvia = re.sub(u'%\(lrn\)s', ulrn, re.sub(u'%\(realname\)s', urn, uvia))
186+
uvia = re.sub(u'%\\(lrn\\)s', ulrn, re.sub(u'%\\(realname\\)s', urn, uvia))
187187
# And get an RFC 2047 encoded header string.
188188
dn = str(Header(uvia, lcs))
189189
change_header('From',
@@ -424,7 +424,7 @@ def prefix_subject(mlist, msg, msgdata):
424424
# leading space after stripping the prefix. It is not known what MUA would
425425
# create such a Subject:, but the issue was reported.
426426
rematch = re.match(
427-
'(\s*(RE|AW|SV|VS)\s*(\[\d+\])?\s*:\s*)+',
427+
r'(\s*(RE|AW|SV|VS)\s*(\[\d+\])?\s*:\s*)+',
428428
subject, re.I)
429429
if rematch:
430430
subject = subject[rematch.end():]

Mailman/Handlers/Decorate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def decorate(mlist, template, what, extradict=None):
210210
# `what' is just a descriptive phrase used in the log message
211211

212212
# If template is only whitespace, ignore it.
213-
if len(re.sub('\s', '', template)) == 0:
213+
if len(re.sub(r'\s', '', template)) == 0:
214214
return ''
215215

216216
# BAW: We've found too many situations where Python can be fooled into

Mailman/Handlers/SMTPDirect.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import time
3232
import socket
3333
import smtplib
34+
from smtplib import SMTPException
3435
from base64 import b64encode
3536

3637
from Mailman import mm_cfg
@@ -66,7 +67,11 @@ def __connect(self):
6667
self.quit()
6768
raise
6869
try:
69-
self.__conn.ehlo(mm_cfg.SMTP_HELO_HOST)
70+
# Use a valid hostname for EHLO, fallback to localhost if SMTP_HELO_HOST is empty or invalid
71+
helo_host = mm_cfg.SMTP_HELO_HOST
72+
if not helo_host or helo_host.startswith('.') or helo_host == '@URLHOST@':
73+
helo_host = 'localhost'
74+
self.__conn.ehlo(helo_host)
7075
except SMTPException as e:
7176
syslog('smtp-failure', 'SMTP EHLO error: %s', e)
7277
self.quit()

Mailman/Handlers/SpamDetect.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def getDecodedHeaders(msg, cset='utf-8'):
7474
uvalue = u''
7575
try:
7676
if isinstance(v, str):
77-
v = decode_header(re.sub('\n\s', ' ', v))
77+
v = decode_header(re.sub(r'\n\s', ' ', v))
7878
else:
7979
continue
8080
except HeaderParseError:

Mailman/Handlers/ToDigest.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def send_i18n_digests(mlist, mboxfp):
208208
print(mastheadtxt, file=plainmsg)
209209
print(file=plainmsg)
210210
# Now add the optional digest header but only if more than whitespace.
211-
if re.sub('\s', '', mlist.digest_header):
211+
if re.sub(r'\s', '', mlist.digest_header):
212212
lc_digest_header_msg = _('digest header')
213213
if isinstance(lc_digest_header_msg, bytes):
214214
lc_digest_header_msg = str(lc_digest_header_msg)
@@ -371,7 +371,7 @@ def send_i18n_digests(mlist, mboxfp):
371371
print(file=plainmsg)
372372

373373
# Now add the footer but only if more than whitespace.
374-
if re.sub('\s', '', mlist.digest_footer):
374+
if re.sub(r'\s', '', mlist.digest_footer):
375375
lc_digest_footer_msg = _('digest footer')
376376
if isinstance(lc_digest_footer_msg, bytes):
377377
lc_digest_footer_msg = str(lc_digest_footer_msg)

Mailman/SecurityManager.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ def __checkone(self, c, authcontext, user):
367367

368368

369369

370-
splitter = re.compile(';\s*')
370+
splitter = re.compile(r';\s*')
371371

372372
def parsecookie(s):
373373
c = {}

Mailman/Utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1263,7 +1263,7 @@ def strip_verbose_pattern(pattern):
12631263
elif c == ']' and inclass:
12641264
inclass = False
12651265
newpattern += c
1266-
elif re.search('\s', c):
1266+
elif re.search(r'\s', c):
12671267
if inclass:
12681268
if c == NL:
12691269
newpattern += '\\n'
@@ -1746,7 +1746,7 @@ def check_eq_domains(email, domains_list):
17461746
except ValueError:
17471747
return []
17481748
domain = domain.lower()
1749-
domains_list = re.sub('\s', '', domains_list).lower()
1749+
domains_list = re.sub(r'\s', '', domains_list).lower()
17501750
domains = domains_list.split(';')
17511751
domains_list = []
17521752
for d in domains:

0 commit comments

Comments
 (0)