Skip to content

Commit d0f33f9

Browse files
author
Richard Jones
committed
- detect and break email loops [SF#640854]
1 parent 799f91c commit d0f33f9

File tree

3 files changed

+20
-2
lines changed

3 files changed

+20
-2
lines changed

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ are given with the most recent entry first.
1616
- removed FILTER_POSITION from bundled configs
1717
- reverse message listing in issue display (reversion of recent change)
1818
- bad entries for multilink editing in cgi don't traceback now (sf bug 640310)
19+
- detect and break email loops (sf bug 640854)
1920

2021

2122
2002-11-07 0.5.2

roundup/mailgw.py

Lines changed: 15 additions & 1 deletion
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.100 2002-12-10 00:11:15 richard Exp $
76+
$Id: mailgw.py,v 1.101 2002-12-10 00:23:35 richard Exp $
7777
'''
7878

7979
import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
@@ -92,6 +92,10 @@ class MailUsageError(ValueError):
9292
class MailUsageHelp(Exception):
9393
pass
9494

95+
class MailLoop(Exception):
96+
''' We've seen this message before... '''
97+
pass
98+
9599
class Unauthorized(Exception):
96100
""" Access denied """
97101

@@ -270,8 +274,12 @@ def handle_Message(self, message):
270274
m = ['']
271275
m.append(str(value))
272276
m = self.bounce_message(message, sendto, m)
277+
except MailLoop:
278+
# XXX we should use a log file here...
279+
return
273280
except:
274281
# bounce the message back to the sender with the error message
282+
# XXX we should use a log file here...
275283
sendto = [sendto[0][1], self.instance.config.ADMIN_EMAIL]
276284
m = ['']
277285
m.append('An unexpected error occurred during the processing')
@@ -285,6 +293,7 @@ def handle_Message(self, message):
285293
m = self.bounce_message(message, sendto, m)
286294
else:
287295
# very bad-looking message - we don't even know who sent it
296+
# XXX we should use a log file here...
288297
sendto = [self.instance.config.ADMIN_EMAIL]
289298
m = ['Subject: badly formed message from mail gateway']
290299
m.append('')
@@ -319,6 +328,7 @@ def bounce_message(self, message, sendto, error,
319328
'''
320329
msg = cStringIO.StringIO()
321330
writer = MimeWriter.MimeWriter(msg)
331+
writer.addheader('X-Roundup-Loop', 'hello')
322332
writer.addheader('Subject', subject)
323333
writer.addheader('From', '%s <%s>'% (self.instance.config.TRACKER_NAME,
324334
self.instance.config.TRACKER_EMAIL))
@@ -371,6 +381,10 @@ def handle_message(self, message):
371381
372382
Parse the message as per the module docstring.
373383
'''
384+
# detect loops
385+
if message.getheader('x-roundup-loop', ''):
386+
raise MailLoop
387+
374388
# handle the subject line
375389
subject = message.getheader('subject', '')
376390

roundup/roundupdb.py

Lines changed: 4 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: roundupdb.py,v 1.73 2002-11-05 22:59:46 richard Exp $
18+
# $Id: roundupdb.py,v 1.74 2002-12-10 00:23:36 richard Exp $
1919

2020
__doc__ = """
2121
Extending hyperdb with types specific to issue-tracking.
@@ -239,6 +239,9 @@ def send_message(self, nodeid, msgid, note, sendto):
239239
# add a uniquely Roundup header to help filtering
240240
writer.addheader('X-Roundup-Name', self.db.config.TRACKER_NAME)
241241

242+
# avoid email loops
243+
writer.addheader('X-Roundup-Loop', 'hello')
244+
242245
# attach files
243246
if message_files:
244247
part = writer.startmultipartbody('mixed')

0 commit comments

Comments
 (0)