summaryrefslogtreecommitdiff
path: root/addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py
diff options
context:
space:
mode:
authorMantavya Gajjar <mga@tinyerp.com>2007-04-03 08:56:09 +0000
committerMantavya Gajjar <mga@tinyerp.com>2007-04-03 08:56:09 +0000
commitdc50b1520aaf1f66ca9199c1cd5657db62b6f3f0 (patch)
tree76c351d43e40e4b682ca183b6c817a168f01e104 /addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py
parent17314089ceadcfbfddaa9fdb818d30b6ed4e6605 (diff)
solved the bug:
if the attachfile have no name than generats random name but still problem for resolving the extension bzr revid: mga@tinyerp.com-8d8ee0a37418e732ca9e9d5393672a509df801c4
Diffstat (limited to 'addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py')
-rwxr-xr-xaddons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py34
1 files changed, 24 insertions, 10 deletions
diff --git a/addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py b/addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py
index d358d900967..1f42d1f7232 100755
--- a/addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py
+++ b/addons/crm/scripts/tinyerp-mailgate/tinyerp-mailgate.py
@@ -74,7 +74,7 @@ class email_parser(object):
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)
+ message = self.msg_body_get(msg);
data = {
'name': self._decode_header(msg['Subject']),
'description': message['body'],
@@ -83,13 +83,18 @@ class email_parser(object):
'email_cc': self._decode_header(msg['Cc'] or ''),
'canal_id': self.canal_id
}
- data.update(self.partner_get(self._decode_header(msg['From'])))
- id = self.rpc('crm.case', 'create', data)
+ try:
+ data.update(self.partner_get(self._decode_header(msg['From'])))
+ except Exception, e:
+ print e;
+ #end try
+ id = self.rpc('crm.case', 'create', data)
attachments = message['attachment'];
+
for attach in attachments:
data_attach = {
- 'name': 'Attachment : ' + attach,
+ 'name': 'Attachment : ' + str(attach),
'datas':binascii.b2a_base64(str(attachments[attach])),
'datas_fname': attach,
'description': 'Attachment comes with mail ',
@@ -113,14 +118,22 @@ class email_parser(object):
# #
def msg_body_get(self, msg):
message = {};
- message['body'] = '';
+ message['body'] = False;
message['attachment'] = {};
attachment = message['attachment'];
+ file_name = 1;
if msg.is_multipart():
for part in msg.get_payload():
if part.get_content_maintype()=='application' or part.get_content_maintype()=='image':
filename = part.get_filename();
- attachment[filename] = part.get_payload(decode=1);
+ if filename != None:
+ attachment[filename] = part.get_payload(decode=1);
+ else:
+ filename = 'attach_file'+str(file_name);
+ file_name += 1;
+ attachment[filename] = part.get_payload(decode=1);
+ #end if
+ #attachment[filename] = part.get_payload(decode=1);
# fp = open(os.path.join('/home/admin/test-src/', filename), 'wb')
# fp.write(part.get_payload(decode=1))
# fp.close()
@@ -131,6 +144,7 @@ class email_parser(object):
message['attachment'] = attachment;
else:
message['body'] = msg.get_payload(decode=1).decode(msg.get_charsets()[0])
+ message['attachment'] = None;
return message
def msg_user(self, msg, id):
@@ -276,11 +290,11 @@ if __name__ == '__main__':
parser = email_parser(options.userid, options.password, options.section, options.email, options.default, dbname=options.dbname)
print
print '-.- ICI'
- msg_txt = email.message_from_file(sys.stdin)
+ #msg_txt = email.message_from_file(sys.stdin)
- #fp = open('/home/admin/Desktop/test1.eml');
- #msg_txt = email.message_from_file(fp)
- #fp.close()
+ fp = open('/home/admin/Desktop/email1.eml');
+ msg_txt = email.message_from_file(fp)
+ fp.close()
print 'Mail Sent to ', parser.parse(msg_txt)