[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Add option to pipe outgoing mail through a command inst...



Update of /home/minion/cvsroot/src/minion/lib/mixminion/server
In directory moria.mit.edu:/tmp/cvs-serv10931/lib/mixminion/server

Modified Files:
	Modules.py 
Log Message:
Add option to pipe outgoing mail through a command instead of using SMTP

Index: Modules.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/server/Modules.py,v
retrieving revision 1.73
retrieving revision 1.74
diff -u -d -r1.73 -r1.74
--- Modules.py	6 Mar 2004 00:04:38 -0000	1.73
+++ Modules.py	19 Apr 2004 03:47:17 -0000	1.74
@@ -1076,7 +1076,8 @@
                           "7 hours for 6 days"),
                 'AddressFile' : ('ALLOW', "filename", None),
                 'RemoveContact' : ('ALLOW', None, None),
-                'SMTPServer' : ('ALLOW', None, 'localhost'),
+                'SMTPServer' : ('ALLOW', None, None),
+                'SendmailCommand' : ('ALLOW', "command", None),
                 }
         cfg.update(MailBase.COMMON_OPTIONS)
         return { "Delivery/MBOX" : cfg }
@@ -1085,8 +1086,7 @@
         sec = config['Delivery/MBOX']
         if not sec.get('Enabled'):
             return
-        for field in ['AddressFile', 'ReturnAddress', 'RemoveContact',
-                      'SMTPServer']:
+        for field in ['AddressFile', 'ReturnAddress', 'RemoveContact']:
             if not sec.get(field):
                 raise ConfigError("Missing field %s in [Delivery/MBOX]"%field)
         if not os.path.exists(sec['AddressFile']):
@@ -1096,6 +1096,9 @@
             if not isSMTPMailbox(sec[field]):
                 LOG.warn("Value of %s (%s) doesn't look like an email address",
                          field, sec[field])
+        if (sec['SMTPServer'] is not None and
+            sec['SendmailCommand'] is not None):
+            raise ConfigError("Cannot specify both SMTPServer and SendmailCommand")
 
         config.validateRetrySchedule("Delivery/MBOX")
 
@@ -1105,15 +1108,14 @@
             return
 
         sec = config['Delivery/MBOX']
-        self.server = sec['SMTPServer']
+        self.cfgSection = sec.copy() #DOCDOC
         self.addressFile = sec['AddressFile']
         self.returnAddress = sec['ReturnAddress']
         self.contact = sec['RemoveContact']
         self.retrySchedule = sec['Retry']
         self.allowFromAddr = sec['AllowFromAddress']
         # validate should have caught these.
-        assert (self.server and self.addressFile and self.returnAddress
-                and self.contact)
+        assert (self.addressFile and self.returnAddress and self.contact)
 
         self.nickname = config['Server']['Nickname']
         if not self.nickname:
@@ -1187,7 +1189,7 @@
             return DELIVER_FAIL_NORETRY
 
         # Deliver the message
-        return sendSMTPMessage(self.server, [address], self.returnAddress, msg)
+        return sendSMTPMessage(self.cfgSection, [address], self.returnAddress, msg)
 
 #----------------------------------------------------------------------
 class SMTPModule(DeliveryModule, MailBase):
@@ -1222,7 +1224,6 @@
     def __init__(self):
         SMTPModule.__init__(self)
 
-
     def getRetrySchedule(self):
         return self.retrySchedule
 
@@ -1231,7 +1232,8 @@
                 'Retry': ('ALLOW', "intervalList",
                           "7 hours for 6 days"),
                 'BlacklistFile' : ('ALLOW', "filename", None),
-                'SMTPServer' : ('ALLOW', None, 'localhost'),
+                'SMTPServer' : ('ALLOW', None, None),
+                'SendmailCommand' : ('ALLOW', "command", None),
                 }
         cfg.update(MailBase.COMMON_OPTIONS)
         return { "Delivery/SMTP" : cfg }
@@ -1240,7 +1242,7 @@
         sec = config['Delivery/SMTP']
         if not sec.get('Enabled'):
             return
-        for field in 'SMTPServer', 'ReturnAddress':
+        for field in ('ReturnAddress',):
             if not sec.get(field):
                 raise ConfigError("Missing field %s in [Delivery/SMTP]"%field)
         fn = sec.get('BlacklistFile')
@@ -1249,6 +1251,9 @@
         if not isSMTPMailbox(sec['ReturnAddress']):
             LOG.warn("Return address (%s) doesn't look like an email address",
                      sec['ReturnAddress'])
+        if (sec['SMTPServer'] is not None and
+            sec['SendmailCommand'] is not None):
+            raise ConfigError("Cannot specify both SMTPServer and SendmailCommand")
 
         config.validateRetrySchedule("Delivery/SMTP")
 
@@ -1258,7 +1263,7 @@
             manager.disableModule(self)
             return
 
-        self.server = sec['SMTPServer']
+        self.cfgSection = sec.copy() #DOCDOC
         self.retrySchedule = sec['Retry']
         if sec['BlacklistFile']:
             self.blacklist = EmailAddressSet(fname=sec['BlacklistFile'])
@@ -1296,7 +1301,7 @@
             return DELIVER_FAIL_NORETRY
 
         # Send the message.
-        return sendSMTPMessage(self.server, [address], self.returnAddress, msg)
+        return sendSMTPMessage(self.cfgSection, [address], self.returnAddress, msg)
 
 class MixmasterSMTPModule(SMTPModule):
     """Implements SMTP by relaying messages via Mixmaster nodes.  This
@@ -1433,27 +1438,37 @@
 
 #----------------------------------------------------------------------
 
-def sendSMTPMessage(server, toList, fromAddr, message):
+def sendSMTPMessage(cfgSection, toList, fromAddr, message):
     """Send a single SMTP message.  The message will be delivered to
        toList, and seem to originate from fromAddr.  We use 'server' as an
-       MTA."""
+       MTA.
+       DOCDOC
+    """
     # FFFF This implementation can stall badly if we don't have a fast
     # FFFF local MTA.
 
     # FFFF We should leave the connection open if we're going to send many
     # FFFF messages in a row.
-    LOG.debug("Sending message via SMTP host %s to %s", server, toList)
-    con = smtplib.SMTP(server)
-    try:
-        con.sendmail(fromAddr, toList, message)
-        res = DELIVER_OK
-    except (smtplib.SMTPException, socket.error), e:
-        LOG.warn("Unsuccessful SMTP connection to %s: %s",
-                 server, str(e))
-        res = DELIVER_FAIL_RETRY
+    if cfgSection['SendmailCommand'] is not None:
+        cmd, opts = cfgSection['SendmailCommand']
+        command = cmd + (" ".join(opts))
+        f = os.popen(command, 'w')
+        f.write(message)
+        f.close()
+    else:
+        server = cfgSection.get('SMTPServer','localhost')
+        LOG.debug("Sending message via SMTP host %s to %s", server, toList)
+        con = smtplib.SMTP(server)
+        try:
+            con.sendmail(fromAddr, toList, message)
+            res = DELIVER_OK
+        except (smtplib.SMTPException, socket.error), e:
+            LOG.warn("Unsuccessful SMTP connection to %s: %s",
+                     server, str(e))
+            res = DELIVER_FAIL_RETRY
 
-    con.quit()
-    con.close()
+        con.quit()
+        con.close()
 
     return res