Conversion from com.fsck.k9.mail.internet.MimeMessage to javax.mail.internet.MimeMessage

18 views
Skip to first unread message

hauke...@gmail.com

unread,
Apr 18, 2015, 4:12:31 AM4/18/15
to k-9-...@googlegroups.com
Hi,

is there any way to convert the mail content, including attachments, from the com.fsck.k9.mail.internet.MimeMessage class to the javax.mail.internet.MimeMessage class? They seem to be similar. I tried it with piped streams, but without success. Here is what I did:

com.fsck.k9.mail.internet.MimeMessage message;
PipedInputStream in = new PipedInputStream(1024);
PipedOutputStream out = new PipedOutputStream(in);
javax
.mail.internet.MimeMessage mm = new javax.mail.internet.MimeMessage(session, in);
message
.getBody().writeTo(out);

Has anyone any clues what is wrong about this code, or is there a better solution for my problem?

Regards

hauke...@gmail.com

unread,
Apr 22, 2015, 4:25:53 PM4/22/15
to k-9-...@googlegroups.com
I solved the problem the following way:

com.fsck.k9.mail.internet.MimeMessage message;
javax
.mail.internet.
MimeMessage mm = null;
Properties prop = System.getProperties();
Session sess = Session.getDefaultInstance(prop, null);
try {
   
ByteArrayOutputStream out = new ByteArrayOutputStream();
    message
.writeTo(out);
   
byte[] ba = out.toByteArray();
   
ByteArrayInputStream in = new ByteArrayInputStream(ba);
    mm
= new javax.mail.internet.MimeMessage(sess, in);
   
out.close();
   
in.close();
} catch (IOException ex) {
    ex
.printStackTrace();
} catch (MessagingException e) {
    e
.printStackTrace();
} catch (javax.mail.MessagingException e) {
    e
.printStackTrace();
}

Regards

Reply all
Reply to author
Forward
0 new messages