Reading from javamail is time consuming

I use javamail to read emails from an exchange account using IMAP protocol. These letters are in a simple format, and its contents are XML.

Almost all of these letters are short (usually less than 100 KB). However, sometimes I have to deal with large letters (about 10 MB-15 MB). For example, yesterday I received a 13 MB email. It took more than 50 minutes to read it. This is normal? Is there a way to increase its performance? Code:

Session sesion = Session.getInstance(System.getProperties());
Store store = sesion.getStore("imap");
store.connect(host, user, passwd);
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);

Message[] messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
for (int i = 0 ; i< messages.length ; i++){
    Object contents = messages[i].getContent();  // Here it takes 50 min on 13Mb mail
    // ...
}

The method that takes such a long time is equal messages[i].getContent(). What am I doing wrong? Any hint?

Thank you very much and sorry for my English!;)

+4
source share
3 answers

, , .

, , , , : http://www.oracle.com/technetwork/java/faq-135477.html#imapserverbug

, , , :

Session sesion = Session.getInstance(System.getProperties());
Store store = sesion.getStore("imap");
store.connect(host, user, passwd);
Folder inbox = store.getFolder("INBOX");
inbox.open(Folder.READ_WRITE);

// Convert to MimeMessage after search 
MimeMessage[] messages = (MimeMessage[]) carpetaInbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false));
for (int i = 0 ; i< messages.length ; i++){
    // Create a new message using MimeMessage copy constructor
    MimeMessage cmsg = new MimeMessage(messages[i]);
    // Use this message to read its contents 
    Object obj = cmsg.getContent(); 
// ....
}

MimeMessage(), MimeMessage . , , , , , . .

: ( 15 ), Exchange Server IMAP. 51-55 13 , 9 , . .

, - ;)

+5

[i].getContent(), . , IMAP- . :

    FetchProfile fp = new FetchProfile();
        fp.add(FetchProfile.Item.ENVELOPE);
        fp.add(FetchProfileItem.FLAGS);
        fp.add(FetchProfileItem.CONTENT_INFO);
    fp.add("X-mailer");

and after you have specified the fetch profile then you do your search/fetch of messages. 

, , IMAP . ( javax.mail.FetchProfile). , , Message. . , , ( getContent() getInputStream()), FETCH. , , , , , . , , .

, "" , SMTP-, . SMTP- - , , , , - .

+4

Folder.fetch, . , .

, , , getInputStream , getContent String .

, mail.imap.fetchsize, 16384. 100 , , fetchsize 100K. .

+1

All Articles