[IMP] mail: improved openerp_mailgate.py script which uses message_catchall method.
bzr revid: tpa@tinyerp.com-20120629045824-xgo1y5i22gmlhdbk
This commit is contained in:
parent
b49db1b76e
commit
f80b469624
|
@ -94,32 +94,21 @@ class RPCProxy(object):
|
|||
return self.rpc.execute(self.dbname, self.user_id, self.passwd, *request, **kwargs)
|
||||
|
||||
class EmailParser(object):
|
||||
def __init__(self, uid, password, model, email_default, dbname, host, port):
|
||||
def __init__(self, uid, password, dbname, host, port):
|
||||
self.rpc = RPCProxy(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, save_original=None):
|
||||
def parse(self, message):
|
||||
# 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 or {},
|
||||
save_original or False)
|
||||
'message_catchall',
|
||||
xmlrpclib.Binary(message))
|
||||
|
||||
def configure_parser():
|
||||
parser = optparse.OptionParser(usage='usage: %prog [options]', version='%prog v1.1')
|
||||
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.")
|
||||
"This program parse a mail from standard input and communicate ")
|
||||
parser.add_option_group(group)
|
||||
parser.add_option("-u", "--user", dest="userid",
|
||||
help="ID of the user in OpenERP",
|
||||
|
@ -127,9 +116,6 @@ def configure_parser():
|
|||
parser.add_option("-p", "--password", dest="password",
|
||||
help="Password of the user in OpenERP",
|
||||
default=config.OPENERP_DEFAULT_PASSWORD)
|
||||
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)
|
||||
|
@ -142,13 +128,6 @@ def configure_parser():
|
|||
parser.add_option("--port", dest="port",
|
||||
help="Port of the OpenERP Server",
|
||||
default=config.OPENERP_PORT)
|
||||
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
|
||||
|
||||
|
@ -162,24 +141,12 @@ def main():
|
|||
|
||||
email_parser = EmailParser(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 or {} ))
|
||||
except:
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
|
||||
try:
|
||||
email_parser.parse(msg_txt, custom_values, options.save_original or False)
|
||||
email_parser.parse(msg_txt)
|
||||
except Exception:
|
||||
msg = '\n'.join([
|
||||
'parameters',
|
||||
|
|
Loading…
Reference in New Issue