zoukankan      html  css  js  c++  java
  • Email发送邮件附件中文名乱码问题

    使用手机中自带Email的客户端在发送附件名是中文的电子邮件时,不管是在PC机上还是在Android设备上,接收到的电子邮件的附件名会显示为乱码,在网上查阅了相关技术资料,以及有关编码解码方面的书籍资料,发现跟发送时传送的文件名参数有关系,因此我们在解决该问题时,只需要修改以下文件就可以解决问题:packages/apps/Email/emailcommon/src/com/android/emailcommon/internet/Rfc822Output.java文件,将writeOneAttachment函数作如下内容的修改:
           writeHeader(writer, "Content-Type",
                   attachment.mMimeType + "; name="" + attachment.mFileName + """);
           writeHeader(writer, "Content-Transfer-Encoding", "base64");
           // Most attachments (real files) will send Content-Disposition. The suppression option
           // is used when sending calendar invites.
          if ((attachment.mFlags & Attachment.FLAG_ICS_ALTERNATIVE_PART) == 0) {
                   writeHeader(writer, "Content-Disposition",
                          "attachment;"
                          + " filename="" + attachment.mFileName + "";"
                          + " size=" + Long.toString(attachment.mSize));
          }
          修改为:
           writeHeader(writer, "Content-Type",
                     attachment.mMimeType + "; name="" +
                     MimeUtility.foldAndEncode2(attachment.mFileName,"Content-Type".length() + 2)+ """);
           writeHeader(writer, "Content-Transfer-Encoding", "base64");
           // Most attachments (real files) will send Content-Disposition. The suppression option
           // is used when sending calendar invites.
           if ((attachment.mFlags & Attachment.FLAG_ICS_ALTERNATIVE_PART) == 0) {
                      writeHeader(writer, "Content-Disposition",
                                 "attachment;"
                                 + " filename="" +MimeUtility.foldAndEncode2(attachment.mFileName,"Content-Disposition".length()+ 2)+ "";"
                                 + " size=" + Long.toString(attachment.mSize));
           }
          在Rfc822Output文件writeOneAttachment函数中将文件名字编码增强下,加+2是因为还有": "这二字符也要占位置.
          至此即可解决该问题。

  • 相关阅读:
    BZOJ1183 Croatian2008 Umnozak 【数位DP】*
    算法--斯坦纳树
    BZOJ2595 Wc2008 游览计划 【斯坦纳树】【状压DP】*
    BZOJ1833 ZJOI2010 count 数字计数 【数位DP】
    BZOJ1087 SCOI2005 互不侵犯King 【状压DP】
    BZOJ1026 SCOI2009 windy数 【数位DP】
    pytest灵魂产物
    django限流全局和单个视图
    论文阅读笔记四十一:Very Deep Convolutional Networks For Large-Scale Image Recongnition(VGG ICLR2015)
    某线 生成式模型预测算法实习生面试总结
  • 原文地址:https://www.cnblogs.com/douzhanshen/p/3227797.html
Copyright © 2011-2022 走看看