for case in cases:
attachments = []
- if attach:
- for att in attach:
- if isinstance(att,(int,long)):
- attachments.append(att)
- elif isinstance(att,dict):
- attachments.append(att_obj.create(cr, uid, {'res_model':case._name,'res_id':case.id,'name': att[0], 'datas': base64.encodestring(att[1])}))
+ for att in attach:
+ if isinstance(att,(int,long)):
+ attachments.append(att)
+ elif isinstance(att,dict):
+ domain = [
+ ('name', '=', att[0]),
+ ('res_id', '=', case.id),
+ ('res_model', '=', case._name)
+ ]
+ att_ids = att_obj.search(cr, uid, domain, context=context)
+
+ if att_ids:
+ attachments.extend(att_ids)
+ else:
+ values = {
+ 'res_model' : case._name,
+ 'res_id' : case.id,
+ 'name' : att[0],
+ 'datas' : base64.encodestring(att[1])
+ }
+ attachment_id = att_obj.create(cr, uid, values, context=context)
+ attachments.append(attachment_id)
+
partner_id = hasattr(case, 'partner_id') and (case.partner_id and case.partner_id.id or False) or False
if not partner_id and case._name == 'res.partner':
partner_id = case.id
if isinstance(param, list):
param = ", ".join(param)
- data = {
+ data.update({
'name': subject or _('History'),
'history': True,
- 'user_id': uid,
- 'model' : case._name,
- 'res_id': case.id,
'date': email_date or time.strftime('%Y-%m-%d %H:%M:%S'),
- 'description': details or (hasattr(case, 'description') and case.description or False),
'email_to': email,
'email_from': email_from or \
(hasattr(case, 'user_id') and case.user_id and case.user_id.address_id and \
case.user_id.address_id.email),
'email_cc': email_cc,
'email_bcc': email_bcc,
- 'partner_id': partner_id,
'references': references,
- 'message_id': message_id,
- 'attachment_ids': [(6, 0, attachments)]
- }
+ })
obj.create(cr, uid, data, context=context)
return True
mailgate_thread()
action_data = False
action_pool = self.pool.get('ir.actions.act_window')
message_pool = self.browse(cr ,uid, ids, context=context)[0]
- att_ids = [x.id for x in message_pool.attachment_ids]
+ att_ids = [x.id for x in message_pool.attachment_ids]
action_ids = action_pool.search(cr, uid, [('res_model', '=', 'ir.attachment')])
if action_ids:
action_data = action_pool.read(cr, uid, action_ids[0], context=context)
'res_id': res_id,
}
att_ids.append(self.pool.get('ir.attachment').create(cr, uid, data_attach))
+
return res_id, att_ids
# Warning: message_from_string doesn't always work correctly on unicode,
elif part.get_content_subtype() == 'plain':
body = content
has_plain_text = True
- elif part.get_content_maintype() in ('application', 'image'):
+ elif part.get_content_maintype() in ('application', 'image') \
+ or part.get_content_subtype() in ('octet-stream'):
if filename :
attachments[filename] = part.get_payload(decode=True)
else: