Search in sources :

Example 46 with MimeMessage

use of com.fsck.k9.mail.internet.MimeMessage in project k-9 by k9mail.

the class MessageTest method sampleMessage.

private MimeMessage sampleMessage() throws MessagingException, IOException {
    MimeMessage message = new MimeMessage();
    message.setFrom(new Address("from@example.com"));
    message.setRecipient(RecipientType.TO, new Address("to@example.com"));
    message.setSubject("Test Message");
    message.setHeader("Date", "Wed, 28 Aug 2013 08:51:09 -0400");
    message.setEncoding(MimeUtil.ENC_7BIT);
    MimeMultipart multipartBody = new MimeMultipart("multipart/mixed", generateBoundary());
    multipartBody.addBodyPart(textBodyPart());
    multipartBody.addBodyPart(binaryBodyPart());
    MimeMessageHelper.setBody(message, multipartBody);
    return message;
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart)

Example 47 with MimeMessage

use of com.fsck.k9.mail.internet.MimeMessage in project k-9 by k9mail.

the class MessageTest method nestedMessage.

private MimeMessage nestedMessage(MimeMessage subMessage) throws MessagingException, IOException {
    BinaryTempFileMessageBody tempMessageBody = new BinaryTempFileMessageBody(MimeUtil.ENC_8BIT);
    OutputStream out = tempMessageBody.getOutputStream();
    try {
        subMessage.writeTo(out);
    } finally {
        out.close();
    }
    MimeBodyPart bodyPart = new MimeBodyPart(tempMessageBody, "message/rfc822");
    bodyPart.setHeader(MimeHeader.HEADER_CONTENT_DISPOSITION, "attachment");
    bodyPart.setEncoding(MimeUtil.ENC_7BIT);
    MimeMessage parentMessage = sampleMessage();
    ((Multipart) parentMessage.getBody()).addBodyPart(bodyPart);
    return parentMessage;
}
Also used : MimeMultipart(com.fsck.k9.mail.internet.MimeMultipart) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) ByteArrayOutputStream(java.io.ByteArrayOutputStream) OutputStream(java.io.OutputStream) BinaryTempFileMessageBody(com.fsck.k9.mail.internet.BinaryTempFileMessageBody) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 48 with MimeMessage

use of com.fsck.k9.mail.internet.MimeMessage in project k-9 by k9mail.

the class MessageIdGeneratorTest method generateMessageId_withoutRelevantHeaders.

@Test
public void generateMessageId_withoutRelevantHeaders() throws Exception {
    Message message = new MimeMessage();
    String result = messageIdGenerator.generateMessageId(message);
    assertEquals("<00000000-0000-4000-0000-000000000000@email.android.com>", result);
}
Also used : Message(com.fsck.k9.mail.Message) Test(org.junit.Test)

Example 49 with MimeMessage

use of com.fsck.k9.mail.internet.MimeMessage in project k-9 by k9mail.

the class MessageIdGeneratorTest method generateMessageId_withFromAndReplyToAddress.

@Test
public void generateMessageId_withFromAndReplyToAddress() throws Exception {
    Message message = new MimeMessage();
    message.setFrom(new Address("alice@example.org"));
    message.setReplyTo(Address.parse("bob@example.com"));
    String result = messageIdGenerator.generateMessageId(message);
    assertEquals("<00000000-0000-4000-0000-000000000000@example.org>", result);
}
Also used : Message(com.fsck.k9.mail.Message) Address(com.fsck.k9.mail.Address) Test(org.junit.Test)

Example 50 with MimeMessage

use of com.fsck.k9.mail.internet.MimeMessage in project k-9 by k9mail.

the class MimeMessageParseTest method checkLeafParts.

private static void checkLeafParts(MimeMessage msg, String... expectedParts) throws Exception {
    List<String> actual = new ArrayList<String>();
    for (Body leaf : getLeafParts(msg.getBody())) {
        actual.add(streamToString(MimeUtility.decodeBody(leaf)));
    }
    assertEquals(Arrays.asList(expectedParts), actual);
}
Also used : ArrayList(java.util.ArrayList) Body(com.fsck.k9.mail.Body)

Aggregations

MimeMessage (com.fsck.k9.mail.internet.MimeMessage)44 Test (org.junit.Test)35 TextBody (com.fsck.k9.mail.internet.TextBody)16 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)14 Part (com.fsck.k9.mail.Part)11 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 ArrayList (java.util.ArrayList)9 BodyPart (com.fsck.k9.mail.BodyPart)8 Message (com.fsck.k9.mail.Message)7 Viewable (com.fsck.k9.mail.internet.Viewable)7 ViewableExtractedText (com.fsck.k9.mailstore.MessageViewInfoExtractor.ViewableExtractedText)7 Intent (android.content.Intent)6 OutputStream (java.io.OutputStream)6 PendingIntent (android.app.PendingIntent)5 Callback (com.fsck.k9.message.MessageBuilder.Callback)5 OpenPgpDataSource (org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSource)5 ComposeCryptoStatus (com.fsck.k9.activity.compose.ComposeCryptoStatus)4 Address (com.fsck.k9.mail.Address)4 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)4