From 47a85e9f8f0fadf16d679a2f1fdbef0ef1c59440 Mon Sep 17 00:00:00 2001 From: "Rifakat Haradwala (Open ERP)" Date: Mon, 4 Apr 2011 15:15:52 +0530 Subject: [IMP] mail: rename module email to mail because of parsing error bzr revid: rha@tinyerp.com-20110404094552-j2rdq2sbeqrbffgn --- addons/mail/scripts/__init__.py | 24 ++++++ addons/mail/scripts/openerp_mailgate/__init__.py | 22 +++++ .../scripts/openerp_mailgate/openerp_mailgate.py | 94 ++++++++++++++++++++++ 3 files changed, 140 insertions(+) create mode 100644 addons/mail/scripts/__init__.py create mode 100644 addons/mail/scripts/openerp_mailgate/__init__.py create mode 100644 addons/mail/scripts/openerp_mailgate/openerp_mailgate.py (limited to 'addons/mail/scripts') diff --git a/addons/mail/scripts/__init__.py b/addons/mail/scripts/__init__.py new file mode 100644 index 00000000000..9d7f6bf56c9 --- /dev/null +++ b/addons/mail/scripts/__init__.py @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import openerp_mailgate + + diff --git a/addons/mail/scripts/openerp_mailgate/__init__.py b/addons/mail/scripts/openerp_mailgate/__init__.py new file mode 100644 index 00000000000..4f7fae0a190 --- /dev/null +++ b/addons/mail/scripts/openerp_mailgate/__init__.py @@ -0,0 +1,22 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2010 Tiny SPRL (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +import openerp_mailgate diff --git a/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py b/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py new file mode 100644 index 00000000000..68e9a0849db --- /dev/null +++ b/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py @@ -0,0 +1,94 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# Copyright (C) 2004-2009 Tiny SPRL (). +# Copyright (C) 2010-TODAY OpenERP S.A. (http://www.openerp.com) +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see +# +########################################################################################### + +import logging +import optparse +import sys +import xmlrpclib + +class rpc_proxy(object): + def __init__(self, uid, passwd, host='localhost', port=8069, path='object', dbname='openerp'): + self.rpc = xmlrpclib.ServerProxy('http://%s:%s/xmlrpc/%s' % (host, port, path), allow_none=True) + self.user_id = uid + self.passwd = passwd + self.dbname = dbname + + def __call__(self, *request, **kwargs): + return self.rpc.execute(self.dbname, self.user_id, self.passwd, *request, **kwargs) + +class email_parser(object): + def __init__(self, uid, password, model, email_default, dbname, host, port): + self.rpc = rpc_proxy(uid, password, host=host, port=port, dbname=dbname) + try: + self.model_id = int(model) + self.model = str(model) + except: + self.model_id = self.rpc('ir.model', 'search', [('model', '=', model)])[0] + self.model = str(model) + self.email_default = email_default + + + def parse(self, message, custom_values=None): + if custom_values is None: + custom_values = {} + try: + # pass message as bytes because we don't know its encoding until we parse its headers + # and hence can't convert it to utf-8 for transport + res_id = self.rpc('email.thread', 'process_email', self.model, xmlrpclib.Binary(message), custom_values) + except Exception: + logger = logging.getLogger('mail-gateway') + logger.warning('Failed to process incoming email. Source of the failed mail is available at debug level.', exc_info=True) + logger.debug('Source of the mail that failed to parse:', message) + +if __name__ == '__main__': + parser = optparse.OptionParser(usage='usage: %prog [options]', version='%prog v1.0') + group = optparse.OptionGroup(parser, "Note", + "This program parse a mail from standard input and communicate " + "with the OpenERP server for case management in the CRM module.") + parser.add_option_group(group) + parser.add_option("-u", "--user", dest="userid", help="ID of the user in OpenERP", default=1, type='int') + parser.add_option("-p", "--password", dest="password", help="Password of the user in OpenERP", default='admin') + parser.add_option("-o", "--model", dest="model", help="Name or ID of crm model", default="crm.lead") + parser.add_option("-m", "--default", dest="default", help="Default eMail in case of any trouble.", default=None) + parser.add_option("-d", "--dbname", dest="dbname", help="Database name (default: openerp)", default='openerp') + parser.add_option("--host", dest="host", help="Hostname of the OpenERP Server", default="localhost") + parser.add_option("--port", dest="port", help="Port of the OpenERP Server", default="8069") + parser.add_option("--custom-values", dest="custom_values", help="Add Custom Values to the object", default=None) + + (options, args) = parser.parse_args() + + logging.basicConfig(level=logging.DEBUG, format="%(asctime)s %(levelname)s %(message)s") + + parser = email_parser(options.userid, options.password, options.model, options.default, dbname=options.dbname, host=options.host, port=options.port) + + msg_txt = sys.stdin.read() + + custom_values = {} + try: + custom_values = dict(eval(options.custom_values)) + except: + pass + + parser.parse(msg_txt, custom_values) + +# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: -- cgit v1.2.3 From c996efa2fe65e87ef62e4f0f4520ee83ed9ea5cd Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Fri, 22 Jul 2011 18:34:57 +0200 Subject: [IMP] mail: another pass of cleanup/refactoring of mail features - finish renaming bzr revid: odo@openerp.com-20110722163457-7g9ngdb2p0bixcst --- addons/mail/scripts/__init__.py | 6 ++---- addons/mail/scripts/openerp_mailgate/__init__.py | 2 +- addons/mail/scripts/openerp_mailgate/openerp_mailgate.py | 2 +- 3 files changed, 4 insertions(+), 6 deletions(-) (limited to 'addons/mail/scripts') diff --git a/addons/mail/scripts/__init__.py b/addons/mail/scripts/__init__.py index 9d7f6bf56c9..3b6a8c7e4b0 100644 --- a/addons/mail/scripts/__init__.py +++ b/addons/mail/scripts/__init__.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). +# Copyright (C) 2009-2010 OpenERP SA (). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as @@ -19,6 +19,4 @@ # ############################################################################## -import openerp_mailgate - - +import openerp_mailgate \ No newline at end of file diff --git a/addons/mail/scripts/openerp_mailgate/__init__.py b/addons/mail/scripts/openerp_mailgate/__init__.py index 4f7fae0a190..de2e2bf390d 100644 --- a/addons/mail/scripts/openerp_mailgate/__init__.py +++ b/addons/mail/scripts/openerp_mailgate/__init__.py @@ -2,7 +2,7 @@ ############################################################################## # # OpenERP, Open Source Management Solution -# Copyright (C) 2004-2010 Tiny SPRL (). +# Copyright (C) 2009-2010 OpenERP SA (). # # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as diff --git a/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py b/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py index 68e9a0849db..d80da98509a 100644 --- a/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py @@ -54,7 +54,7 @@ class email_parser(object): try: # pass message as bytes because we don't know its encoding until we parse its headers # and hence can't convert it to utf-8 for transport - res_id = self.rpc('email.thread', 'process_email', self.model, xmlrpclib.Binary(message), custom_values) + res_id = self.rpc('mail.thread', 'process_email', self.model, xmlrpclib.Binary(message), custom_values) except Exception: logger = logging.getLogger('mail-gateway') logger.warning('Failed to process incoming email. Source of the failed mail is available at debug level.', exc_info=True) -- cgit v1.2.3 From b0bed63351956455a23cdc960292e104af53f67a Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Tue, 23 Aug 2011 19:58:09 +0200 Subject: [IMP] mail.thread: renaming methods to avoid collisions with objects that use the mixin bzr revid: odo@openerp.com-20110823175809-hw81fkptg90702vh --- addons/mail/scripts/openerp_mailgate/openerp_mailgate.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'addons/mail/scripts') diff --git a/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py b/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py index 24854cb1ccb..b75c92d8d34 100755 --- a/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py @@ -110,7 +110,7 @@ class EmailParser(object): # pass message as bytes because we don't know its encoding until we parse its headers # and hence can't convert it to utf-8 for transport res_id = self.rpc('mail.thread', - 'process_email', + 'message_process', self.model, xmlrpclib.Binary(message), custom_values) -- cgit v1.2.3 From 7c7c8a0348f2dd4eb8b701d2b709b3215c2b18bb Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 7 Sep 2011 17:13:48 +0200 Subject: [IMP] mail*: mail.message.original: binary field and optional bzr revid: odo@openerp.com-20110907151348-jiqfqm5cagy8bzto --- .../scripts/openerp_mailgate/openerp_mailgate.py | 27 ++++++++++++++-------- 1 file changed, 17 insertions(+), 10 deletions(-) (limited to 'addons/mail/scripts') diff --git a/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py b/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py index b75c92d8d34..7e6ba87945f 100755 --- a/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py @@ -46,13 +46,14 @@ class DefaultConfig(object): OPENERP_PORT = 8069 OPENERP_DEFAULT_DATABASE = 'openerp' MAIL_ERROR = 'error@example.com' - MAIL_SERVER = 'localhost' - MAIL_ADMINS = ('admin@example.com',) + MAIL_SERVER = 'smtp.example.com' + MAIL_SERVER_PORT = 25 + MAIL_ADMINS = ('info@example.com',) config = DefaultConfig() -def send_mail(_from_, to_, subject, text, files=None, server=config.MAIL_SERVER): +def send_mail(_from_, to_, subject, text, files=None, server=config.MAIL_SERVER, port=config.MAIL_SERVER_PORT): assert isinstance(to_, (list, tuple)) if files is None: @@ -74,7 +75,7 @@ def send_mail(_from_, to_, subject, text, files=None, server=config.MAIL_SERVER) % file_name) msg.attach(part) - smtp = smtplib.SMTP(server) + smtp = smtplib.SMTP(server, port=port) smtp.sendmail(_from_, to_, msg.as_string() ) smtp.close() @@ -104,16 +105,15 @@ class EmailParser(object): self.email_default = email_default - def parse(self, message, custom_values=None): - if custom_values is None: - custom_values = {} + def parse(self, message, custom_values=None, save_original=None): # pass message as bytes because we don't know its encoding until we parse its headers # and hence can't convert it to utf-8 for transport res_id = self.rpc('mail.thread', 'message_process', self.model, xmlrpclib.Binary(message), - custom_values) + custom_values or {}, + save_original or False) def configure_parser(): parser = optparse.OptionParser(usage='usage: %prog [options]', version='%prog v1.1') @@ -145,6 +145,10 @@ def configure_parser(): parser.add_option("--custom-values", dest="custom_values", help="Add Custom Values to the object", default=None) + parser.add_option("-s", dest="save_original", + action="store_true", + help="Attach a copy of original email to the message entry", + default=False) return parser @@ -169,12 +173,14 @@ def main(): custom_values = {} try: + print "custom vals: %s" % options.custom_values custom_values = dict(eval(options.custom_values or {} )) except: - pass + import traceback + traceback.print_exc() try: - email_parser.parse(msg_txt, custom_values) + email_parser.parse(msg_txt, custom_values, options.save_original or False) except Exception: msg = '\n'.join([ 'parameters', @@ -191,6 +197,7 @@ def main(): config.MAIL_ADMINS, subject, msg, files=[('message.txt', msg_txt)] ) + sys.stderr.write("Failed to deliver email to OpenERP Server, sending error notification to %s\n" % config.MAIL_ADMINS) if __name__ == '__main__': main() -- cgit v1.2.3 From 9c39d8b42afe158e2c53c865211d8555d7b7799e Mon Sep 17 00:00:00 2001 From: Olivier Dony Date: Wed, 7 Sep 2011 17:21:36 +0200 Subject: [REM] mail: remove debugging statement bzr revid: odo@openerp.com-20110907152136-1kbt1ntwyk3d3h0p --- addons/mail/scripts/openerp_mailgate/openerp_mailgate.py | 1 - 1 file changed, 1 deletion(-) (limited to 'addons/mail/scripts') diff --git a/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py b/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py index 7e6ba87945f..68ae20d35e3 100755 --- a/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py +++ b/addons/mail/scripts/openerp_mailgate/openerp_mailgate.py @@ -173,7 +173,6 @@ def main(): custom_values = {} try: - print "custom vals: %s" % options.custom_values custom_values = dict(eval(options.custom_values or {} )) except: import traceback -- cgit v1.2.3