Code

*** empty log message ***
[roundup.git] / roundup / mailgw.py
index f45eedc9d51af4e3e6e0a88259c054676215dcdb..47d0831099bff7579ab1f7e7fd3311c29b4d5999 100644 (file)
@@ -72,7 +72,7 @@ are calling the create() method to create a new node). If an auditor raises
 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'
 
@@ -80,7 +80,7 @@ import string, re, os, mimetools, cStringIO, smtplib, socket, binascii, quopri
 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', '')
@@ -429,13 +429,16 @@ class MailGW:
         """
         # 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:')
@@ -454,27 +457,24 @@ class MailGW:
         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
@@ -483,6 +483,7 @@ class MailGW:
         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')
@@ -804,8 +805,13 @@ not find a text/plain part to use.
             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
@@ -820,20 +826,23 @@ not find a text/plain part to use.
         # 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
@@ -947,10 +956,13 @@ def uidFromAddress(db, address, create=1, **user_props):
             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