changeset 2:5559e0734c8c

discriminate on From address; give a real version
author k0s <k0scist@gmail.com>
date Mon, 18 Jan 2010 15:37:59 -0500
parents 2c76525ce80b
children 99532babf06f
files emaildispatcher/main.py setup.py
diffstat 2 files changed, 16 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/emaildispatcher/main.py	Thu Dec 31 00:26:33 2009 -0500
+++ b/emaildispatcher/main.py	Mon Jan 18 15:37:59 2010 -0500
@@ -24,31 +24,38 @@
                       help="list available handlers")
     options, args = parser.parse_args(args)
 
+    # get the handlers
     handlers = {}
     for handler in iter_entry_points('email.dispatchers'):
         try:
             handlers[handler.name] = handler.load()
         except:
             pass
-
     if options.list_handlers:
         for handler in sorted(handlers.keys()):
             print handler
         sys.exit(0)
-
     assert options.handler
 
-    kwargs = dict([arg.split('=', 1) for arg in args if '=' in arg])
-    args = [arg for arg in args if '=' not in arg]
-
-    handler = handlers[options.handler](*args, **kwargs)
-
+    # get the message
     if options.file:
         input = file(options.file).read()
     else:
         input = sys.stdin.read()
+    message = message_from_string(input)
 
-    message = message_from_string(input)
+    # test to ensure correct From address
+    if options.From:
+        if message['From'] not in options.From:
+            sys.exit(0)
+
+    ### handle the message
+    # get arguments to handler
+    kwargs = dict([arg.split('=', 1) for arg in args if '=' in arg])
+    args = [arg for arg in args if '=' not in arg]
+
+    # dispatch the message
+    handler = handlers[options.handler](*args, **kwargs)
     handler(message)
     
 
--- a/setup.py	Thu Dec 31 00:26:33 2009 -0500
+++ b/setup.py	Mon Jan 18 15:37:59 2010 -0500
@@ -1,7 +1,7 @@
 from setuptools import setup, find_packages
 import sys, os
 
-version = '0.0'
+version = '0.1'
 
 setup(name='emaildispatcher',
       version=version,