자바메일에서 Unknown encoding: plain 에러

뉴로맨서의 이미지

javamail을 사용하여 pop3로 메일을 가져오는 프로그램을 만들고 있습니다. 그런데 아래와 같이 메일바디를 가져오는 부분에서 에러가 나는 메일들이 있습니다.

if (part.isMimeType("text/*")) { 
 mail.setBody(part.getContent().toString()); 
}

에러메시지는

java.io.IOException: Unknown encoding: plain 
 at javax.mail.internet.MimePartDataSource.getInputStream(MimePartDataSource.java:70) 
 at com.sun.mail.handlers.text_plain.getContent(text_plain.java:64) 
 at javax.activation.DataSourceDataContentHandler.getContent(DataHandler.java:745) 
 at javax.activation.DataHandler.getContent(DataHandler.java:501) 
 at javax.mail.internet.MimeMessage.getContent(MimeMessage.java:1339)

에러가 나는 메일을 보니 Content-Transfer-Encoding 부분이 plain으로 되어 있더군요. inputstream 으로 처리할려고 part.getInputStream() 하여도 마찬가지 에러가 납니다.

해결방법을 아시는 분의 도움을 부탁드립니다.

iolo의 이미지

Content-Transer-Encoding에 plain이라니... 참 므흣한 인코딩입니다.
잘못된 인코딩이라... 뾰족한 해법은 없을듯 하네요...

DataSource를 직접만들어서 가로 채는 수 밖에 없을 듯 한데요...
아니면 그냥 잘못된 메일이라고 해도 그만아닌가요?

찍어맞추기도 어느정도지...
plain이라고 하면 뭐라고 가정하고 디코딩을 해야 하나요?
7bit? 8bit? qp? base64?
-.-;;;

저도 메일관련 프로그래밍을 오래했는데... 참 당황스런 메일들이 많지만..
이것도 만만치 않군요-.-;

----
the smile has left your eyes...

atie의 이미지

text/*해서, text만 비교하고 getContent()가 수행이 되었는데... 그 전에 getContentType()해서 charset 정보가 있는지 등의 검사를 먼저 해보고 경우에 따라 대응을 하세요.

----
I paint objects as I think them, not as I see them.
atie's minipage

뉴로맨서의 이미지

두분 답변 감사합니다. ^^

iolo의 이미지

atie wrote:
text/*해서, text만 비교하고 getContent()가 수행이 되었는데... 그 전에 getContentType()해서 charset 정보가 있는지 등의 검사를 먼저 해보고 경우에 따라 대응을 하세요.

Content-Type헤더가 아니라 Content-Transfer-Encoding이 plain이라는 것이 문제 안닐까요? 그런 인코딩은 없으므로... javamail은 파싱을 거부하겠죠.
결국 수동으로 디코딩할수 밖에 없다는 얘긴데... 인코딩 방법을 모른상태에서 디코딩하는 건 그냥 찍어맞추기로 한다고 치더라도... javamail만으로 할 수 있는 건 아닌듯하네요..
캐릭터셋이 무엇인가는 디코딩한 연후의 문제죠.
디코딩한 결과가 바이너리라면 해당사항없음이고...

그런데 그 메일을 일반적인 메일클라이언트(아웃룩이나 썬더버드같은)에선 파싱해서 보여주나요?

----
the smile has left your eyes...

댓글 달기

Filtered HTML

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

BBCode

  • 텍스트에 BBCode 태그를 사용할 수 있습니다. URL은 자동으로 링크 됩니다.
  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param>
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.

Textile

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • You can use Textile markup to format text.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Markdown

  • 다음 태그를 이용하여 소스 코드 구문 강조를 할 수 있습니다: <code>, <blockcode>, <apache>, <applescript>, <autoconf>, <awk>, <bash>, <c>, <cpp>, <css>, <diff>, <drupal5>, <drupal6>, <gdb>, <html>, <html5>, <java>, <javascript>, <ldif>, <lua>, <make>, <mysql>, <perl>, <perl6>, <php>, <pgsql>, <proftpd>, <python>, <reg>, <spec>, <ruby>. 지원하는 태그 형식: <foo>, [foo].
  • Quick Tips:
    • Two or more spaces at a line's end = Line break
    • Double returns = Paragraph
    • *Single asterisks* or _single underscores_ = Emphasis
    • **Double** or __double__ = Strong
    • This is [a link](http://the.link.example.com "The optional title text")
    For complete details on the Markdown syntax, see the Markdown documentation and Markdown Extra documentation for tables, footnotes, and more.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 사용할 수 있는 HTML 태그: <p><div><span><br><a><em><strong><del><ins><b><i><u><s><pre><code><cite><blockquote><ul><ol><li><dl><dt><dd><table><tr><td><th><thead><tbody><h1><h2><h3><h4><h5><h6><img><embed><object><param><hr>

Plain text

  • HTML 태그를 사용할 수 없습니다.
  • web 주소와/이메일 주소를 클릭할 수 있는 링크로 자동으로 바꿉니다.
  • 줄과 단락은 자동으로 분리됩니다.
댓글 첨부 파일
이 댓글에 이미지나 파일을 업로드 합니다.
파일 크기는 8 MB보다 작아야 합니다.
허용할 파일 형식: txt pdf doc xls gif jpg jpeg mp3 png rar zip.
CAPTCHA
이것은 자동으로 스팸을 올리는 것을 막기 위해서 제공됩니다.