summaryrefslogtreecommitdiff
path: root/addons/crm/scripts
diff options
context:
space:
mode:
authorHarry (Open ERP) <hmo@tinyerp.com>2010-03-17 11:31:45 +0530
committerHarry (Open ERP) <hmo@tinyerp.com>2010-03-17 11:31:45 +0530
commit586a4ef79aa7f87ea55ccc44c727eaffb53c730b (patch)
tree9d6e447af4e1662a6eb451fd73a27fecb9599c25 /addons/crm/scripts
parent0db347d65f9c67f4b114a96874ea120cf7eacdee (diff)
parentb6b93ef9d0eee59855f509c844bcc1a18e7bbb8d (diff)
[MERGE] from lp:~openerp/openobject-addons/trunk/
bzr revid: hmo@tinyerp.com-20100317060145-grxjqr8b90u4nn5d
Diffstat (limited to 'addons/crm/scripts')
-rwxr-xr-xaddons/crm/scripts/openerp_mailgate/openerp_mailgate.py32
1 files changed, 8 insertions, 24 deletions
diff --git a/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py b/addons/crm/scripts/openerp_mailgate/openerp_mailgate.py
index 27b84e4941b..a81c2a5776d 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 -*-
##############################################################################
#
@@ -29,14 +30,8 @@ import os
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)
@@ -123,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))
@@ -177,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)
@@ -257,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)
@@ -362,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]
@@ -385,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.")
@@ -407,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: