dpchen2004 2017-11-25 06:14
浏览 182
已采纳

Gmail imap-正文中的字符集错误

currently trying to use package "github.com/emersion/go-imap" in order to parse some emails however I've discovered when trying to parse emails from a specific company - they send an automated email on signup, I get returned the error "unhandled charset "ascii" when attempting the following code:

mr, err := mail.CreateReader(r)

    if err != nil {
        log.Fatal(err)
    }

the value r is assigned with the code:

msg := <-messages
    r := msg.GetBody("BODY[]")

    if r == nil {
        log.Fatal("Server didn't returned message body")
    }

which attempts to get the body of the message in my inbox. I'm not sure what's causing this error to be thrown considering every other email I've tested it on works - it's just this specific email that gets sent that causes my code to fail. I've tried having it resend and tried new email addresses. Not sure what I can do

  • 写回答

1条回答 默认 最新

  • doulou1970 2017-11-25 07:58
    关注

    That message seems to be from message.go, and probably says that go-imap only supports ASCII when it's the default, not when it's explicitly specified. In other words, Content-Type: text/plain should work, Content-Type: text/plain; charset=ascii not. The easiest way forward is probably to fix go-imap and submit a pull request.

    FYI, many old charsets have more than one name. You don't need to add support for all the legacy charsets, but for those that are supported, go-imap really should know all the names. The names are kept by IANA and this script is the kind of thing you might want to use to parse the IANA list and generate an array of aliases.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?