diff --git a/roundup/mailgw.py b/roundup/mailgw.py
index f45eedc9d51af4e3e6e0a88259c054676215dcdb..47d0831099bff7579ab1f7e7fd3311c29b4d5999 100644 (file)
--- a/roundup/mailgw.py
+++ b/roundup/mailgw.py
an exception, the original message is bounced back to the sender with the
explanatory message given in the exception.
-$Id: mailgw.py,v 1.143 2004-02-11 23:55:08 richard Exp $
+$Id: mailgw.py,v 1.146 2004-03-26 00:44:11 richard Exp $
"""
__docformat__ = 'restructuredtext'
import time, random, sys
import traceback, MimeWriter, rfc822
-from roundup import hyperdb, date, password, rfc2822
+from roundup import hyperdb, date, password, rfc2822, exceptions
from roundup.mailer import Mailer
SENDMAILDEBUG = os.environ.get('SENDMAILDEBUG', '')
"""
# in some rare cases, a particularly stuffed-up e-mail will make
# its way into here... try to handle it gracefully
+
sendto = message.getaddrlist('resent-from')
if not sendto:
sendto = message.getaddrlist('from')
if not sendto:
# very bad-looking message - we don't even know who sent it
# XXX we should use a log file here...
+
sendto = [self.instance.config.ADMIN_EMAIL]
+
m = ['Subject: badly formed message from mail gateway']
m.append('')
m.append('The mail gateway retrieved a message which has no From:')
except MailUsageHelp:
# bounce the message back to the sender with the usage message
fulldoc = '\n'.join(string.split(__doc__, '\n')[2:])
- sendto = [sendto[0][1]]
m = ['']
m.append('\n\nMail Gateway Help\n=================')
m.append(fulldoc)
- self.mailer.bounce_message(message, sendto, m,
+ self.mailer.bounce_message(message, [sendto[0][1]], m,
subject="Mail Gateway Help")
except MailUsageError, value:
# bounce the message back to the sender with the usage message
fulldoc = '\n'.join(string.split(__doc__, '\n')[2:])
- sendto = [sendto[0][1]]
m = ['']
m.append(str(value))
m.append('\n\nMail Gateway Help\n=================')
m.append(fulldoc)
- self.mailer.bounce_message(message, sendto, m)
+ self.mailer.bounce_message(message, [sendto[0][1]], m)
except Unauthorized, value:
# just inform the user that he is not authorized
- sendto = [sendto[0][1]]
m = ['']
m.append(str(value))
- self.mailer.bounce_message(message, sendto, m)
+ self.mailer.bounce_message(message, [sendto[0][1]], m)
except IgnoreMessage:
# XXX we should use a log file here...
# do not take any action
except:
# bounce the message back to the sender with the error message
# XXX we should use a log file here...
+ # let the admin know that something very bad is happening
sendto = [sendto[0][1], self.instance.config.ADMIN_EMAIL]
m = ['']
m.append('An unexpected error occurred during the processing')
for (name, mime_type, data) in attachments:
if not name:
name = "unnamed"
- files.append(self.db.file.create(type=mime_type, name=name,
- content=data, **file_props))
+ try:
+ fileid = self.db.file.create(type=mime_type, name=name,
+ content=data, **file_props)
+ except exceptions.Reject:
+ pass
+ else:
+ files.append(fileid)
# attach the files to the issue
if nodeid:
# extend the existing files list
# create the message if there's a message body (content)
#
if (content and properties.has_key('messages')):
- message_id = self.db.msg.create(author=author,
- recipients=recipients, date=date.Date('.'), summary=summary,
- content=content, files=files, messageid=messageid,
- inreplyto=inreplyto, **msg_props)
-
- # attach the message to the node
- if nodeid:
- # add the message to the node's list
- messages = cl.get(nodeid, 'messages')
- messages.append(message_id)
- props['messages'] = messages
+ try:
+ message_id = self.db.msg.create(author=author,
+ recipients=recipients, date=date.Date('.'),
+ summary=summary, content=content, files=files,
+ messageid=messageid, inreplyto=inreplyto, **msg_props)
+ except exceptions.Reject:
+ pass
else:
- # pre-load the messages list
- props['messages'] = [message_id]
+ # attach the message to the node
+ if nodeid:
+ # add the message to the node's list
+ messages = cl.get(nodeid, 'messages')
+ messages.append(message_id)
+ props['messages'] = messages
+ else:
+ # pre-load the messages list
+ props['messages'] = [message_id]
#
# perform the node change / create
trying = username + str(n)
# create!
- return db.user.create(username=trying, address=address,
- realname=realname, roles=db.config.NEW_EMAIL_USER_ROLES,
- password=password.Password(password.generatePassword()),
- **user_props)
+ try:
+ return db.user.create(username=trying, address=address,
+ realname=realname, roles=db.config.NEW_EMAIL_USER_ROLES,
+ password=password.Password(password.generatePassword()),
+ **user_props)
+ except exceptions.Reject:
+ return 0
else:
return 0