from openerp import tools
from email.header import decode_header
+from email.utils import formataddr
from openerp import SUPERUSER_ID
from openerp.osv import osv, orm, fields
from openerp.tools import html_email_clean
def default_get(self, cr, uid, fields, context=None):
# protection for `default_type` values leaking from menu action context (e.g. for invoices)
- if context and context.get('default_type') and context.get('default_type') not in self._columns['type'].selection:
+ if context and context.get('default_type') and context.get('default_type') not in [
+ val[0] for val in self._columns['type'].selection]:
context = dict(context, default_type=None)
return super(mail_message, self).default_get(cr, uid, fields, context=context)
def _get_default_from(self, cr, uid, context=None):
this = self.pool.get('res.users').browse(cr, SUPERUSER_ID, uid, context=context)
if this.alias_name and this.alias_domain:
- return '%s <%s@%s>' % (this.name, this.alias_name, this.alias_domain)
+ return formataddr((this.name, '%s@%s' % (this.alias_name, this.alias_domain)))
elif this.email:
- return '%s <%s>' % (this.name, this.email)
+ return formataddr((this.name, this.email))
raise osv.except_osv(_('Invalid Action!'), _("Unable to send email, please configure the sender's email address or alias."))
def _get_default_author(self, cr, uid, context=None):
email_reply_to = None
ir_config_parameter = self.pool.get("ir.config_parameter")
- catchall_domain = ir_config_parameter.get_param(cr, uid, "mail.catchall.domain", context=context)
+ catchall_domain = ir_config_parameter.get_param(cr, SUPERUSER_ID, "mail.catchall.domain", context=context)
# model, res_id, email_from: comes from values OR related message
model, res_id, email_from = values.get('model'), values.get('res_id'), values.get('email_from')
email_reply_to = self.pool[model].message_get_reply_to(cr, uid, [res_id], context=context)[0]
# no alias reply_to -> catchall alias
if not email_reply_to and catchall_domain:
- catchall_alias = ir_config_parameter.get_param(cr, uid, "mail.catchall.alias", context=context)
+ catchall_alias = ir_config_parameter.get_param(cr, SUPERUSER_ID, "mail.catchall.alias", context=context)
if catchall_alias:
email_reply_to = '%s@%s' % (catchall_alias, catchall_domain)
# still no reply_to -> reply_to will be the email_from
email_reply_to = emails[0]
document_name = self.pool[model].name_get(cr, SUPERUSER_ID, [res_id], context=context)[0]
if document_name:
- # sanitize document name
- sanitized_doc_name = re.sub(r'[^\w+.]+', '-', document_name[1])
# generate reply to
- email_reply_to = _('"Followers of %s" <%s>') % (sanitized_doc_name, email_reply_to)
+ email_reply_to = formataddr((_('Followers of %s') % document_name[1], email_reply_to))
return email_reply_to
('res_id', '=', message.res_id),
], context=context)
partners_to_notify |= set(
- fo.partner_id for fo in fol_obj.browse(cr, SUPERUSER_ID, fol_ids, context=context)
+ fo.partner_id.id for fo in fol_obj.browse(cr, SUPERUSER_ID, fol_ids, context=context)
if message.subtype_id.id in [st.id for st in fo.subtype_ids]
)
# remove me from notified partners, unless the message is written on my own wall