【问题标题】:Parse Exception in javax.mail MimeMessagejavax.mail MimeMessage 中的解析异常
【发布时间】:2013-11-21 16:31:14
【问题描述】:

我在

中发现了同样的错误

https://forums.oracle.com/thread/2449918

根据答案,电子邮件是错误的。我的问题是,有没有关于如何处理这个问题的想法?
如问题所述,如果我尝试发送:

内容类型:text/rfc822-headers;
内容传输编码:8bit

代替

Content-Type: text/rfc822-headers;内容传输编码:8bit

它会起作用的。

通过使用mail.mime.contenttypehandler 属性,我可以添加自己的类来清理 Content-Type 标头,但这可能有风险,因为完整的验证、正则表达式...等可能带来的问题多于解决的问题。 以前有人遇到过这个问题吗?怎么解决?

任何想法都会被欣赏。

【问题讨论】:

    标签: java parsing mime-message


    【解决方案1】:

    根据documentation,问题是Content-Type参数结构,ti应该是:

    Content-Type: text/rfc822-headers; Content-Transfer-Encoding= 8bit
    

    我刚刚创建了一个类来修复它,但我仍然认为必须有一些更好的解决方案。 如果有人发现它,请继续回答! :)

    谢谢

    public static String cleanContentType(String contentType){
            StringBuilder cleanedContentType = new StringBuilder();
            if(contentType.contains(";")){   //It contains paramenter
                cleanedContentType.append(contentType.split(";")[0]).append("; ");
                if(contentType.split(";").length > 1){
                    for(int i = 1; i < contentType.split(";").length ; i++){
                        cleanedContentType.append(contentType.split(";")[i].replace(":", "=")).append("; ");
                    }
                }
            } else{
                return contentType;
            }
    
            return cleanedContentType.toString();
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-06-25
      • 2013-04-13
      • 2020-08-31
      • 2016-05-24
      • 2012-07-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多