diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/mail/static/scripts | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/mail/static/scripts')
| -rwxr-xr-x | addons/mail/static/scripts/odoo-mailgate.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/addons/mail/static/scripts/odoo-mailgate.py b/addons/mail/static/scripts/odoo-mailgate.py new file mode 100755 index 00000000..e4ccc3c9 --- /dev/null +++ b/addons/mail/static/scripts/odoo-mailgate.py @@ -0,0 +1,46 @@ +#!/usr/bin/env python2 +# Part of Odoo. See LICENSE file for full copyright and licensing details. +# +# odoo-mailgate +# +# This program will read an email from stdin and forward it to odoo. Configure +# a pipe alias in your mail server to use it, postfix uses a syntax that looks +# like: +# +# email@address: "|/home/odoo/src/odoo-mail.py" +# +# while exim uses a syntax that looks like: +# +# *: |/home/odoo/src/odoo-mail.py +# +# Note python2 was chosen on purpose for backward compatibility with old mail +# servers. +# +import optparse +import sys +import traceback +import xmlrpclib + +def main(): + op = optparse.OptionParser(usage='usage: %prog [options]', version='%prog v1.2') + op.add_option("-d", "--database", dest="database", help="Odoo database name (default: %default)", default='odoo') + op.add_option("-u", "--userid", dest="userid", help="Odoo user id to connect with (default: %default)", default=1, type=int) + op.add_option("-p", "--password", dest="password", help="Odoo user password (default: %default)", default='admin') + op.add_option("--host", dest="host", help="Odoo host (default: %default)", default='localhost') + op.add_option("--port", dest="port", help="Odoo port (default: %default)", default=8069, type=int) + (o, args) = op.parse_args() + + try: + msg = sys.stdin.read() + models = xmlrpclib.ServerProxy('http://%s:%s/xmlrpc/2/object' % (o.host, o.port), allow_none=True) + models.execute_kw(o.database, o.userid, o.password, 'mail.thread', 'message_process', [False, xmlrpclib.Binary(msg)], {}) + except xmlrpclib.Fault as e: + # reformat xmlrpc faults to print a readable traceback + err = "xmlrpclib.Fault: %s\n%s" % (e.faultCode, e.faultString) + sys.exit(err) + except Exception as e: + traceback.print_exc(None, sys.stderr) + sys.exit(2) + +if __name__ == '__main__': + main() |
