[FIX] crm, mail_gateway: Use the utf8 encoding
bzr revid: stephane@openerp.com-20100312123528-ppvn4w9sdi20iw6v
This commit is contained in:
parent
14e0a4ed89
commit
412b0eab4e
|
@ -55,11 +55,12 @@ class case(osv.osv):
|
|||
if case.section_id.reply_to and case.email_from:
|
||||
src = case.email_from
|
||||
dest = case.section_id.reply_to
|
||||
body = ""
|
||||
body = case.email_last or case.description
|
||||
if not destination:
|
||||
src, dest = dest, src
|
||||
if case.user_id.signature:
|
||||
body += '\n\n%s' % (case.user_id.signature or '')
|
||||
if body and case.user_id.signature:
|
||||
body += '\n\n%s' % (case.user_id.signature).encode('utf8')
|
||||
dest = [dest]
|
||||
|
||||
attach_to_send = None
|
||||
|
@ -79,10 +80,10 @@ class case(osv.osv):
|
|||
openobject_id=str(case.id),
|
||||
attach=attach_to_send
|
||||
)
|
||||
if flag:
|
||||
raise osv.except_osv(_('Email!'),("Email Successfully Sent"))
|
||||
else:
|
||||
raise osv.except_osv(_('Email Fail!'),("Email is not sent successfully"))
|
||||
#if flag:
|
||||
# raise osv.except_osv(_('Email!'),("Email Successfully Sent"))
|
||||
#else:
|
||||
# raise osv.except_osv(_('Email Fail!'),("Email is not sent successfully"))
|
||||
return True
|
||||
|
||||
def _check(self, cr, uid, ids=False, context={}):
|
||||
|
@ -120,6 +121,23 @@ case()
|
|||
class base_action_rule(osv.osv):
|
||||
_inherit = 'base.action.rule'
|
||||
_description = 'Action Rules'
|
||||
|
||||
def email_send(self, cr, uid, obj, emails, body, emailfrom=tools.config.get('email_from',False), context={}):
|
||||
body = self.format_mail(obj, body)
|
||||
if not emailfrom:
|
||||
if hasattr(obj, 'user_id') and obj.user_id and obj.user_id.address_id and obj.user_id.address_id.email:
|
||||
emailfrom = obj.user_id.address_id.email
|
||||
|
||||
name = '[%d] %s' % (obj.id, tools.ustr(obj.name))
|
||||
emailfrom = tools.ustr(emailfrom)
|
||||
if obj.section_id and obj.section_id.reply_to:
|
||||
reply_to = obj.section_id.reply_to
|
||||
else:
|
||||
reply_to = emailfrom
|
||||
if not emailfrom:
|
||||
raise osv.except_osv(_('Error!'),
|
||||
_("No E-Mail ID Found for your Company address!"))
|
||||
return tools.email_send(emailfrom, emails, name, body, reply_to=reply_to, openobject_id=str(obj.id))
|
||||
|
||||
def do_check(self, cr, uid, action, obj, context={}):
|
||||
ok = super(base_action_rule, self).do_check(cr, uid, action, obj, context=context)
|
||||
|
|
|
@ -36,13 +36,18 @@ class crm_cases(osv.osv):
|
|||
_name = "crm.case"
|
||||
_inherit = "crm.case"
|
||||
|
||||
def _decode_header(self, s):
|
||||
from email.Header import decode_header
|
||||
s = decode_header(s)
|
||||
return ''.join(map(lambda x:x[0].decode(x[1] or 'ascii', 'replace'), s))
|
||||
|
||||
def msg_new(self, cr, uid, msg):
|
||||
mailgate_obj = self.pool.get('mail.gateway')
|
||||
msg_body = mailgate_obj.msg_body_get(msg)
|
||||
data = {
|
||||
'name': msg['Subject'],
|
||||
'email_from': msg['From'],
|
||||
'email_cc': msg['Cc'],
|
||||
'name': self._decode_header(msg['Subject']),
|
||||
'email_from': self._decode_header(msg['From']),
|
||||
'email_cc': msg['Cc'] and self._decode_header(msg['Cc']),
|
||||
'user_id': False,
|
||||
'description': msg_body['body'],
|
||||
}
|
||||
|
@ -51,7 +56,7 @@ class crm_cases(osv.osv):
|
|||
data.update(res)
|
||||
res = self.create(cr, uid, data)
|
||||
cases = self.browse(cr, uid, [res])
|
||||
self._history(cr, uid, cases, _('Receive'), history=True, email=msg['From'])
|
||||
self._history(cr, uid, cases, _('Receive'), history=True, email=self._decode_header(msg['From']))
|
||||
return res
|
||||
|
||||
def msg_update(self, cr, uid, ids, msg, data={}, default_act='pending'):
|
||||
|
|
|
@ -81,7 +81,7 @@ def _mass_mail_send(self, cr, uid, data, context):
|
|||
emails = filter(None, emails)
|
||||
body = data['form']['text']
|
||||
if case.user_id.signature:
|
||||
body += '\n\n%s' % (case.user_id.signature)
|
||||
body += '\n\n%s' % (case.user_id.signature).encode('utf8')
|
||||
case_pool._history(cr, uid, [case], _('Send'), history=True, email=data['form']['to'], details=body)
|
||||
flag = tools.email_send(
|
||||
case.user_id.address_id.email,
|
||||
|
|
|
@ -61,11 +61,17 @@ def _mass_mail_send(self, cr, uid, data, context):
|
|||
'som': False,
|
||||
'canal_id': False,
|
||||
})
|
||||
emails = [data['form']['to']] + (data['form']['cc'] or '').split(',')
|
||||
from_to = tools.email_re.search(data['form']['to']).group(1)
|
||||
emails = []
|
||||
if from_to:
|
||||
emails.append(from_to)
|
||||
for cc in (data['form']['cc'] or '').split(','):
|
||||
if cc:
|
||||
emails.append(tools.email_re.search(cc).group(1))
|
||||
emails = filter(None, emails)
|
||||
body = data['form']['text']
|
||||
if case.user_id.signature:
|
||||
body += '\n\n%s' % (case.user_id.signature)
|
||||
body += '\n\n%s' % (case.user_id.signature).encode('utf8')
|
||||
tools.email_send(
|
||||
case.user_id.address_id.email,
|
||||
emails,
|
||||
|
|
|
@ -362,13 +362,11 @@ class mail_gateway(osv.osv):
|
|||
del msg['Subject']
|
||||
msg['Subject'] = '[%s] %s' %(str(res_id), subject)
|
||||
|
||||
em = [user_email, from_email] + (cc_email or '').split(',')
|
||||
em = [user_email or '', from_email] + (cc_email or '').split(',')
|
||||
emails = map(self.emails_get, filter(None, em))
|
||||
|
||||
mm = [self._decode_header(msg['From']), self._decode_header(msg['To'])]+self._decode_header(msg.get('Cc','')).split(',')
|
||||
msg_mails = map(self.emails_get, filter(None, mm))
|
||||
|
||||
emails = filter(lambda m: m and m not in msg_mails, emails)
|
||||
emails = filter(lambda m: m and m not in msg_mails, emails)
|
||||
try:
|
||||
self.msg_send(msg, mailgateway.reply_to, emails, priority, res_id)
|
||||
if hasattr(self.pool.get(res_model), 'msg_send'):
|
||||
|
|
Loading…
Reference in New Issue