Skip to content

Commit e5b9e27

Browse files
committed
issue2551186 - replace socket.sslerror in mailgw.py.
roundup/mailgw.py: replaced socket.sslerror with anypy/ssl_.SSLError also looks like a socket.sslerror was removed from pops handling. added it back using method above. roundupanypy/ssl_.py: defines replacement SSLError suitable for python2 or 3 tested by running nc -lp 995 or 993 (pop3s/imaps) and sending gibberish when mailgw connects. This generates a bad version number SSLError. I need to get my imap and pop mock servers included for testing at some point, but I am not sure how to make them bind to the right port as they are priv ports.
1 parent 0f42750 commit e5b9e27

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed

CHANGES.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Fixed:
6969
--prefix=/tmp/r2. Force insert --old-and-unmangable to get it
7070
to use a classic installer and not an easy install. This only
7171
affects python2.
72+
- issue2551186 - Python versions >= 3.3 no longer use socket.sslerror.
73+
Andrew (kragacles) patched uses of socket.sslerror in mailgy.py.
74+
Patch adapted to allow trapping sslerror under both python2 and 3.
75+
(John Rouillard)
7276

7377
Features:
7478

roundup/anypy/ssl_.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
try:
2+
# Python 3+
3+
from ssl import SSLError
4+
except (ImportError, AttributeError):
5+
# Python 2.5-2.7
6+
from socket import sslerror as SSLError

roundup/mailgw.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ class node. Any parts of other types are each stored in separate files
112112
from roundup.hyperdb import iter_roles
113113
from roundup.anypy.strings import StringIO, b2s, u2s
114114
import roundup.anypy.random_ as random_
115+
import roundup.anypy.ssl_ as ssl_
115116

116117
try:
117118
import gpg, gpg.core, gpg.constants, gpg.constants.sigsum
@@ -1373,7 +1374,7 @@ def do_imap(self, server, user='', password='', mailbox='', ssl=0, cram=0):
13731374
else:
13741375
self.logger.debug('Trying server %r without ssl' % server)
13751376
server = imaplib.IMAP4(server)
1376-
except (imaplib.IMAP4.error, socket.error, socket.sslerror):
1377+
except (imaplib.IMAP4.error, socket.error, ssl_.SSLError):
13771378
self.logger.exception('IMAP server error')
13781379
return 1
13791380

@@ -1415,7 +1416,7 @@ def do_imap(self, server, user='', password='', mailbox='', ssl=0, cram=0):
14151416
finally:
14161417
try:
14171418
server.expunge()
1418-
except (imaplib.IMAP4.error, socket.error, socket.sslerror):
1419+
except (imaplib.IMAP4.error, socket.error, ssl_.SSLError):
14191420
pass
14201421
server.logout()
14211422

@@ -1461,7 +1462,7 @@ def _do_pop(self, server, user, password, apop, ssl):
14611462
else:
14621463
klass = poplib.POP3
14631464
server = klass(server)
1464-
except socket.error:
1465+
except (socket.error, ssl_.SSLError):
14651466
self.logger.exception('POP server error')
14661467
return 1
14671468
if apop:

0 commit comments

Comments
 (0)