Skip to content

Commit bada740

Browse files
author
Richard Jones
committed
SMTP login and TLS support added ([SF#710853] with extras ;)
1 parent 4136b90 commit bada740

File tree

7 files changed

+74
-14
lines changed

7 files changed

+74
-14
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ Feature:
6464
- Roundup templates are now distributed much more sanely, allowing for
6565
3rd-party templates.
6666
- extended date syntax to make range searches even more useful
67+
- SMTP login and TLS support added (sf bug 710853 with extras ;)
6768

6869
Fixed:
6970
- applied unicode patch. All data is stored in utf-8. Incoming messages

roundup/cgi/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# $Id: client.py,v 1.113 2003-04-10 05:12:41 richard Exp $
1+
# $Id: client.py,v 1.114 2003-04-24 07:19:59 richard Exp $
22

33
__doc__ = """
44
WWW request handler (also used in the stand-alone server).
@@ -14,7 +14,7 @@
1414
from roundup.cgi import cgitb
1515
from roundup.cgi.PageTemplates import PageTemplate
1616
from roundup.rfc2822 import encode_header
17-
from roundup.mailgw import uidFromAddress
17+
from roundup.mailgw import uidFromAddress, openSMTPConnection
1818

1919
class HTTPException(Exception):
2020
pass
@@ -787,7 +787,7 @@ def sendEmail(self, to, subject, content):
787787
try:
788788
# send the message as admin so bounces are sent there
789789
# instead of to roundup
790-
smtp = smtplib.SMTP(self.db.config.MAILHOST)
790+
smtp = openSMTPConnection(self.db.config)
791791
smtp.sendmail(self.db.config.ADMIN_EMAIL, [to],
792792
message.getvalue())
793793
except socket.error, value:

roundup/mailgw.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class node. Any parts of other types are each stored in separate files
7373
an exception, the original message is bounced back to the sender with the
7474
explanatory message given in the exception.
7575
76-
$Id: mailgw.py,v 1.117 2003-04-23 12:09:20 richard Exp $
76+
$Id: mailgw.py,v 1.118 2003-04-24 07:19:58 richard Exp $
7777
'''
7878

7979
import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -132,6 +132,35 @@ def getparam(str, param):
132132
return rfc822.unquote(f[i+1:].strip())
133133
return None
134134

135+
def openSMTPConnection(config):
136+
''' Open an SMTP connection to the mailhost specified in the config
137+
'''
138+
smtp = smtplib.SMTP(config.MAILHOST)
139+
140+
# use TLS?
141+
use_tls = getattr(config, 'MAILHOST_TLS', 'no')
142+
if use_tls == 'yes'
143+
# do we have key files too?
144+
keyfile = getattr(config, 'MAILHOST_TLS_KEYFILE', None)
145+
if keyfile is not None:
146+
certfile = getattr(config, 'MAILHOST_TLS_CERTFILE', None)
147+
if certfile is not None:
148+
args = (keyfile, certfile)
149+
else:
150+
args = (keyfile, )
151+
else:
152+
args = ()
153+
# start the TLS
154+
smtp.starttls(*args)
155+
156+
# ok, now do we also need to log in?
157+
mailuser = getattr(config, 'MAILUSER', None)
158+
if mailuser:
159+
smtp.login(*config.MAILUSER)
160+
161+
# that's it, a fully-configured SMTP connection ready to go
162+
return smtp
163+
135164
class Message(mimetools.Message):
136165
''' subclass mimetools.Message so we can retrieve the parts of the
137166
message...
@@ -345,7 +374,7 @@ def handle_Message(self, message):
345374
m.getvalue()))
346375
else:
347376
try:
348-
smtp = smtplib.SMTP(self.instance.config.MAILHOST)
377+
smtp = openSMTPConnection(self.instance.config)
349378
smtp.sendmail(self.instance.config.ADMIN_EMAIL, sendto,
350379
m.getvalue())
351380
except socket.error, value:
@@ -820,12 +849,12 @@ def handle_message(self, message):
820849
# attach the files to the issue
821850
if nodeid:
822851
# extend the existing files list
823-
fileprop = cl.get(nodeid, 'file')
852+
fileprop = cl.get(nodeid, 'files')
824853
fileprop.extend(files)
825854
props['files'] = fileprop
826855
else:
827856
# pre-load the files list
828-
props['files'] = fileprop
857+
props['files'] = files
829858

830859

831860
#

roundup/roundupdb.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: roundupdb.py,v 1.84 2003-04-14 06:24:01 richard Exp $
18+
# $Id: roundupdb.py,v 1.85 2003-04-24 07:19:58 richard Exp $
1919

2020
__doc__ = """
2121
Extending hyperdb with types specific to issue-tracking.
@@ -43,7 +43,8 @@ def straddr(pair, specialsre = re.compile(r'[][\()<>@,:;".]'),
4343
return '%s%s%s <%s>' % (quotes, name, quotes, address)
4444
return address
4545

46-
import hyperdb
46+
from roundup import hyperdb
47+
from roundup.mailgw import openSMTPConnection
4748

4849
# set to indicate to roundup not to actually _send_ email
4950
# this var must contain a file to write the mail to
@@ -333,7 +334,7 @@ def send_message(self, nodeid, msgid, note, sendto, from_address=None):
333334
try:
334335
# send the message as admin so bounces are sent there
335336
# instead of to roundup
336-
smtp = smtplib.SMTP(self.db.config.MAILHOST)
337+
smtp = openSMTPConnection(self.db.config)
337338
smtp.sendmail(self.db.config.ADMIN_EMAIL, sendto,
338339
message.getvalue())
339340
except socket.error, value:

scripts/roundup-reminder

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
2020
# SOFTWARE.
2121

22-
# $Id: roundup-reminder,v 1.5 2003-02-06 05:43:49 richard Exp $
22+
# $Id: roundup-reminder,v 1.6 2003-04-24 07:19:59 richard Exp $
2323

2424
'''
2525
Simple script that emails all users of a tracker with the issues that
@@ -34,6 +34,7 @@ Note: The instance that this script was designed for has a modified schema!
3434

3535
import sys, cStringIO, MimeWriter, smtplib
3636
from roundup import instance, date
37+
from roundup.mailgw import openSMTPConnection
3738

3839
# open the instance
3940
if len(sys.argv) != 2:
@@ -147,7 +148,7 @@ and click on "My Issues". Do NOT respond to this message.
147148
writer.lastpart()
148149

149150
# all done, send!
150-
smtp = smtplib.SMTP(db.config.MAILHOST)
151+
smtp = openSMTPConnection(db.config)
151152
smtp.sendmail(db.config.ADMIN_EMAIL, address, message.getvalue())
152153

153154
# vim: set filetype=python ts=4 sw=4 et si

templates/classic/config.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: config.py,v 1.2 2003-04-23 11:59:36 richard Exp $
18+
# $Id: config.py,v 1.3 2003-04-24 07:19:59 richard Exp $
1919

2020
import os
2121

@@ -25,6 +25,20 @@
2525
# The SMTP mail host that roundup will use to send mail
2626
MAILHOST = 'localhost'
2727

28+
# If your SMTP mail host requires a username and password for access, then
29+
# specify them here.
30+
# eg. MAILUSER = ('username', 'password')
31+
MAILUSER = ()
32+
33+
# If your SMTP mail host provides or requires TLS (Transport Layer
34+
# Security) then set MAILHOST_TLS = 'yes'
35+
# Optionallly, you may also set MAILHOST_TLS_KEYFILE to the name of a PEM
36+
# formatted file that contains your private key, and MAILHOST_TLS_CERTFILE
37+
# to the name of a PEM formatted certificate chain file.
38+
MAILHOST_TLS = 'no'
39+
MAILHOST_TLS_KEYFILE = ''
40+
MAILHOST_TLS_CERTFILE = ''
41+
2842
# The domain name used for email addresses.
2943
MAIL_DOMAIN = 'your.tracker.email.domain.example'
3044

templates/minimal/config.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717
#
18-
# $Id: config.py,v 1.1 2003-04-17 03:27:27 richard Exp $
18+
# $Id: config.py,v 1.2 2003-04-24 07:20:00 richard Exp $
1919

2020
import os
2121

@@ -25,6 +25,20 @@
2525
# The SMTP mail host that roundup will use to send mail
2626
MAILHOST = 'localhost'
2727

28+
# If your SMTP mail host requires a username and password for access, then
29+
# specify them here.
30+
# eg. MAILUSER = ('username', 'password')
31+
MAILUSER = ()
32+
33+
# If your SMTP mail host provides or requires TLS (Transport Layer
34+
# Security) then set MAILHOST_TLS = 'yes'
35+
# Optionallly, you may also set MAILHOST_TLS_KEYFILE to the name of a PEM
36+
# formatted file that contains your private key, and MAILHOST_TLS_CERTFILE
37+
# to the name of a PEM formatted certificate chain file.
38+
MAILHOST_TLS = 'no'
39+
MAILHOST_TLS_KEYFILE = ''
40+
MAILHOST_TLS_CERTFILE = ''
41+
2842
# The domain name used for email addresses.
2943
MAIL_DOMAIN = 'your.tracker.email.domain.example'
3044

0 commit comments

Comments
 (0)