diff roundup/mailgw.py @ 2119:cc4667ef3f12

Added the ability to toggle where error messages go. They either go to the user (default, for backwards compatibility), the dispatcher, or both. These are able to be toggled via settings in config.py. Please refer to upgrading.txt for more details. (And Richard, let me know if I've done anything wrong with this checkin. :))
author Eddie Parker <eparker@users.sourceforge.net>
date Thu, 25 Mar 2004 19:27:15 +0000
parents fc52d57c6c3e
children 95da13c1bdbd
line wrap: on
line diff
--- a/roundup/mailgw.py	Thu Mar 25 16:25:15 2004 +0000
+++ b/roundup/mailgw.py	Thu Mar 25 19:27:15 2004 +0000
@@ -72,7 +72,7 @@
 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.144 2004-03-25 19:27:15 eparker Exp $
 """
 __docformat__ = 'restructuredtext'
 
@@ -429,13 +429,27 @@
         """
         # in some rare cases, a particularly stuffed-up e-mail will make
         # its way into here... try to handle it gracefully
+
+        # Setting the dispatcher e-mail here, so as not to clutter things. Defaulting to ADMIN_EMAIL, if not set.
+        dispatcherEmail = getattr(self.instance.config, "DISPATCHER_EMAIL", getattr(self.instance.config, "ADMIN_EMAIL"))
+        errorMessagesTo = getattr(self.instance.config, "ERROR_MESSAGES_TO", "user")
+
         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]
+            
+            # [EP] This section was originally only to admin.. Not sure if this should ever go to the user?
+
+            if(errorMessagesTo == "dispatcher"):
+                sendto = [dispatcherEmail]
+            elif(errorMessagesTo == "both"):
+                sendto = [dispatcherEmail, self.instance.config.ADMIN_EMAIL]
+            else:
+                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,7 +468,13 @@
         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]]
+            if(errorMessagesTo == "dispatcher"):
+                sendto = [dispatcherEmail]
+            elif(errorMessagesTo == "both"):
+                sendto = [dispatcherEmail, sendto[0][1]]
+            else:
+                sendto = [sendto[0][1]]
+
             m = ['']
             m.append('\n\nMail Gateway Help\n=================')
             m.append(fulldoc)
@@ -463,7 +483,13 @@
         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]]
+
+            if(errorMessagesTo == "dispatcher"):
+                sendto = [dispatcherEmail]
+            elif(errorMessagesTo == "both"):
+                sendto = [dispatcherEmail, sendto[0][1]]
+            else:
+                sendto = [sendto[0][1]]
             m = ['']
             m.append(str(value))
             m.append('\n\nMail Gateway Help\n=================')
@@ -471,7 +497,13 @@
             self.mailer.bounce_message(message, sendto, m)
         except Unauthorized, value:
             # just inform the user that he is not authorized
-            sendto = [sendto[0][1]]
+            
+            if(errorMessagesTo == "dispatcher"):
+                sendto = [dispatcherEmail]
+            elif(errorMessagesTo == "both"):
+                sendto = [dispatcherEmail, sendto[0][1]]
+            else:
+                sendto = [sendto[0][1]]
             m = ['']
             m.append(str(value))
             self.mailer.bounce_message(message, sendto, m)
@@ -483,7 +515,14 @@
         except:
             # bounce the message back to the sender with the error message
             # XXX we should use a log file here...
-            sendto = [sendto[0][1], self.instance.config.ADMIN_EMAIL]
+
+            if(errorMessagesTo == "dispatcher"):
+                sendto = [dispatcherEmail]
+            elif(errorMessagesTo == "both"):
+                sendto = [dispatcherEmail, sendto[0][1], self.instance.config.ADMIN_EMAIL]
+            else:
+                sendto = [sendto[0][1], self.instance.config.ADMIN_EMAIL]
+
             m = ['']
             m.append('An unexpected error occurred during the processing')
             m.append('of your message. The tracker administrator is being')

Roundup Issue Tracker: http://roundup-tracker.org/