summaryrefslogtreecommitdiff
path: root/addons/crm/scripts
diff options
context:
space:
mode:
authorAntony Lesuisse <al@openerp.com>2010-03-17 05:30:34 +0100
committerAntony Lesuisse <al@openerp.com>2010-03-17 05:30:34 +0100
commitb6b93ef9d0eee59855f509c844bcc1a18e7bbb8d (patch)
tree8fe4820f9ee53a21a6a5fd6c7b63279aef35f052 /addons/crm/scripts
parent6b697e8569517e8d0df196a277f01d7b8520c0c0 (diff)
lead view update, name vs partner_name
mailgate do not depends on netsvc, don't catch exceptions silently, fix email regex (allow underscores and modern tlds) bzr revid: al@openerp.com-20100317043034-u7pqd2f80eur286r
Diffstat (limited to 'addons/crm/scripts')
-rwxr-xr-xaddons/crm/scripts/openerp_mailgate/openerp_mailgate.py31
1 files changed, 7 insertions, 24 deletions
diff --git a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py
index 22264710fcf..fb73bafdbe4 100755
--- a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py
+++ b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py
@@ -1,3 +1,4 @@
+#!/usr/bin/env python
# -*- coding: utf-8 -*-
##############################################################################
#
@@ -30,14 +31,7 @@ import binascii
import time, socket
-email_re = re.compile(r"""
- ([a-zA-Z][\w\.-]*[a-zA-Z0-9] # username part
- @ # mandatory @ sign
- [a-zA-Z0-9][\w\.-]* # domain must start with a letter ... Ged> why do we include a 0-9 then?
- \.
- [a-z]{2,3} # TLD
- )
- """, re.VERBOSE)
+email_re = re.compile(r"([A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6})")
case_re = re.compile(r"\[([0-9]+)\]", re.UNICODE)
command_re = re.compile("^Set-([a-z]+) *: *(.+)$", re.I + re.UNICODE)
reference_re = re.compile("<.*-tinycrm-(\\d+)@(.*)>", re.UNICODE)
@@ -124,7 +118,7 @@ def html2plaintext(html, body_id=None, encoding='utf-8'):
html += '\n\n'
html += '[%s] %s\n' % (i+1, url)
return html
-
+
class rpc_proxy(object):
def __init__(self, uid, passwd, host='localhost', port=8069, path='object', dbname='terp'):
self.rpc = xmlrpclib.ServerProxy('http://%s:%s/xmlrpc/%s' % (host, port, path))
@@ -178,11 +172,7 @@ class email_parser(object):
'user_id': False,
'description': message['body'],
}
- try:
- data.update(self.partner_get(self._decode_header(msg['From'])))
- except Exception, e:
- import netsvc
- netsvc.Logger().notifyChannel('mailgate', netsvc.LOG_ERROR, "%s" % e)
+ data.update(self.partner_get(self._decode_header(msg['From'])))
try:
id = self.rpc(self.model, 'create', data)
@@ -258,7 +248,6 @@ class email_parser(object):
message['attachment'] = attachment
#end for
return message
- #end def
def msg_user(self, msg, id):
body = self.msg_body_get(msg)
@@ -363,7 +352,7 @@ class email_parser(object):
if msg.get('Subject', ''):
del msg['Subject']
msg['Subject'] = '['+str(case_id)+'] '+subject
- msg['Message-Id'] = '<'+str(time.time())+'-tinycrm-'+str(case_id)+'@'+socket.gethostname()+'>'
+ msg['Message-Id'] = '<'+str(time.time())+'-openerpcrm-'+str(case_id)+'@'+socket.gethostname()+'>'
emails = self.rpc(self.model, 'emails_get', case_id)
priority = emails[3]
@@ -386,9 +375,7 @@ class email_parser(object):
if __name__ == '__main__':
import sys, optparse
- parser = optparse.OptionParser(
- usage='usage: %prog [options]',
- version='%prog v1.0')
+ 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 Open ERP server for case management in the CRM module.")
@@ -408,10 +395,6 @@ if __name__ == '__main__':
msg_txt = email.message_from_file(sys.stdin)
- try :
- parser.parse(msg_txt)
- except Exception, e:
- if getattr(e, 'faultCode', '') and 'Connection unexpectedly closed' in e.faultCode:
- print e
+ parser.parse(msg_txt)
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: