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;
}
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);
}
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));
}
Aggregations