Java Mail: Only one part of the message is retrieved / Parsing error / Badly formatted mail

BenoitParis

Hello all :) I'm having troubles parsing mails from a pop3 server. In the end I want to get the attachements. The mails are multiparts, but so far I only managed to get a small part of the mail.

Here is the original email, as read by outlook (+one file attached):

ID-G1619161

P.S. : This is an automated email.
 Write back to [email protected]

Post-scriptum :

This message is confidential. [...]

Here is some code:

inbox.open(Folder.READ_ONLY);
Message[] messages = inbox.getMessages();

for (int i = 0; i < messages.length; i++) {

    Message message = messages[i];
    System.out.println("message : " + message);
    System.out.println("***");
    IOUtils.copy(message.getInputStream(),System.out);
    System.out.println("***");              
    System.out.println("message.getContentType : " + message.getContentType());
    Multipart multiPart = (Multipart) message.getContent();
    System.out.println("multiPart : " + multiPart);
    int numberOfParts = multiPart.getCount();  // line A
}

This prints:

message : org.apache.geronimo.javamail.store.pop3.message.POP3Message@79f6f296
***

P.S. : This is an automated email.***
message.getContentType : multipart/mixed; boundary="qMm9M+Fa2AknHoGS"
multiPart : javax.mail.internet.MimeMultipart@bc92535

And throws on line A (multiPart.getCount!):

javax.mail.MessagingException: Unexpected response:  Write back to [email protected]

My take on this is the message is formatted in a weird way that is not recognised by javax.mail, because getCount is trying to read the rest of the mail.

I can even get the whole message! (Trying to do this at: IOUtils.copy(message.getInputStream(),System.out);)

How would you debug this? Also, if you know a way to get the whole mail as a string (attachements included), I'd be very glad you share it. I'm prepared to parse this by hand.

Best regards

Bill Shannon

JavaMail debugging tips are here.

You can get the entire message text using the Message.writeTo method. Write it to a FileOutputStream or a ByteArrayOutputStream.

You might have better luck using the JavaMail reference implementation instead of the Geronimo(?) version you're using.

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

sending bulk mail with HTML formatted

分類Dev

Undefined index only for only one item when using mail

分類Dev

javax.mail.AuthenticationFailedException Java Mail

分類Dev

javax.mail.Part.getContent()ArrayIndexOutOfBoundsException:16448

分類Dev

500 error after PHP mail()

分類Dev

Java Mail APIの代替

分類Dev

JSoup parsing badly structured HTML

分類Dev

xlabels only appear formatted in one of two subplots

分類Dev

UIDocumentInteractionController can only share pdf with Mail app

分類Dev

error while sending mail using javamail

分類Dev

Spring Integration: Mail error and HTTP gateway response

分類Dev

Strange error on exit mail from hpux

分類Dev

Sending MHT file using C# Mail Message

分類Dev

(VBA Outlook) Prompt a message box when sending blanket mail

分類Dev

Java Parsing - delimiter can also be part of the token

分類Dev

Parsing HTML with formatted text

分類Dev

Is there a way to verify if e-mail was delivered only using SSL connection?

分類Dev

using textscan to read badly formatted CSV file in Octave

分類Dev

Spring Mail Integration-org.springframework.messaging.Messageをjavax.mail.internet.MimeMessageに変換する方法

分類Dev

How to extract only a part of one line?

分類Dev

Error in multicasting a message in java

分類Dev

Java : Parsing Long throws error

分類Dev

Only ahow error message when error occurs

分類Dev

Laravel 5.1 Mail::queue Amazon SQS error 404

分類Dev

Error While sending a mail from Email subscription in SSRS

分類Dev

Windows Task Scheduler Error 2147746322 Sending Mail with Attachment

分類Dev

Sending mail with dynamic attachment(pdf) using phpmailer returns error in pdf

分類Dev

.Net - Error when get unread mail from Gmail by IMAP protocol

分類Dev

Python popen2関数の書き換え(php-mail-parsing)

Related 関連記事

  1. 1

    sending bulk mail with HTML formatted

  2. 2

    Undefined index only for only one item when using mail

  3. 3

    javax.mail.AuthenticationFailedException Java Mail

  4. 4

    javax.mail.Part.getContent()ArrayIndexOutOfBoundsException:16448

  5. 5

    500 error after PHP mail()

  6. 6

    Java Mail APIの代替

  7. 7

    JSoup parsing badly structured HTML

  8. 8

    xlabels only appear formatted in one of two subplots

  9. 9

    UIDocumentInteractionController can only share pdf with Mail app

  10. 10

    error while sending mail using javamail

  11. 11

    Spring Integration: Mail error and HTTP gateway response

  12. 12

    Strange error on exit mail from hpux

  13. 13

    Sending MHT file using C# Mail Message

  14. 14

    (VBA Outlook) Prompt a message box when sending blanket mail

  15. 15

    Java Parsing - delimiter can also be part of the token

  16. 16

    Parsing HTML with formatted text

  17. 17

    Is there a way to verify if e-mail was delivered only using SSL connection?

  18. 18

    using textscan to read badly formatted CSV file in Octave

  19. 19

    Spring Mail Integration-org.springframework.messaging.Messageをjavax.mail.internet.MimeMessageに変換する方法

  20. 20

    How to extract only a part of one line?

  21. 21

    Error in multicasting a message in java

  22. 22

    Java : Parsing Long throws error

  23. 23

    Only ahow error message when error occurs

  24. 24

    Laravel 5.1 Mail::queue Amazon SQS error 404

  25. 25

    Error While sending a mail from Email subscription in SSRS

  26. 26

    Windows Task Scheduler Error 2147746322 Sending Mail with Attachment

  27. 27

    Sending mail with dynamic attachment(pdf) using phpmailer returns error in pdf

  28. 28

    .Net - Error when get unread mail from Gmail by IMAP protocol

  29. 29

    Python popen2関数の書き換え(php-mail-parsing)

ホットタグ

アーカイブ