2010-03-17 04:30:34 +00:00
|
|
|
#!/usr/bin/env python
|
2009-10-13 05:58:37 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-06-16 11:00:21 +00:00
|
|
|
##############################################################################
|
2009-10-14 11:15:34 +00:00
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
2010-01-12 09:18:39 +00:00
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
2008-06-16 11:00:21 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# This program is free software: you can redistribute it and/or modify
|
2009-10-14 11:15:34 +00:00
|
|
|
# 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.
|
2008-06-16 11:00:21 +00:00
|
|
|
#
|
2008-11-03 19:18:56 +00:00
|
|
|
# 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
|
2009-10-14 11:15:34 +00:00
|
|
|
# GNU Affero General Public License for more details.
|
2008-06-16 11:00:21 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2008-06-16 11:00:21 +00:00
|
|
|
#
|
2009-10-14 11:15:34 +00:00
|
|
|
###########################################################################################
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
import re
|
|
|
|
import smtplib
|
|
|
|
import email, mimetypes
|
|
|
|
from email.Header import decode_header
|
|
|
|
from email.MIMEText import MIMEText
|
|
|
|
import xmlrpclib
|
2007-04-02 09:40:45 +00:00
|
|
|
import os
|
2007-04-02 11:29:16 +00:00
|
|
|
import binascii
|
2007-08-01 14:04:09 +00:00
|
|
|
import time, socket
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2010-03-10 06:55:07 +00:00
|
|
|
|
2010-03-17 04:30:34 +00:00
|
|
|
email_re = re.compile(r"([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6})")
|
2007-08-01 14:03:50 +00:00
|
|
|
case_re = re.compile(r"\[([0-9]+)\]", re.UNICODE)
|
2006-12-07 13:41:40 +00:00
|
|
|
command_re = re.compile("^Set-([a-z]+) *: *(.+)$", re.I + re.UNICODE)
|
2007-08-10 06:13:13 +00:00
|
|
|
reference_re = re.compile("<.*-tinycrm-(\\d+)@(.*)>", re.UNICODE)
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
priorities = {
|
2010-03-08 13:49:55 +00:00
|
|
|
'1': '1 (Highest)',
|
|
|
|
'2': '2 (High)',
|
|
|
|
'3': '3 (Normal)',
|
|
|
|
'4': '4 (Low)',
|
|
|
|
'5': '5 (Lowest)',
|
2006-12-07 13:41:40 +00:00
|
|
|
}
|
|
|
|
|
2009-10-27 12:27:46 +00:00
|
|
|
def html2plaintext(html, body_id=None, encoding='utf-8'):
|
|
|
|
## (c) Fry-IT, www.fry-it.com, 2007
|
|
|
|
## <peter@fry-it.com>
|
|
|
|
## download here: http://www.peterbe.com/plog/html2plaintext
|
|
|
|
|
|
|
|
|
|
|
|
""" from an HTML text, convert the HTML to plain text.
|
|
|
|
If @body_id is provided then this is the tag where the
|
|
|
|
body (not necessarily <body>) starts.
|
|
|
|
"""
|
|
|
|
try:
|
|
|
|
from BeautifulSoup import BeautifulSoup, SoupStrainer, Comment
|
|
|
|
except:
|
|
|
|
return html
|
|
|
|
|
|
|
|
urls = []
|
|
|
|
if body_id is not None:
|
|
|
|
strainer = SoupStrainer(id=body_id)
|
|
|
|
else:
|
|
|
|
strainer = SoupStrainer('body')
|
|
|
|
|
|
|
|
soup = BeautifulSoup(html, parseOnlyThese=strainer, fromEncoding=encoding)
|
|
|
|
for link in soup.findAll('a'):
|
|
|
|
title = link.renderContents()
|
|
|
|
for url in [x[1] for x in link.attrs if x[0]=='href']:
|
|
|
|
urls.append(dict(url=url, tag=str(link), title=title))
|
|
|
|
|
|
|
|
html = soup.__str__()
|
|
|
|
|
|
|
|
url_index = []
|
|
|
|
i = 0
|
|
|
|
for d in urls:
|
|
|
|
if d['title'] == d['url'] or 'http://'+d['title'] == d['url']:
|
|
|
|
html = html.replace(d['tag'], d['url'])
|
|
|
|
else:
|
|
|
|
i += 1
|
|
|
|
html = html.replace(d['tag'], '%s [%s]' % (d['title'], i))
|
|
|
|
url_index.append(d['url'])
|
|
|
|
|
2010-03-08 13:49:55 +00:00
|
|
|
html = html.replace('<strong>', '*').replace('</strong>', '*')
|
|
|
|
html = html.replace('<b>', '*').replace('</b>', '*')
|
|
|
|
html = html.replace('<h3>', '*').replace('</h3>', '*')
|
|
|
|
html = html.replace('<h2>', '**').replace('</h2>', '**')
|
|
|
|
html = html.replace('<h1>', '**').replace('</h1>', '**')
|
|
|
|
html = html.replace('<em>', '/').replace('</em>', '/')
|
2009-10-27 12:27:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
# the only line breaks we respect is those of ending tags and
|
|
|
|
# breaks
|
|
|
|
|
2010-03-08 13:49:55 +00:00
|
|
|
html = html.replace('\n', ' ')
|
2009-10-27 12:27:46 +00:00
|
|
|
html = html.replace('<br>', '\n')
|
|
|
|
html = html.replace('<tr>', '\n')
|
|
|
|
html = html.replace('</p>', '\n\n')
|
|
|
|
html = re.sub('<br\s*/>', '\n', html)
|
|
|
|
html = html.replace(' ' * 2, ' ')
|
|
|
|
|
|
|
|
|
|
|
|
# for all other tags we failed to clean up, just remove then and
|
|
|
|
# complain about them on the stderr
|
|
|
|
def desperate_fixer(g):
|
|
|
|
#print >>sys.stderr, "failed to clean up %s" % str(g.group())
|
|
|
|
return ' '
|
|
|
|
|
|
|
|
html = re.sub('<.*?>', desperate_fixer, html)
|
|
|
|
|
|
|
|
# lstrip all lines
|
|
|
|
html = '\n'.join([x.lstrip() for x in html.splitlines()])
|
|
|
|
|
|
|
|
for i, url in enumerate(url_index):
|
|
|
|
if i == 0:
|
|
|
|
html += '\n\n'
|
|
|
|
html += '[%s] %s\n' % (i+1, url)
|
|
|
|
return html
|
2010-03-17 04:30:34 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
class rpc_proxy(object):
|
2009-10-27 12:27:46 +00:00
|
|
|
def __init__(self, uid, passwd, host='localhost', port=8069, path='object', dbname='terp'):
|
2008-10-10 10:04:21 +00:00
|
|
|
self.rpc = xmlrpclib.ServerProxy('http://%s:%s/xmlrpc/%s' % (host, port, path))
|
2008-07-22 15:11:28 +00:00
|
|
|
self.user_id = uid
|
|
|
|
self.passwd = passwd
|
|
|
|
self.dbname = dbname
|
2007-04-02 09:40:45 +00:00
|
|
|
|
2010-03-09 14:13:53 +00:00
|
|
|
def __call__(self, *request, **kwargs):
|
|
|
|
return self.rpc.execute(self.dbname, self.user_id, self.passwd, *request, **kwargs)
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
class email_parser(object):
|
2010-03-08 13:49:55 +00:00
|
|
|
def __init__(self, uid, password, model, email, email_default, dbname, host, port):
|
2009-10-27 12:27:46 +00:00
|
|
|
self.rpc = rpc_proxy(uid, password, host=host, port=port, dbname=dbname)
|
2008-07-22 15:11:28 +00:00
|
|
|
try:
|
2010-03-08 13:49:55 +00:00
|
|
|
self.model_id = int(model)
|
|
|
|
self.model = str(model)
|
2008-07-22 15:11:28 +00:00
|
|
|
except:
|
2010-03-08 13:49:55 +00:00
|
|
|
self.model_id = self.rpc('ir.model', 'search', [('model', '=', model)])[0]
|
|
|
|
self.model = str(model)
|
2008-07-22 15:11:28 +00:00
|
|
|
self.email = email
|
|
|
|
self.email_default = email_default
|
|
|
|
self.canal_id = False
|
|
|
|
|
|
|
|
def email_get(self, email_from):
|
|
|
|
res = email_re.search(email_from)
|
|
|
|
return res and res.group(1)
|
|
|
|
|
|
|
|
def partner_get(self, email):
|
|
|
|
mail = self.email_get(email)
|
|
|
|
adr_ids = self.rpc('res.partner.address', 'search', [('email', '=', mail)])
|
|
|
|
if not adr_ids:
|
|
|
|
return {}
|
|
|
|
adr = self.rpc('res.partner.address', 'read', adr_ids, ['partner_id'])
|
|
|
|
return {
|
2010-03-08 13:49:55 +00:00
|
|
|
'partner_address_id': adr[0]['id'],
|
|
|
|
'partner_id': adr[0].get('partner_id', False) and adr[0]['partner_id'][0] or False
|
2008-07-22 15:11:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
def _decode_header(self, s):
|
|
|
|
from email.Header import decode_header
|
|
|
|
s = decode_header(s)
|
|
|
|
return ''.join(map(lambda x:x[0].decode(x[1] or 'ascii', 'replace'), s))
|
|
|
|
|
|
|
|
def msg_new(self, msg):
|
|
|
|
message = self.msg_body_get(msg)
|
|
|
|
data = {
|
2010-03-08 13:49:55 +00:00
|
|
|
'name': self._decode_header(msg['Subject']),
|
|
|
|
'email_from': self._decode_header(msg['From']),
|
|
|
|
'email_cc': self._decode_header(msg['Cc'] or ''),
|
|
|
|
'canal_id': self.canal_id,
|
|
|
|
'user_id': False,
|
|
|
|
'description': message['body'],
|
2008-07-22 15:11:28 +00:00
|
|
|
}
|
2010-03-17 04:30:34 +00:00
|
|
|
data.update(self.partner_get(self._decode_header(msg['From'])))
|
2008-07-22 15:11:28 +00:00
|
|
|
|
2009-07-22 13:16:10 +00:00
|
|
|
try:
|
2010-03-08 13:49:55 +00:00
|
|
|
id = self.rpc(self.model, 'create', data)
|
2010-03-19 10:51:46 +00:00
|
|
|
self.rpc(self.model, 'history', [id], 'Receive', True, msg['From'], message['body'])
|
|
|
|
#self.rpc(self.model, 'case_open', [id])
|
2010-03-08 13:49:55 +00:00
|
|
|
except Exception, e:
|
|
|
|
if getattr(e, 'faultCode', '') and 'AccessError' in e.faultCode:
|
2009-07-22 13:16:10 +00:00
|
|
|
e = '\n\nThe Specified user does not have an access to the CRM case.'
|
|
|
|
print e
|
2008-07-22 15:11:28 +00:00
|
|
|
attachments = message['attachment']
|
|
|
|
|
|
|
|
for attach in attachments or []:
|
|
|
|
data_attach = {
|
2010-03-08 13:49:55 +00:00
|
|
|
'name': str(attach),
|
|
|
|
'datas': binascii.b2a_base64(str(attachments[attach])),
|
|
|
|
'datas_fname': str(attach),
|
|
|
|
'description': 'Mail attachment',
|
|
|
|
'res_model': self.model,
|
2008-07-22 15:11:28 +00:00
|
|
|
'res_id': id
|
|
|
|
}
|
|
|
|
self.rpc('ir.attachment', 'create', data_attach)
|
|
|
|
|
|
|
|
return id
|
|
|
|
|
|
|
|
# #change the return type format to dictionary
|
|
|
|
# {
|
|
|
|
# 'body':'body part',
|
|
|
|
# 'attachment':{
|
|
|
|
# 'file_name':'file data',
|
|
|
|
# 'file_name':'file data',
|
|
|
|
# 'file_name':'file data',
|
|
|
|
# }
|
|
|
|
# }
|
|
|
|
# #
|
|
|
|
def msg_body_get(self, msg):
|
|
|
|
message = {};
|
2009-10-27 12:27:46 +00:00
|
|
|
message['body'] = '';
|
2008-07-22 15:11:28 +00:00
|
|
|
message['attachment'] = {};
|
|
|
|
attachment = message['attachment'];
|
|
|
|
counter = 1;
|
2009-03-24 13:46:24 +00:00
|
|
|
def replace(match):
|
|
|
|
return ''
|
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
for part in msg.walk():
|
|
|
|
if part.get_content_maintype() == 'multipart':
|
|
|
|
continue
|
|
|
|
|
2009-10-27 12:27:46 +00:00
|
|
|
if part.get_content_maintype()=='text':
|
2008-07-22 15:11:28 +00:00
|
|
|
buf = part.get_payload(decode=True)
|
|
|
|
if buf:
|
2009-03-24 13:46:24 +00:00
|
|
|
txt = buf.decode(part.get_charsets()[0] or 'ascii', 'replace')
|
|
|
|
txt = re.sub("<(\w)>", replace, txt)
|
|
|
|
txt = re.sub("<\/(\w)>", replace, txt)
|
2009-10-27 12:27:46 +00:00
|
|
|
if txt and part.get_content_subtype() == 'plain':
|
|
|
|
message['body'] += txt
|
|
|
|
elif txt and part.get_content_subtype() == 'html':
|
|
|
|
message['body'] += html2plaintext(txt)
|
|
|
|
|
2009-11-13 07:07:03 +00:00
|
|
|
filename = part.get_filename();
|
|
|
|
if filename :
|
|
|
|
attachment[filename] = part.get_payload(decode=True);
|
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
elif part.get_content_maintype()=='application' or part.get_content_maintype()=='image' or part.get_content_maintype()=='text':
|
|
|
|
filename = part.get_filename();
|
|
|
|
if filename :
|
|
|
|
attachment[filename] = part.get_payload(decode=True);
|
|
|
|
else:
|
|
|
|
filename = 'attach_file'+str(counter);
|
|
|
|
counter += 1;
|
|
|
|
attachment[filename] = part.get_payload(decode=True);
|
|
|
|
#end if
|
|
|
|
#end if
|
|
|
|
message['attachment'] = attachment
|
2009-10-27 12:27:46 +00:00
|
|
|
#end for
|
2008-07-22 15:11:28 +00:00
|
|
|
return message
|
|
|
|
|
|
|
|
def msg_user(self, msg, id):
|
|
|
|
body = self.msg_body_get(msg)
|
|
|
|
|
|
|
|
# handle email body commands (ex: Set-State: Draft)
|
|
|
|
actions = {}
|
|
|
|
body_data=''
|
|
|
|
for line in body['body'].split('\n'):
|
|
|
|
res = command_re.match(line)
|
|
|
|
if res:
|
|
|
|
actions[res.group(1).lower()] = res.group(2).lower()
|
|
|
|
else:
|
|
|
|
body_data += line+'\n'
|
|
|
|
body['body'] = body_data
|
|
|
|
|
|
|
|
data = {
|
2010-03-08 13:49:55 +00:00
|
|
|
'description': body['body'],
|
2008-07-22 15:11:28 +00:00
|
|
|
}
|
2009-10-28 11:46:16 +00:00
|
|
|
act = 'case_pending'
|
2008-07-22 15:11:28 +00:00
|
|
|
if 'state' in actions:
|
2010-03-08 13:49:55 +00:00
|
|
|
if actions['state'] in ['draft', 'close', 'cancel', 'open', 'pending']:
|
2008-07-22 15:11:28 +00:00
|
|
|
act = 'case_' + actions['state']
|
|
|
|
|
2010-03-08 13:49:55 +00:00
|
|
|
for k1, k2 in [('cost', 'planned_cost'), ('revenue', 'planned_revenue'), ('probability', 'probability')]:
|
2008-07-22 15:11:28 +00:00
|
|
|
try:
|
|
|
|
data[k2] = float(actions[k1])
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
|
|
|
if 'priority' in actions:
|
2010-03-08 13:49:55 +00:00
|
|
|
if actions['priority'] in ('1', '2', '3', '4', '5'):
|
2008-07-22 15:11:28 +00:00
|
|
|
data['priority'] = actions['priority']
|
|
|
|
|
|
|
|
if 'partner' in actions:
|
|
|
|
data['email_from'] = actions['partner'][:128]
|
|
|
|
|
|
|
|
if 'user' in actions:
|
|
|
|
uids = self.rpc('res.users', 'name_search', actions['user'])
|
|
|
|
if uids:
|
|
|
|
data['user_id'] = uids[0][0]
|
|
|
|
|
2010-03-08 13:49:55 +00:00
|
|
|
self.rpc(self.model, act, [id])
|
|
|
|
self.rpc(self.model, 'write', [id], data)
|
2010-03-19 10:51:46 +00:00
|
|
|
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], message['body'])
|
2008-07-22 15:11:28 +00:00
|
|
|
return id
|
|
|
|
|
|
|
|
def msg_send(self, msg, emails, priority=None):
|
|
|
|
if not len(emails):
|
|
|
|
return False
|
|
|
|
del msg['To']
|
|
|
|
msg['To'] = emails[0]
|
|
|
|
if len(emails)>1:
|
|
|
|
if 'Cc' in msg:
|
|
|
|
del msg['Cc']
|
|
|
|
msg['Cc'] = ','.join(emails[1:])
|
|
|
|
del msg['Reply-To']
|
|
|
|
msg['Reply-To'] = self.email
|
|
|
|
if priority:
|
|
|
|
msg['X-Priority'] = priorities.get(priority, '3 (Normal)')
|
|
|
|
s = smtplib.SMTP()
|
|
|
|
s.connect()
|
|
|
|
s.sendmail(self.email, emails, msg.as_string())
|
|
|
|
s.close()
|
|
|
|
return True
|
|
|
|
|
|
|
|
def msg_partner(self, msg, id):
|
|
|
|
message = self.msg_body_get(msg)
|
|
|
|
body = message['body']
|
|
|
|
act = 'case_open'
|
2010-03-08 13:49:55 +00:00
|
|
|
self.rpc(self.model, act, [id])
|
2008-07-22 15:11:28 +00:00
|
|
|
body2 = '\n'.join(map(lambda l: '> '+l, (body or '').split('\n')))
|
|
|
|
data = {
|
2010-03-08 13:49:55 +00:00
|
|
|
'description':body,
|
2008-07-22 15:11:28 +00:00
|
|
|
}
|
2010-03-08 13:49:55 +00:00
|
|
|
self.rpc(self.model, 'write', [id], data)
|
2010-03-19 10:51:46 +00:00
|
|
|
self.rpc(self.model, 'history', [id], 'Send', True, msg['From'], message['body'])
|
2008-07-22 15:11:28 +00:00
|
|
|
return id
|
|
|
|
|
|
|
|
def msg_test(self, msg, case_str):
|
|
|
|
if not case_str:
|
|
|
|
return (False, False)
|
2010-03-08 13:49:55 +00:00
|
|
|
emails = self.rpc(self.model, 'emails_get', int(case_str))
|
2008-07-22 15:11:28 +00:00
|
|
|
return (int(case_str), emails)
|
|
|
|
|
|
|
|
def parse(self, msg):
|
|
|
|
case_str = reference_re.search(msg.get('References', ''))
|
|
|
|
if case_str:
|
|
|
|
case_str = case_str.group(1)
|
|
|
|
else:
|
|
|
|
case_str = case_re.search(msg.get('Subject', ''))
|
|
|
|
if case_str:
|
|
|
|
case_str = case_str.group(1)
|
|
|
|
(case_id, emails) = self.msg_test(msg, case_str)
|
|
|
|
if case_id:
|
|
|
|
if emails[0] and self.email_get(emails[0])==self.email_get(self._decode_header(msg['From'])):
|
|
|
|
self.msg_user(msg, case_id)
|
|
|
|
else:
|
|
|
|
self.msg_partner(msg, case_id)
|
|
|
|
else:
|
|
|
|
case_id = self.msg_new(msg)
|
|
|
|
subject = self._decode_header(msg['subject'])
|
|
|
|
if msg.get('Subject', ''):
|
|
|
|
del msg['Subject']
|
|
|
|
msg['Subject'] = '['+str(case_id)+'] '+subject
|
2010-03-17 04:30:34 +00:00
|
|
|
msg['Message-Id'] = '<'+str(time.time())+'-openerpcrm-'+str(case_id)+'@'+socket.gethostname()+'>'
|
2008-07-22 15:11:28 +00:00
|
|
|
|
2010-03-08 13:49:55 +00:00
|
|
|
emails = self.rpc(self.model, 'emails_get', case_id)
|
2008-07-22 15:11:28 +00:00
|
|
|
priority = emails[3]
|
|
|
|
em = [emails[0], emails[1]] + (emails[2] or '').split(',')
|
|
|
|
emails = map(self.email_get, filter(None, em))
|
|
|
|
|
2010-03-08 13:49:55 +00:00
|
|
|
mm = [self._decode_header(msg['From']), self._decode_header(msg['To'])]+self._decode_header(msg.get('Cc', '')).split(',')
|
2008-07-22 15:11:28 +00:00
|
|
|
msg_mails = map(self.email_get, filter(None, mm))
|
|
|
|
|
|
|
|
emails = filter(lambda m: m and m not in msg_mails, emails)
|
|
|
|
try:
|
|
|
|
self.msg_send(msg, emails, priority)
|
|
|
|
except:
|
|
|
|
if self.email_default:
|
|
|
|
a = self._decode_header(msg['Subject'])
|
|
|
|
del msg['Subject']
|
2008-11-14 16:12:27 +00:00
|
|
|
msg['Subject'] = '[OpenERP-CaseError] ' + a
|
2008-07-22 15:11:28 +00:00
|
|
|
self.msg_send(msg, self.email_default.split(','))
|
2009-10-27 12:27:46 +00:00
|
|
|
return case_id, emails
|
2006-12-07 13:41:40 +00:00
|
|
|
|
|
|
|
if __name__ == '__main__':
|
2008-07-22 15:11:28 +00:00
|
|
|
import sys, optparse
|
2010-03-19 10:51:46 +00:00
|
|
|
parser = optparse.OptionParser(usage='usage: %prog [options]', version='%prog v1.0')
|
2010-03-08 13:49:55 +00:00
|
|
|
group = optparse.OptionGroup(parser, "Note",
|
2008-07-22 15:11:28 +00:00
|
|
|
"This program parse a mail from standard input and communicate "
|
2008-12-10 22:55:43 +00:00
|
|
|
"with the Open ERP server for case management in the CRM module.")
|
2008-07-22 15:11:28 +00:00
|
|
|
parser.add_option_group(group)
|
2009-09-14 13:10:25 +00:00
|
|
|
parser.add_option("-u", "--user", dest="userid", help="ID of the user in Open ERP", default=1, type='int')
|
2008-12-10 22:55:43 +00:00
|
|
|
parser.add_option("-p", "--password", dest="password", help="Password of the user in Open ERP", default='admin')
|
2008-07-22 15:11:28 +00:00
|
|
|
parser.add_option("-e", "--email", dest="email", help="Email address used in the From field of outgoing messages")
|
2010-03-08 13:49:55 +00:00
|
|
|
parser.add_option("-o", "--model", dest="model", help="Name or ID of crm model", default="crm.lead")
|
2008-07-22 15:11:28 +00:00
|
|
|
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: terp)", default='terp')
|
2009-10-09 05:21:00 +00:00
|
|
|
parser.add_option("--host", dest="host", help="Hostname of the Open ERP Server", default="localhost")
|
2009-10-27 12:27:46 +00:00
|
|
|
parser.add_option("--port", dest="port", help="Port of the Open ERP Server", default="8069")
|
2009-10-08 13:40:36 +00:00
|
|
|
|
2006-12-07 13:41:40 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
(options, args) = parser.parse_args()
|
2010-03-08 13:49:55 +00:00
|
|
|
parser = email_parser(options.userid, options.password, options.model, options.email, options.default, dbname=options.dbname, host=options.host, port=options.port)
|
2007-04-13 10:43:49 +00:00
|
|
|
|
2008-07-22 15:11:28 +00:00
|
|
|
msg_txt = email.message_from_file(sys.stdin)
|
2007-04-13 10:45:40 +00:00
|
|
|
|
2010-03-17 04:30:34 +00:00
|
|
|
parser.parse(msg_txt)
|
2009-07-22 13:16:10 +00:00
|
|
|
|
2010-03-19 10:51:46 +00:00
|
|
|
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|