跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 新手求助
  4. Poweremail 收件 邮件标题 以及 收(发)件人 地址乱码问题修正

Poweremail 收件 邮件标题 以及 收(发)件人 地址乱码问题修正

已定时 已固定 已锁定 已移动 Odoo 新手求助
2 帖子 1 发布者 4.7k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • mrshellyM 离线
    mrshellyM 离线
    mrshelly
    写于 最后由 编辑
    #1


    影响 PowerEmail for OpenERP 0.6.3及以下版本. 听说 0.7 版本已修正...
    解决方案由 广州-hugo(150672834) 提供. mrshelly做相关整理

    poweremail_core.py 文件

    save_header
    save_fullmail
    complete_mail
    三个方法中. 对于 vals['pem_from'], vals['pem_to'], vals['pem_subject'] 三个值做处理
    其中 vals['pem_from'] vals['pem_to'] 使用 email.utils.parseaddr() 方法处理, 并获取出里面的邮件地址回存.
    相关代码:

    <br />....<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;pem_from&#039;:email.utils.parseaddr(mail&#91;&#039;From&#039;])[1],<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;pem_to&#039;:email.utils.parseaddr(mail&#91;&#039;To&#039;])[1] or &#039;no recepient&#039;,<br />....<br />
    



    vals['pem_subject'] 则将 Quoted Printable 格式转成正常的 unicode 串.
    相关代码:

    <br />....<br />&nbsp; &nbsp; &nbsp; &nbsp; h = email.Header.Header(mail&#91;&#039;subject&#039;])&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; dh = email.Header.decode_header(h)&nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; subject = dh[0][0]<br />....<br />....<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &#039;pem_subject&#039;:subject,<br />....<br />
    




    get_payloads
    这个方法中, 主要在处理 multipart 的附加内容时 没有进行 Quoted Printable -->Unicode String 的转换. 所以 转换后. 附件就处理正常了.
    相关代码:

    <br />....<br />&nbsp; &nbsp; &nbsp; &nbsp; for part in mail.walk():<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; mail_part_type = part.get_content_type()<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if mail_part_type == &#039;text/plain&#039;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parsed_mail&#91;&#039;text&#039;] = tools.ustr(part.get_payload(decode=True))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elif mail_part_type == &#039;text/html&#039;:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parsed_mail&#91;&#039;html&#039;] = tools.ustr(part.get_payload(decode=True))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; elif not mail_part_type.startswith(&#039;multipart&#039;):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parsed_mail&#91;&#039;attachments&#039;].append((mail_part_type, tools.ustr(email.Header.decode_header(part.get_filename())[0][0]), part.get_payload(decode=True)))<br />&nbsp; &nbsp; &nbsp; &nbsp; return parsed_mail<br />....<br />
    

    1 条回复 最后回复
    0

    • 登录

    • 没有帐号? 注册

    • 登录或注册以进行搜索。
    • 第一个帖子
      最后一个帖子
    0
    • 版块
    • 标签
    • 热门
    • 用户
    • 群组