Redian新闻
>
A question about Content-type & encoding
avatar
A question about Content-type & encoding# Java - 爪哇娇娃
c*y
1
I am writing an email client. There are several lines like this in the program:
message.getContent()
Then for one email I got an exception which will abort the operation, the exception
is:
java.io.UnsupportedEncodingException: X-UNKNOWN
I looked at the email mesage, and found out in the headers of the email:
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN
obviously it was the charset's problem..
How can solve this problem?
Thanks.
avatar
g*y
2
what is in that email?
guess u must have ur program support X-UNKNOWN...

program:
exception

【在 c*y 的大作中提到】
: I am writing an email client. There are several lines like this in the program:
: message.getContent()
: Then for one email I got an exception which will abort the operation, the exception
: is:
: java.io.UnsupportedEncodingException: X-UNKNOWN
: I looked at the email mesage, and found out in the headers of the email:
: Content-Type: TEXT/PLAIN; charset=X-UNKNOWN
: obviously it was the charset's problem..
: How can solve this problem?
: Thanks.

avatar
c*y
3
The emails header has an entry says:
Content-Type: TEXT/PLAIN; charset=X-UNKNOWN
I don't think X-UNKNOWN is a valid charset... hehe. anyway, what I did is
before call getContent(), I call getContentType(), if it's sth weird, then I
just use writeTo() to write the raw data into a file without decoding it...
hehe.

【在 g****y 的大作中提到】
: what is in that email?
: guess u must have ur program support X-UNKNOWN...
:
: program:
: exception

avatar
r*s
4
Suppose you are using Java Mail API. For messages with attachment,
you cannot use msg.getContent() directly. Instead, you need to get its
Part object first. Then getContent() from it. The content could be
text string, or Multipart. If the latter, you will have to do it
recursively ...

【在 c*y 的大作中提到】
: I am writing an email client. There are several lines like this in the program:
: message.getContent()
: Then for one email I got an exception which will abort the operation, the exception
: is:
: java.io.UnsupportedEncodingException: X-UNKNOWN
: I looked at the email mesage, and found out in the headers of the email:
: Content-Type: TEXT/PLAIN; charset=X-UNKNOWN
: obviously it was the charset's problem..
: How can solve this problem?
: Thanks.

avatar
c*y
5
As far as I know, for a msg with attachment, its bodypart is an multipart,
so your first use getContent() to get the multipart, then process the
parts in the multipart.
This problem was not due to multipart, but because some application put
X-UNKNOWN in "content-type" field, which java parse can't deal with..

【在 r*****s 的大作中提到】
: Suppose you are using Java Mail API. For messages with attachment,
: you cannot use msg.getContent() directly. Instead, you need to get its
: Part object first. Then getContent() from it. The content could be
: text string, or Multipart. If the latter, you will have to do it
: recursively ...

avatar
e*g
6

nobody can... the client has to guess, or let user to select.

【在 c*y 的大作中提到】
: As far as I know, for a msg with attachment, its bodypart is an multipart,
: so your first use getContent() to get the multipart, then process the
: parts in the multipart.
: This problem was not due to multipart, but because some application put
: X-UNKNOWN in "content-type" field, which java parse can't deal with..

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。