Mercurial > libervia-backend
comparison src/plugins/plugin_misc_smtp.py @ 993:301b342c697a
core: use of the new core.log module:
/!\ this is a massive refactoring and was largely automated, it probably did bring some bugs /!\
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 19 Apr 2014 19:19:19 +0200 |
parents | bfabeedbf32e |
children | e90125d07072 |
comparison
equal
deleted
inserted
replaced
992:f51a1895275c | 993:301b342c697a |
---|---|
16 | 16 |
17 # You should have received a copy of the GNU Affero General Public License | 17 # You should have received a copy of the GNU Affero General Public License |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | 18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | 19 |
20 from sat.core.i18n import _ | 20 from sat.core.i18n import _ |
21 from logging import debug, info, error | 21 from sat.core.log import getLogger |
22 import warnings | 22 log = getLogger(__name__) |
23 from twisted.internet import protocol, defer | 23 from twisted.internet import defer |
24 from twisted.words.protocols.jabber import error as jab_error | |
25 from twisted.cred import portal, checkers, credentials | 24 from twisted.cred import portal, checkers, credentials |
26 from twisted.cred import error as cred_error | 25 from twisted.cred import error as cred_error |
27 from twisted.mail import smtp | 26 from twisted.mail import smtp |
28 from twisted.python import failure | 27 from twisted.python import failure |
29 from email.parser import Parser | 28 from email.parser import Parser |
30 from email.utils import parseaddr | 29 from email.utils import parseaddr |
31 from twisted.mail.imap4 import LOGINCredentials, PLAINCredentials | 30 from twisted.mail.imap4 import LOGINCredentials, PLAINCredentials |
32 import os | |
33 from twisted.internet import reactor | 31 from twisted.internet import reactor |
34 import sys | 32 import sys |
35 | 33 |
36 from zope.interface import implements | 34 from zope.interface import implements |
37 | 35 |
58 </general> | 56 </general> |
59 </params> | 57 </params> |
60 """ | 58 """ |
61 | 59 |
62 def __init__(self, host): | 60 def __init__(self, host): |
63 info(_("Plugin SMTP Server initialization")) | 61 log.info(_("Plugin SMTP Server initialization")) |
64 self.host = host | 62 self.host = host |
65 | 63 |
66 #parameters | 64 #parameters |
67 host.memory.updateParams(self.params) | 65 host.memory.updateParams(self.params) |
68 | 66 |
69 port = int(self.host.memory.getParamA("SMTP Port", "Mail Server")) | 67 port = int(self.host.memory.getParamA("SMTP Port", "Mail Server")) |
70 info(_("Launching SMTP server on port %d"), port) | 68 log.info(_("Launching SMTP server on port %d") % port) |
71 | 69 |
72 self.server_factory = SmtpServerFactory(self.host) | 70 self.server_factory = SmtpServerFactory(self.host) |
73 reactor.listenTCP(port, self.server_factory) | 71 reactor.listenTCP(port, self.server_factory) |
74 | 72 |
75 | 73 |
91 try: | 89 try: |
92 self.host._sendMessage(parseaddr(mail['to'].decode('utf-8', 'replace'))[1], mail.get_payload().decode('utf-8', 'replace'), # TODO: manage other charsets | 90 self.host._sendMessage(parseaddr(mail['to'].decode('utf-8', 'replace'))[1], mail.get_payload().decode('utf-8', 'replace'), # TODO: manage other charsets |
93 subject=mail['subject'].decode('utf-8', 'replace'), mess_type='normal', profile_key=self.profile) | 91 subject=mail['subject'].decode('utf-8', 'replace'), mess_type='normal', profile_key=self.profile) |
94 except: | 92 except: |
95 exc_type, exc_value, exc_traceback = sys.exc_info() | 93 exc_type, exc_value, exc_traceback = sys.exc_info() |
96 error(_("Can't send message: %s") % exc_value) # The email is invalid or incorreclty parsed | 94 log.error(_("Can't send message: %s") % exc_value) # The email is invalid or incorreclty parsed |
97 return defer.fail() | 95 return defer.fail() |
98 self.message = None | 96 self.message = None |
99 return defer.succeed(None) | 97 return defer.succeed(None) |
100 | 98 |
101 def connectionLost(self): | 99 def connectionLost(self): |
150 | 148 |
151 def __init__(self, host): | 149 def __init__(self, host): |
152 self.host = host | 150 self.host = host |
153 | 151 |
154 def requestAvatar(self, avatarID, mind, *interfaces): | 152 def requestAvatar(self, avatarID, mind, *interfaces): |
155 debug('requestAvatar') | 153 log.debug('requestAvatar') |
156 profile = avatarID.decode('utf-8') | 154 profile = avatarID.decode('utf-8') |
157 if smtp.IMessageDelivery not in interfaces: | 155 if smtp.IMessageDelivery not in interfaces: |
158 raise NotImplementedError | 156 raise NotImplementedError |
159 return smtp.IMessageDelivery, SatSmtpDelivery(self.host, profile), lambda: None | 157 return smtp.IMessageDelivery, SatSmtpDelivery(self.host, profile), lambda: None |
160 | 158 |
196 _portal = portal.Portal(SmtpRealm(self.host)) | 194 _portal = portal.Portal(SmtpRealm(self.host)) |
197 _portal.registerChecker(SatProfileCredentialChecker(self.host)) | 195 _portal.registerChecker(SatProfileCredentialChecker(self.host)) |
198 smtp.SMTPFactory.__init__(self, _portal) | 196 smtp.SMTPFactory.__init__(self, _portal) |
199 | 197 |
200 def startedConnecting(self, connector): | 198 def startedConnecting(self, connector): |
201 debug(_("SMTP server connection started")) | 199 log.debug(_("SMTP server connection started")) |
202 smtp.SMTPFactory.startedConnecting(self, connector) | 200 smtp.SMTPFactory.startedConnecting(self, connector) |
203 | 201 |
204 def clientConnectionLost(self, connector, reason): | 202 def clientConnectionLost(self, connector, reason): |
205 debug(_("SMTP server connection lost (reason: %s)"), reason) | 203 log.debug(_("SMTP server connection lost (reason: %s)"), reason) |
206 smtp.SMTPFactory.clientConnectionLost(self, connector, reason) | 204 smtp.SMTPFactory.clientConnectionLost(self, connector, reason) |
207 | 205 |
208 def buildProtocol(self, addr): | 206 def buildProtocol(self, addr): |
209 p = smtp.SMTPFactory.buildProtocol(self, addr) | 207 p = smtp.SMTPFactory.buildProtocol(self, addr) |
210 # add the challengers from imap4, more secure and complicated challengers are available | 208 # add the challengers from imap4, more secure and complicated challengers are available |