diff --git a/addons/mail/mail_followers.py b/addons/mail/mail_followers.py
index d0444a31cc1..255b6d55a50 100644
--- a/addons/mail/mail_followers.py
+++ b/addons/mail/mail_followers.py
@@ -84,11 +84,20 @@ class mail_notification(osv.Model):
def notify(self, cr, uid, partner_ids, msg_id, context=None):
""" Send by email the notification depending on the user preferences """
context = context or {}
+ # mail_noemail (do not send email) or no partner_ids: do not send, return
+ if context.get('mail_noemail') or not partner_ids:
+ return True
+
mail_mail_obj = self.pool.get('mail.mail')
msg_obj = self.pool.get('mail.message')
msg = msg_obj.browse(cr, uid, msg_id, context=context)
- towrite = self.notify_get_notif_email_dict(cr, uid, msg, context=context)
+ towrite = {
+ 'mail_message_id': msg.id,
+ 'email_to': [],
+ 'user_signature': True,
+ 'auto_delete': True,
+ }
for partner in self.pool.get('res.partner').browse(cr, uid, partner_ids, context=context):
# Do not send an email to the writer
@@ -97,34 +106,14 @@ class mail_notification(osv.Model):
# Partner does not want to receive any emails
if partner.notification_email_send=='none' or not partner.email:
continue
- # Partners want to receive only emails and comments
+ # Partner want to receive only emails and comments
if partner.notification_email_send=='comment' and msg.type not in ('email','comment'):
continue
- towrite['state'] = 'outgoing'
if partner.email not in towrite['email_to']:
towrite['email_to'].append(partner.email)
+ towrite['email_to'] = ', '.join(towrite['email_to'])
- if towrite.get('state') and not context.get('mail_noemail'):
- towrite['message_id'] = msg.id
- towrite['email_to'] = ', '.join(towrite['email_to'])
-
- email_notif_id = mail_mail_obj.create(cr, uid, towrite, context=context)
- mail_mail_obj.send(cr, uid, [email_notif_id], context=context)
-
+ email_notif_id = mail_mail_obj.create(cr, uid, towrite, context=context)
+ mail_mail_obj.send(cr, uid, [email_notif_id], context=context)
return True
-
- def notify_get_notif_email_dict(self, cr, uid, msg, context=None):
- """ Return the content of the email send for notification.
- :param message: browse record on source mail.message
- """
- subject = msg.subject or '%s posted a comment on %s' % (msg.author_id.name, msg.record_name)
- body = msg.body or ''
- author_signature = msg.author_id.user_ids[0].signature
- if author_signature:
- body += '
%s
' % (author_signature)
- return {
- 'email_to': [],
- 'subject': subject,
- 'body': body,
- }
diff --git a/addons/mail/mail_mail.py b/addons/mail/mail_mail.py
index ebfd19e87b3..50b5b4cfe84 100644
--- a/addons/mail/mail_mail.py
+++ b/addons/mail/mail_mail.py
@@ -26,6 +26,7 @@ import tools
from osv import osv
from osv import fields
+from tools.translate import _
_logger = logging.getLogger(__name__)
@@ -50,29 +51,27 @@ class mail_mail(osv.Model):
], 'Status', readonly=True),
'auto_delete': fields.boolean('Auto Delete',
help="Permanently delete this email after sending it, to save space"),
+ 'user_signature': fields.boolean('Add Signature',
+ help="If checked, the user's signature will be appended to the text version of the message"),
'references': fields.text('References', help='Message references, such as identifiers of previous messages', readonly=1),
'email_from': fields.char('From', size=128, help='Message sender, taken from user preferences.'),
'email_to': fields.text('To', help='Message recipients'),
'email_cc': fields.char('Cc', size=256, help='Carbon copy message recipients'),
'reply_to':fields.char('Reply-To', size=256, help='Preferred response address for the message'),
-
- 'content_subtype': fields.char('Message content subtype', size=32,
- oldname="subtype", readonly=1,
- help="Type of message, usually 'html' or 'plain', used to select "\
- "plain-text or rich-text contents accordingly"),
- 'body_html': fields.text('Rich-text Contents', help="Rich-text/HTML version of the message"),
}
- def _get_default_from(self, cr, uid, context={}):
+ def _get_default_from(self, cr, uid, context=None):
cur = self.pool.get('res.users').browse(cr, uid, uid, context=context)
if not cur.alias_domain:
- raise osv.except_osv(_('Invalid Action!'), _('Unable to send email, set an alias domain in your server settings.'))
+ # TDE temp: impossible to install social module, because mail.group tries to send emails ...
+ # raise osv.except_osv(_('Invalid Action!'), _('Unable to send email, set an alias domain in your server settings.'))
+ pass
return cur.alias_name + '@' + cur.alias_domain
_defaults = {
'state': 'outgoing',
- 'content_subtype': 'plain',
- 'email_from': _get_default_from
+ 'email_from': lambda self, cr, uid, ctx=None: self._get_default_from(cr, uid, ctx),
+ 'user_signature': False,
}
def mark_outgoing(self, cr, uid, ids, context=None):
@@ -144,50 +143,53 @@ class mail_mail(osv.Model):
:return: True
"""
ir_mail_server = self.pool.get('ir.mail_server')
- self.write(cr, uid, ids, {'state': 'outgoing'}, context=context)
for message in self.browse(cr, uid, ids, context=context):
try:
+ body = message.body
+
+ # handle attachments
attachments = []
for attach in message.attachment_ids:
attachments.append((attach.datas_fname, base64.b64decode(attach.datas)))
- body = message.body_html if message.content_subtype == 'html' else message.body
- body_alternative = None
- content_subtype_alternative = None
- if message.content_subtype == 'html':
- # we have a plain text alternative prepared, pass it to
- # build_message instead of letting it build one
- body_alternative = tools.html2plaintext(message.body)
- content_subtype_alternative = 'plain'
+ # add signature if flag set
+ if message.user_signature:
+ signature = message.author_id and message.author_id.user_ids[0].signature or ''
+ insertion_point = body.find('