Email发送邮件附件中文名乱码问题

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

posted @ 2013-07-31 14:53  奥斯卡影帝  阅读(1401)  评论(0编辑  收藏  举报