# TDE FIXME: commented, to be improved in a future branch
# quote_context = self.pool.get('mail.message').message_quote_context(cr, uid, msg_id, context=context)
- mail_mail = self.pool.get('mail.mail')
# add signature
body_html = msg.body
- # if quote_context:
- # body_html = tools.append_content_to_html(body_html, quote_context, plaintext=False)
- signature = msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0].signature or ''
- if signature:
- body_html = tools.append_content_to_html(body_html, signature, plaintext=True, container_tag='div')
-
- # email_from: partner-user alias or partner email or mail.message email_from
- if msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0].alias_domain and msg.author_id.user_ids[0].alias_name:
- email_from = '%s <%s@%s>' % (msg.author_id.name, msg.author_id.user_ids[0].alias_name, msg.author_id.user_ids[0].alias_domain)
- elif msg.author_id:
- email_from = '%s <%s>' % (msg.author_id.name, msg.author_id.email)
- else:
- email_from = msg.email_from
+ user_id = msg.author_id and msg.author_id.user_ids and msg.author_id.user_ids[0] and msg.author_id.user_ids[0].id or None
+ signature_company = self.get_signature_footer(cr, uid, user_id, res_model=msg.model, res_id=msg.res_id, context=context)
+ body_html = tools.append_content_to_html(body_html, signature_company, plaintext=False, container_tag='div')
+ references = False
+ if msg.parent_id:
+ references = msg.parent_id.message_id
+
mail_values = {
'mail_message_id': msg.id,
'auto_delete': True,
'body_html': body_html,
- 'recipient_ids': [(4, id) for id in notify_partner_ids]
- 'email_from': email_from,
++ 'recipient_ids': [(4, id) for id in notify_partner_ids],
+ 'references': references,
}
+ if msg.email_from:
+ mail_values['email_from'] = msg.email_from
+ if msg.reply_to:
+ mail_values['reply_to'] = msg.reply_to
+ mail_mail = self.pool.get('mail.mail')
email_notif_id = mail_mail.create(cr, uid, mail_values, context=context)
try:
- return mail_mail.send(cr, uid, [email_notif_id], recipient_ids=notify_partner_ids, context=context)
+ return mail_mail.send(cr, uid, [email_notif_id], context=context)
except Exception:
return False
'body': lambda self, cr, uid, ctx={}: '',
'subject': lambda self, cr, uid, ctx={}: False,
'partner_ids': lambda self, cr, uid, ctx={}: [],
+ 'notify': lambda self, cr, uid, ctx={}: False,
+ 'post': lambda self, cr, uid, ctx={}: True,
+ 'same_thread': lambda self, cr, uid, ctx={}: True,
}
+ def check_access_rule(self, cr, uid, ids, operation, context=None):
+ """ Access rules of mail.compose.message:
+ - create: if
+ - model, no res_id, I create a message in mass mail mode
+ - then: fall back on mail.message acces rules
+ """
+ if isinstance(ids, (int, long)):
+ ids = [ids]
+
+ # Author condition (CREATE (mass_mail))
+ if operation == 'create' and uid != SUPERUSER_ID:
+ # read mail_compose_message.ids to have their values
+ message_values = {}
+ cr.execute('SELECT DISTINCT id, model, res_id FROM "%s" WHERE id = ANY (%%s) AND res_id = 0' % self._table, (ids,))
+ for id, rmod, rid in cr.fetchall():
+ message_values[id] = {'model': rmod, 'res_id': rid}
+ # remove from the set to check the ids that mail_compose_message accepts
+ author_ids = [mid for mid, message in message_values.iteritems()
+ if message.get('model') and not message.get('res_id')]
+ ids = list(set(ids) - set(author_ids))
+
+ return super(mail_compose_message, self).check_access_rule(cr, uid, ids, operation, context=context)
+
def _notify(self, cr, uid, newid, context=None):
""" Override specific notify method of mail.message, because we do
not want that feature in the wizard. """
new_attachments = email_dict.pop('attachments', [])
post_values['attachments'] += new_attachments
post_values.update(email_dict)
+ # email_from: mass mailing only can specify another email_from
+ if email_dict.get('email_from'):
+ post_values['email_from'] = email_dict.pop('email_from')
+ # replies redirection: mass mailing only
+ if not wizard.same_thread:
+ post_values['reply_to'] = email_dict.pop('reply_to')
+ # clean the context (hint: mass mailing sets some default values that
+ # could be wrongly interpreted by mail_mail)
+ context.pop('default_email_to', None)
+ context.pop('default_partner_ids', None)
# post the message
- subtype = 'mail.mt_comment'
- if is_log: # log a note: subtype is False
- subtype = False
- elif mass_mail_mode: # mass mail: is a log pushed to recipients, author not added
- subtype = False
- context = dict(context, mail_create_nosubscribe=True) # add context key to avoid subscribing the author
- msg_id = active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
- # mass_mailing: notify specific partners, because subtype was False, and no-one was notified
- if mass_mail_mode and post_values['partner_ids']:
- self.pool.get('mail.notification')._notify(cr, uid, msg_id, post_values['partner_ids'], context=context)
+ if mass_mail_mode and not wizard.post:
+ post_values['recipient_ids'] = [(4, id) for id in post_values.pop('partner_ids', [])]
+ self.pool.get('mail.mail').create(cr, uid, post_values, context=context)
+ else:
+ subtype = 'mail.mt_comment'
- if is_log or (mass_mail_mode and not wizard.notify):
++ if is_log: # log a note: subtype is False
++ subtype = False
++ elif mass_mail_mode: # mass mail: is a log pushed to recipients, author not added
+ subtype = False
++ context = dict(context, mail_create_nosubscribe=True) # add context key to avoid subscribing the author
+ msg_id = active_model_pool.message_post(cr, uid, [res_id], type='comment', subtype=subtype, context=context, **post_values)
+ # mass_mailing, post without notify: notify specific partners
+ if mass_mail_mode and not wizard.notify and post_values['partner_ids']:
+ self.pool.get('mail.notification')._notify(cr, uid, msg_id, post_values['partner_ids'], context=context)
return {'type': 'ir.actions.act_window_close'}