changeset 0:bbcc528508f1

initial stub for emaildispatcher framework; ultimately, this should be written in lamson but dont have the patience to learn it today
author k0s <k0scist@gmail.com>
date Wed, 30 Dec 2009 22:46:56 -0500
parents
children 2c76525ce80b
files emaildispatcher/__init__.py emaildispatcher/handlers.py emaildispatcher/main.py setup.py
diffstat 4 files changed, 83 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/emaildispatcher/__init__.py	Wed Dec 30 22:46:56 2009 -0500
@@ -0,0 +1,1 @@
+#
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/emaildispatcher/handlers.py	Wed Dec 30 22:46:56 2009 -0500
@@ -0,0 +1,9 @@
+class Images(object):
+    "extract images from an email message"
+    
+    def __init__(self, directory):
+        self.directory = directory
+
+    def __call__(self, message):
+        import pdb; pdb.set_trace()
+    
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/emaildispatcher/main.py	Wed Dec 30 22:46:56 2009 -0500
@@ -0,0 +1,42 @@
+#!/usr/bin/env python
+
+import sys
+
+from email.Message import Message
+from optparse import OptionParser
+from pkg_resources import iter_entry_points
+
+def matches_from(message, accept_from):
+    pass
+
+def main(args=sys.argv[1:]):
+    parser = OptionParser()
+    parser.add_option('-f', '--file', dest='file',
+                      help="file to read from (otherwise use stdin)")
+    parser.add_option('-F', '--from', dest='from', default=[],
+                      action='append',
+                      help="from addresses to accept")
+    parser.add_option('-H', '--handler', dest='handler', default=None,
+                      help="handler to use")
+    parser.add_option('--list-handlers', dest='list_handlers',
+                      help="list available handlers")
+    options, args = parser.parse_args(args)
+
+    vars = dict([arg.split('=, 1) for arg in args if '=' in arg])
+    args = [arg for arg in args if '=' not in arg]
+
+    handlers = {}
+    for handler in iter_entry_point('email.dispatchers'):
+        import pdb; pdb.set_trace()
+
+    if options.from:
+        input = file(options.from).read()
+    else:
+        input = sys.stdin.read()
+
+    message = Message(input)
+
+    
+
+if __name__ == '__main__':
+    main()
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/setup.py	Wed Dec 30 22:46:56 2009 -0500
@@ -0,0 +1,31 @@
+from setuptools import setup, find_packages
+import sys, os
+
+version = '0.0'
+
+setup(name='emaildispatcher',
+      version=version,
+      description='dispatches email to handlers',
+      long_description="""\
+""",
+      classifiers=[], # Get strings from http://pypi.python.org/pypi?%3Aaction=list_classifiers
+      keywords='',
+      author='Jeff Hammel',
+      author_email='k0scist@gmail.com',
+      url='http://k0s.org',
+      license='',
+      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      include_package_data=True,
+      zip_safe=False,
+      install_requires=[
+          # -*- Extra requirements: -*-
+      ],
+      entry_points="""
+      # -*- Entry points: -*-
+      [console_scripts]
+      emaildispatcher = emaildispatcher.main:main
+
+      [email.dispatchers]
+      extract_images = emaildispatcher.dispatchers:Images
+      """,
+      )