annotate sat/plugins/plugin_misc_smtp.py @ 3075:501a1a3c8594

plugin text syntaxes: don't use anymore deprecated cgi.escape
author Goffi <goffi@goffi.org>
date Mon, 18 Nov 2019 20:50:34 +0100
parents ab2696e34d29
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
1 #!/usr/bin/env python3
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
3
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
4 # SàT plugin for managing smtp server
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
5 # Copyright (C) 2011 Jérôme Poisson (goffi@goffi.org)
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
6
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
7 # This program is free software: you can redistribute it and/or modify
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
10 # (at your option) any later version.
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
11
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
12 # This program is distributed in the hope that it will be useful,
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
15 # GNU Affero General Public License for more details.
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
16
609
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
84a6e83157c2 fixed licences in docstrings (they are now in comments)
Goffi <goffi@goffi.org>
parents: 602
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
19
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 662
diff changeset
20 from sat.core.i18n import _
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
21 from sat.core.constants import Const as C
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
22 from sat.core.log import getLogger
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
23
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
24 log = getLogger(__name__)
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
25 from twisted.internet import defer
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
26 from twisted.cred import portal, checkers, credentials
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
27 from twisted.cred import error as cred_error
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
28 from twisted.mail import smtp
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
29 from twisted.python import failure
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
30 from email.parser import Parser
370
68cdaf6d78e3 plugin smtp: fixed email address parsing and invalid unicode message
Goffi <goffi@goffi.org>
parents: 261
diff changeset
31 from email.utils import parseaddr
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
32 from twisted.mail.imap4 import LOGINCredentials, PLAINCredentials
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
33 from twisted.internet import reactor
370
68cdaf6d78e3 plugin smtp: fixed email address parsing and invalid unicode message
Goffi <goffi@goffi.org>
parents: 261
diff changeset
34 import sys
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
35
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
36 from zope.interface import implementer
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
37
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
38 PLUGIN_INFO = {
2145
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
39 C.PI_NAME: "SMTP server Plugin",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
40 C.PI_IMPORT_NAME: "SMTP",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
41 C.PI_TYPE: "Misc",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
42 C.PI_PROTOCOLS: [],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
43 C.PI_DEPENDENCIES: ["Maildir"],
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
44 C.PI_MAIN: "SMTP_server",
33c8c4973743 core (plugins): added missing contants + use of new constants in PLUGIN_INFO
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
45 C.PI_HANDLER: "no",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
46 C.PI_DESCRIPTION: _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
47 """Create a SMTP server that you can use to send your "normal" type messages"""
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 ),
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
49 }
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
50
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
51
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
52 class SMTP_server(object):
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
53
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
54 params = """
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
55 <params>
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
56 <general>
261
0ecd9c33fa3a IMAP & SMTP Port parameters are now merged in "Mail Server" category
Goffi <goffi@goffi.org>
parents: 260
diff changeset
57 <category name="Mail Server">
1226
72f25d671368 memory (params): use more generic param attribute "constraint" instead of "min" and "max"
souliane <souliane@mailoo.org>
parents: 1220
diff changeset
58 <param name="SMTP Port" value="10125" type="int" constraint="1;65535" />
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
59 </category>
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
60 </general>
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
61 </params>
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
62 """
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
63
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
64 def __init__(self, host):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
65 log.info(_("Plugin SMTP Server initialization"))
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.host = host
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
67
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
68 # parameters
662
4f747d7fde8c core: importParams renamed to updateParams: it now updates the parameter instead of appending children if it find an existing one.
Goffi <goffi@goffi.org>
parents: 609
diff changeset
69 host.memory.updateParams(self.params)
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
70
261
0ecd9c33fa3a IMAP & SMTP Port parameters are now merged in "Mail Server" category
Goffi <goffi@goffi.org>
parents: 260
diff changeset
71 port = int(self.host.memory.getParamA("SMTP Port", "Mail Server"))
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
72 log.info(_("Launching SMTP server on port %d") % port)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
73
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.server_factory = SmtpServerFactory(self.host)
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
75 reactor.listenTCP(port, self.server_factory)
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
76
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
77
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
78 @implementer(smtp.IMessage)
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
79 class SatSmtpMessage(object):
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
80
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
81 def __init__(self, host, profile):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
82 self.host = host
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
83 self.profile = profile
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
84 self.message = []
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
85
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
86 def lineReceived(self, line):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
87 """handle another line"""
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
88 self.message.append(line)
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
89
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
90 def eomReceived(self):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
91 """handle end of message"""
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
92 mail = Parser().parsestr("\n".join(self.message))
370
68cdaf6d78e3 plugin smtp: fixed email address parsing and invalid unicode message
Goffi <goffi@goffi.org>
parents: 261
diff changeset
93 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
94 self.host._sendMessage(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 parseaddr(mail["to"].decode("utf-8", "replace"))[1],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 mail.get_payload().decode(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 "utf-8", "replace"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
98 ), # TODO: manage other charsets
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
99 subject=mail["subject"].decode("utf-8", "replace"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
100 mess_type="normal",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 profile_key=self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 )
370
68cdaf6d78e3 plugin smtp: fixed email address parsing and invalid unicode message
Goffi <goffi@goffi.org>
parents: 261
diff changeset
103 except:
68cdaf6d78e3 plugin smtp: fixed email address parsing and invalid unicode message
Goffi <goffi@goffi.org>
parents: 261
diff changeset
104 exc_type, exc_value, exc_traceback = sys.exc_info()
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 log.error(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
106 _("Can't send message: %s") % exc_value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
107 ) # The email is invalid or incorreclty parsed
370
68cdaf6d78e3 plugin smtp: fixed email address parsing and invalid unicode message
Goffi <goffi@goffi.org>
parents: 261
diff changeset
108 return defer.fail()
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
109 self.message = None
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
110 return defer.succeed(None)
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
111
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
112 def connectionLost(self):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
113 """handle message truncated"""
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
114 raise smtp.SMTPError
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
115
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
116
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
117 @implementer(smtp.IMessageDelivery)
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
118 class SatSmtpDelivery(object):
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
119
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
120 def __init__(self, host, profile):
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
121 self.host = host
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
122 self.profile = profile
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
123
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
124 def receivedHeader(self, helo, origin, recipients):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
125 """
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
126 Generate the Received header for a message
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
127 @param helo: The argument to the HELO command and the client's IP
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
128 address.
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
129 @param origin: The address the message is from
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
130 @param recipients: A list of the addresses for which this message
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
131 is bound.
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
132 @return: The full \"Received\" header string.
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
133 """
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
134 return "Received:"
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
135
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
136 def validateTo(self, user):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
137 """
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
138 Validate the address for which the message is destined.
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
139 @param user: The address to validate.
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
140 @return: A Deferred which becomes, or a callable which
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
141 takes no arguments and returns an object implementing IMessage.
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
142 This will be called and the returned object used to deliver the
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
143 message when it arrives.
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
144 """
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
145 return lambda: SatSmtpMessage(self.host, self.profile)
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
146
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
147 def validateFrom(self, helo, origin):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
148 """
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
149 Validate the address from which the message originates.
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
150 @param helo: The argument to the HELO command and the client's IP
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
151 address.
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
152 @param origin: The address the message is from
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
153 @return: origin or a Deferred whose callback will be
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
154 passed origin.
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
155 """
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
156 return origin
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
157
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
158
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
159 @implementer(portal.IRealm)
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
160 class SmtpRealm(object):
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
161
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
162 def __init__(self, host):
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
163 self.host = host
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
164
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
165 def requestAvatar(self, avatarID, mind, *interfaces):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
166 log.debug("requestAvatar")
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
167 profile = avatarID
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
168 if smtp.IMessageDelivery not in interfaces:
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
169 raise NotImplementedError
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
170 return smtp.IMessageDelivery, SatSmtpDelivery(self.host, profile), lambda: None
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
171
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
172
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
173 @implementer(checkers.ICredentialsChecker)
588
beaf6bec2fcd Remove every old-style class.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 587
diff changeset
174 class SatProfileCredentialChecker(object):
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
175 """
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
176 This credential checker check against SàT's profile and associated jabber's password
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
177 Check if the profile exists, and if the password is OK
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
178 Return the profile as avatarId
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
179 """
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 credentialInterfaces = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
182 credentials.IUsernamePassword,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
183 credentials.IUsernameHashedPassword,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 )
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
185
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
186 def __init__(self, host):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
187 self.host = host
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
188
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
189 def _cbPasswordMatch(self, matched, profile):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
190 if matched:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
191 return profile.encode("utf-8")
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
192 else:
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
193 return failure.Failure(cred_error.UnauthorizedLogin())
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
194
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
195 def requestAvatarId(self, credentials):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
196 profiles = self.host.memory.getProfilesList()
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
197 if not credentials.username in profiles:
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
198 return defer.fail(cred_error.UnauthorizedLogin())
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
199 d = self.host.memory.asyncGetParamA(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
200 "Password", "Connection", profile_key=credentials.username
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
201 )
1031
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
202 d.addCallback(credentials.checkPassword)
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
203 d.addCallback(self._cbPasswordMatch, credentials.username)
e90125d07072 plugins misc_account, misc_smtp: update the plugins that deal with passwords
souliane <souliane@mailoo.org>
parents: 993
diff changeset
204 return d
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
205
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
206
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
207 class SmtpServerFactory(smtp.SMTPFactory):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
208 def __init__(self, host):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
209 self.protocol = smtp.ESMTP
594
e629371a28d3 Fix pep8 support in src/plugins.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 588
diff changeset
210 self.host = host
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
211 _portal = portal.Portal(SmtpRealm(self.host))
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
212 _portal.registerChecker(SatProfileCredentialChecker(self.host))
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
213 smtp.SMTPFactory.__init__(self, _portal)
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
214
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
215 def startedConnecting(self, connector):
993
301b342c697a core: use of the new core.log module:
Goffi <goffi@goffi.org>
parents: 771
diff changeset
216 log.debug(_("SMTP server connection started"))
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
217 smtp.SMTPFactory.startedConnecting(self, connector)
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
218
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
219 def clientConnectionLost(self, connector, reason):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
220 log.debug(_("SMTP server connection lost (reason: %s)"), reason)
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
221 smtp.SMTPFactory.clientConnectionLost(self, connector, reason)
587
952322b1d490 Remove trailing whitespaces.
Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
parents: 574
diff changeset
222
260
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
223 def buildProtocol(self, addr):
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
224 p = smtp.SMTPFactory.buildProtocol(self, addr)
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
225 # add the challengers from imap4, more secure and complicated challengers are available
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
226 p.challengers = {"LOGIN": LOGINCredentials, "PLAIN": PLAINCredentials}
c8406fe5e81e Added SMTP server plugin, for sending messages from classic MUA \o/
Goffi <goffi@goffi.org>
parents:
diff changeset
227 return p