Back to index

moin  1.9.0~rc2
mailimport.py
Go to the documentation of this file.
00001 # -*- coding: iso-8859-1 -*-
00002 """
00003 MoinMoin - MailImport script
00004 
00005 @copyright: 2006 MoinMoin:AlexanderSchremmer
00006 @license: GNU GPL, see COPYING for details.
00007 """
00008 
00009 import sys
00010 import xmlrpclib
00011 
00012 from MoinMoin.script import MoinScript, fatal
00013 
00014 input = sys.stdin
00015 
00016 class PluginScript(MoinScript):
00017     """\
00018 Purpose:
00019 ========
00020 This tool allows you to import mail into the wiki.
00021 
00022 Detailed Instructions:
00023 ======================
00024 General syntax: moin [options] maint mailimport [mailimport-options]
00025 
00026 [options] usually should be:
00027     --config-dir=/path/to/my/cfg/ --wiki-url=wiki.example.org/
00028 
00029 [mailimport-options] see below:
00030     0. Verify that you have a mailimportconf.py configuration file.
00031 
00032     1. To import mail from the file '/mymail'
00033        moin ... xmlrpc mailimport << /mymail
00034        OR
00035        cat /mymail | moin ... xmlrpc mailimport
00036 """
00037 
00038     def __init__(self, argv, def_values):
00039         MoinScript.__init__(self, argv, def_values)
00040 
00041     def mainloop(self):
00042         try:
00043             import mailimportconf
00044         except ImportError:
00045             fatal("Could not find the file mailimportconf.py. Maybe you want to use the --config-dir=... option?")
00046 
00047         secret = mailimportconf.mail_import_secret
00048         url = mailimportconf.mail_import_url
00049 
00050         s = xmlrpclib.ServerProxy(url)
00051 
00052         result = s.ProcessMail(secret, xmlrpclib.Binary(input.read()))
00053 
00054         if result != "OK":
00055             print >> sys.stderr, result
00056