Search in sources :

Example 1 with TextBody

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

the class MessagingController method addErrorMessage.

private void addErrorMessage(Account account, String subject, String body) {
    if (!K9.isDebug()) {
        return;
    }
    if (!loopCatch.compareAndSet(false, true)) {
        return;
    }
    try {
        if (body == null || body.length() < 1) {
            return;
        }
        Store localStore = account.getLocalStore();
        LocalFolder localFolder = (LocalFolder) localStore.getFolder(account.getErrorFolderName());
        MimeMessage message = new MimeMessage();
        MimeMessageHelper.setBody(message, new TextBody(body));
        message.setFlag(Flag.X_DOWNLOADED_FULL, true);
        message.setSubject(subject);
        long nowTime = System.currentTimeMillis();
        Date nowDate = new Date(nowTime);
        message.setInternalDate(nowDate);
        message.addSentDate(nowDate, K9.hideTimeZone());
        message.setFrom(new Address(account.getEmail(), "K9mail internal"));
        localFolder.appendMessages(Collections.singletonList(message));
        localFolder.clearMessagesOlderThan(nowTime - (15 * 60 * 1000));
    } catch (Throwable it) {
        Timber.e(it, "Could not save error message to %s", account.getErrorFolderName());
    } finally {
        loopCatch.set(false);
    }
}
Also used : LocalFolder(com.fsck.k9.mailstore.LocalFolder) TextBody(com.fsck.k9.mail.internet.TextBody) Address(com.fsck.k9.mail.Address) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) LocalStore(com.fsck.k9.mailstore.LocalStore) Store(com.fsck.k9.mail.Store) Pop3Store(com.fsck.k9.mail.store.pop3.Pop3Store) Date(java.util.Date)

Example 2 with TextBody

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

the class MessageDecryptVerifierTest method isPartPgpInlineEncryptedOrSigned__withSignedData__shouldReturnTrue.

@Test
public void isPartPgpInlineEncryptedOrSigned__withSignedData__shouldReturnTrue() throws Exception {
    String pgpInlineData = "-----BEGIN PGP SIGNED MESSAGE-----\n" + "Header: Value\n" + "\n" + "-----BEGIN PGP SIGNATURE-----\n" + "Header: Value\n" + "\n" + "base64base64base64base64\n" + "-----END PGP SIGNED MESSAGE-----\n";
    MimeMessage message = new MimeMessage();
    message.setBody(new TextBody(pgpInlineData));
    assertTrue(MessageDecryptVerifier.isPartPgpInlineEncryptedOrSigned(message));
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Test(org.junit.Test)

Example 3 with TextBody

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

the class MessageDecryptVerifierTest method isPgpInlineMethods__withEncryptedDataAndLeadingWhitespace__shouldReturnTrue.

@Test
public void isPgpInlineMethods__withEncryptedDataAndLeadingWhitespace__shouldReturnTrue() throws Exception {
    String pgpInlineData = "\n   \n \n" + "-----BEGIN PGP MESSAGE-----\n" + "Header: Value\n" + "\n" + "base64base64base64base64\n" + "-----END PGP MESSAGE-----\n";
    MimeMessage message = new MimeMessage();
    message.setBody(new TextBody(pgpInlineData));
    assertTrue(MessageDecryptVerifier.isPartPgpInlineEncryptedOrSigned(message));
    assertTrue(MessageDecryptVerifier.isPartPgpInlineEncrypted(message));
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Test(org.junit.Test)

Example 4 with TextBody

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

the class MessageDecryptVerifierTest method isPgpInlineMethods__withPgpInlineData__shouldReturnTrue.

@Test
public void isPgpInlineMethods__withPgpInlineData__shouldReturnTrue() throws Exception {
    String pgpInlineData = "-----BEGIN PGP MESSAGE-----\n" + "Header: Value\n" + "\n" + "base64base64base64base64\n" + "-----END PGP MESSAGE-----\n";
    MimeMessage message = new MimeMessage();
    message.setBody(new TextBody(pgpInlineData));
    assertTrue(MessageDecryptVerifier.isPartPgpInlineEncrypted(message));
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Test(org.junit.Test)

Example 5 with TextBody

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

the class MessageDecryptVerifierTest method findEncryptedPartsShouldReturnEmptyListForSimpleMessage.

@Test
public void findEncryptedPartsShouldReturnEmptyListForSimpleMessage() throws Exception {
    MimeMessage message = new MimeMessage();
    message.setBody(new TextBody("message text"));
    List<Part> encryptedParts = MessageDecryptVerifier.findEncryptedParts(message);
    assertEquals(0, encryptedParts.size());
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeMessage(com.fsck.k9.mail.internet.MimeMessage) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Test(org.junit.Test)

Aggregations

TextBody (com.fsck.k9.mail.internet.TextBody)27 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)16 Test (org.junit.Test)15 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)13 Part (com.fsck.k9.mail.Part)7 ArrayList (java.util.ArrayList)7 Viewable (com.fsck.k9.mail.internet.Viewable)6 ViewableExtractedText (com.fsck.k9.mailstore.MessageViewInfoExtractor.ViewableExtractedText)6 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)5 BodyPart (com.fsck.k9.mail.BodyPart)3 Message (com.fsck.k9.mail.Message)3 MessagingException (com.fsck.k9.mail.MessagingException)3 Address (com.fsck.k9.mail.Address)2 InsertableHtmlContent (com.fsck.k9.message.quote.InsertableHtmlContent)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2 Date (java.util.Date)2 Theory (org.junit.experimental.theories.Theory)2 PendingIntent (android.app.PendingIntent)1 Intent (android.content.Intent)1 Account (com.fsck.k9.Account)1