Search in sources :

Example 51 with MimeMessage

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

the class ReconstructMessageFromDatabaseTest method readMessageFromDatabase.

protected LocalMessage readMessageFromDatabase(LocalFolder folder, MimeMessage message) throws MessagingException {
    LocalMessage localMessage = folder.getMessage(message.getUid());
    FetchProfile fp = new FetchProfile();
    fp.add(FetchProfile.Item.ENVELOPE);
    fp.add(FetchProfile.Item.BODY);
    folder.fetch(Collections.singletonList(localMessage), fp, null);
    folder.close();
    return localMessage;
}
Also used : FetchProfile(com.fsck.k9.mail.FetchProfile)

Example 52 with MimeMessage

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

the class ReconstructMessageFromDatabaseTest method testAddMissingPart.

public void testAddMissingPart() throws MessagingException, IOException {
    LocalFolder folder = createFolderInDatabase();
    MimeMessage message = new MimeMessage();
    message.addHeader("To", "to@example.com");
    message.addHeader("MIME-Version", "1.0");
    message.addHeader("Content-Type", "text/plain");
    message.setServerExtra("text");
    saveMessageToDatabase(folder, message);
    LocalMessage localMessage = readMessageFromDatabase(folder, message);
    assertEquals("to@example.com", localMessage.getHeader("To")[0]);
    assertEquals("text/plain", localMessage.getHeader(MimeHeader.HEADER_CONTENT_TYPE)[0]);
    assertEquals("text", localMessage.getServerExtra());
    assertNull(localMessage.getBody());
    Body body = new BinaryMemoryBody("Test message body".getBytes(), MimeUtil.ENC_7BIT);
    localMessage.setBody(body);
    folder.addPartToMessage(localMessage, localMessage);
    LocalMessage completeLocalMessage = readMessageFromDatabase(folder, message);
    String reconstructedMessage = writeMessageToString(completeLocalMessage);
    assertEquals("To: to@example.com\r\n" + "MIME-Version: 1.0\r\n" + "Content-Type: text/plain\r\n" + "\r\n" + "Test message body", reconstructedMessage);
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) BinaryTempFileBody(com.fsck.k9.mail.internet.BinaryTempFileBody) Body(com.fsck.k9.mail.Body)

Example 53 with MimeMessage

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

the class EmailProviderTest method query_forAThreadOfMessages_returnsMessage.

@Test
public void query_forAThreadOfMessages_returnsMessage() throws MessagingException {
    Account account = Preferences.getPreferences(getContext()).newAccount();
    account.getUuid();
    Message message = new MimeMessage();
    message.setSubject("Test Subject");
    message.setSentDate(new GregorianCalendar(2016, 1, 2).getTime(), false);
    account.getLocalStore().getFolder("Inbox").appendMessages(Collections.singletonList(message));
    //Now get the thread id we just put in.
    Cursor cursor = getProvider().query(Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/messages"), new String[] { EmailProvider.MessageColumns.ID, EmailProvider.MessageColumns.FOLDER_ID, EmailProvider.ThreadColumns.ROOT }, "", new String[] {}, EmailProvider.MessageColumns.DATE);
    assertNotNull(cursor);
    cursor.moveToFirst();
    String threadId = cursor.getString(2);
    //Now check the message is listed under that thread
    Cursor threadCursor = getProvider().query(Uri.parse("content://" + EmailProvider.AUTHORITY + "/account/" + account.getUuid() + "/thread/" + threadId), new String[] { EmailProvider.MessageColumns.ID, EmailProvider.MessageColumns.FOLDER_ID, EmailProvider.ThreadColumns.ROOT, EmailProvider.MessageColumns.SUBJECT, EmailProvider.MessageColumns.DATE }, "", new String[] {}, EmailProvider.MessageColumns.DATE);
    assertNotNull(threadCursor);
    assertTrue(threadCursor.moveToFirst());
    assertEquals(message.getSubject(), threadCursor.getString(3));
}
Also used : Account(com.fsck.k9.Account) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) GregorianCalendar(java.util.GregorianCalendar) Cursor(android.database.Cursor) Test(org.junit.Test)

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