Mercurial > libervia-backend
comparison sat/plugins/plugin_misc_smtp.py @ 3028:ab2696e34d29
Python 3 port:
/!\ this is a huge commit
/!\ starting from this commit, SàT is needs Python 3.6+
/!\ SàT maybe be instable or some feature may not work anymore, this will improve with time
This patch port backend, bridge and frontends to Python 3.
Roughly this has been done this way:
- 2to3 tools has been applied (with python 3.7)
- all references to python2 have been replaced with python3 (notably shebangs)
- fixed files not handled by 2to3 (notably the shell script)
- several manual fixes
- fixed issues reported by Python 3 that where not handled in Python 2
- replaced "async" with "async_" when needed (it's a reserved word from Python 3.7)
- replaced zope's "implements" with @implementer decorator
- temporary hack to handle data pickled in database, as str or bytes may be returned,
to be checked later
- fixed hash comparison for password
- removed some code which is not needed anymore with Python 3
- deactivated some code which needs to be checked (notably certificate validation)
- tested with jp, fixed reported issues until some basic commands worked
- ported Primitivus (after porting dependencies like urwid satext)
- more manual fixes
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 13 Aug 2019 19:08:41 +0200 |
parents | 56f94936df1e |
children |
comparison
equal
deleted
inserted
replaced
3027:ff5bcb12ae60 | 3028:ab2696e34d29 |
---|---|
1 #!/usr/bin/env python2 | 1 #!/usr/bin/env python3 |
2 # -*- coding: utf-8 -*- | 2 # -*- coding: utf-8 -*- |
3 | 3 |
4 # SàT plugin for managing smtp server | 4 # SàT plugin for managing smtp server |
5 # Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) | 5 # Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org) |
6 | 6 |
31 from email.utils import parseaddr | 31 from email.utils import parseaddr |
32 from twisted.mail.imap4 import LOGINCredentials, PLAINCredentials | 32 from twisted.mail.imap4 import LOGINCredentials, PLAINCredentials |
33 from twisted.internet import reactor | 33 from twisted.internet import reactor |
34 import sys | 34 import sys |
35 | 35 |
36 from zope.interface import implements | 36 from zope.interface import implementer |
37 | 37 |
38 PLUGIN_INFO = { | 38 PLUGIN_INFO = { |
39 C.PI_NAME: "SMTP server Plugin", | 39 C.PI_NAME: "SMTP server Plugin", |
40 C.PI_IMPORT_NAME: "SMTP", | 40 C.PI_IMPORT_NAME: "SMTP", |
41 C.PI_TYPE: "Misc", | 41 C.PI_TYPE: "Misc", |
73 | 73 |
74 self.server_factory = SmtpServerFactory(self.host) | 74 self.server_factory = SmtpServerFactory(self.host) |
75 reactor.listenTCP(port, self.server_factory) | 75 reactor.listenTCP(port, self.server_factory) |
76 | 76 |
77 | 77 |
78 @implementer(smtp.IMessage) | |
78 class SatSmtpMessage(object): | 79 class SatSmtpMessage(object): |
79 implements(smtp.IMessage) | |
80 | 80 |
81 def __init__(self, host, profile): | 81 def __init__(self, host, profile): |
82 self.host = host | 82 self.host = host |
83 self.profile = profile | 83 self.profile = profile |
84 self.message = [] | 84 self.message = [] |
101 profile_key=self.profile, | 101 profile_key=self.profile, |
102 ) | 102 ) |
103 except: | 103 except: |
104 exc_type, exc_value, exc_traceback = sys.exc_info() | 104 exc_type, exc_value, exc_traceback = sys.exc_info() |
105 log.error( | 105 log.error( |
106 _(u"Can't send message: %s") % exc_value | 106 _("Can't send message: %s") % exc_value |
107 ) # The email is invalid or incorreclty parsed | 107 ) # The email is invalid or incorreclty parsed |
108 return defer.fail() | 108 return defer.fail() |
109 self.message = None | 109 self.message = None |
110 return defer.succeed(None) | 110 return defer.succeed(None) |
111 | 111 |
112 def connectionLost(self): | 112 def connectionLost(self): |
113 """handle message truncated""" | 113 """handle message truncated""" |
114 raise smtp.SMTPError | 114 raise smtp.SMTPError |
115 | 115 |
116 | 116 |
117 @implementer(smtp.IMessageDelivery) | |
117 class SatSmtpDelivery(object): | 118 class SatSmtpDelivery(object): |
118 implements(smtp.IMessageDelivery) | |
119 | 119 |
120 def __init__(self, host, profile): | 120 def __init__(self, host, profile): |
121 self.host = host | 121 self.host = host |
122 self.profile = profile | 122 self.profile = profile |
123 | 123 |
154 passed origin. | 154 passed origin. |
155 """ | 155 """ |
156 return origin | 156 return origin |
157 | 157 |
158 | 158 |
159 @implementer(portal.IRealm) | |
159 class SmtpRealm(object): | 160 class SmtpRealm(object): |
160 implements(portal.IRealm) | |
161 | 161 |
162 def __init__(self, host): | 162 def __init__(self, host): |
163 self.host = host | 163 self.host = host |
164 | 164 |
165 def requestAvatar(self, avatarID, mind, *interfaces): | 165 def requestAvatar(self, avatarID, mind, *interfaces): |
166 log.debug("requestAvatar") | 166 log.debug("requestAvatar") |
167 profile = avatarID.decode("utf-8") | 167 profile = avatarID |
168 if smtp.IMessageDelivery not in interfaces: | 168 if smtp.IMessageDelivery not in interfaces: |
169 raise NotImplementedError | 169 raise NotImplementedError |
170 return smtp.IMessageDelivery, SatSmtpDelivery(self.host, profile), lambda: None | 170 return smtp.IMessageDelivery, SatSmtpDelivery(self.host, profile), lambda: None |
171 | 171 |
172 | 172 |
173 @implementer(checkers.ICredentialsChecker) | |
173 class SatProfileCredentialChecker(object): | 174 class SatProfileCredentialChecker(object): |
174 """ | 175 """ |
175 This credential checker check against SàT's profile and associated jabber's password | 176 This credential checker check against SàT's profile and associated jabber's password |
176 Check if the profile exists, and if the password is OK | 177 Check if the profile exists, and if the password is OK |
177 Return the profile as avatarId | 178 Return the profile as avatarId |
178 """ | 179 """ |
179 | 180 |
180 implements(checkers.ICredentialsChecker) | |
181 credentialInterfaces = ( | 181 credentialInterfaces = ( |
182 credentials.IUsernamePassword, | 182 credentials.IUsernamePassword, |
183 credentials.IUsernameHashedPassword, | 183 credentials.IUsernameHashedPassword, |
184 ) | 184 ) |
185 | 185 |
215 def startedConnecting(self, connector): | 215 def startedConnecting(self, connector): |
216 log.debug(_("SMTP server connection started")) | 216 log.debug(_("SMTP server connection started")) |
217 smtp.SMTPFactory.startedConnecting(self, connector) | 217 smtp.SMTPFactory.startedConnecting(self, connector) |
218 | 218 |
219 def clientConnectionLost(self, connector, reason): | 219 def clientConnectionLost(self, connector, reason): |
220 log.debug(_(u"SMTP server connection lost (reason: %s)"), reason) | 220 log.debug(_("SMTP server connection lost (reason: %s)"), reason) |
221 smtp.SMTPFactory.clientConnectionLost(self, connector, reason) | 221 smtp.SMTPFactory.clientConnectionLost(self, connector, reason) |
222 | 222 |
223 def buildProtocol(self, addr): | 223 def buildProtocol(self, addr): |
224 p = smtp.SMTPFactory.buildProtocol(self, addr) | 224 p = smtp.SMTPFactory.buildProtocol(self, addr) |
225 # add the challengers from imap4, more secure and complicated challengers are available | 225 # add the challengers from imap4, more secure and complicated challengers are available |