Search in sources :

Example 6 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 7 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)

Example 8 with TextBody

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

the class AttachmentInfoExtractorTest method extractInfoForDb__withNoBody__shouldReturnContentAvailable.

@Test
public void extractInfoForDb__withNoBody__shouldReturnContentAvailable() throws Exception {
    MimeBodyPart part = new MimeBodyPart();
    part.setBody(new TextBody("data"));
    AttachmentViewInfo attachmentViewInfo = attachmentInfoExtractor.extractAttachmentInfoForDatabase(part);
    assertTrue(attachmentViewInfo.isContentAvailable);
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) AttachmentViewInfo(com.fsck.k9.mailstore.AttachmentViewInfo) Test(org.junit.Test)

Example 9 with TextBody

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

the class MessageCryptoHelper method getDataSinkForDecryptedInlineData.

private OpenPgpDataSink<MimeBodyPart> getDataSinkForDecryptedInlineData() {
    return new OpenPgpDataSink<MimeBodyPart>() {

        @Override
        public MimeBodyPart processData(InputStream is) throws IOException {
            try {
                ByteArrayOutputStream decryptedByteOutputStream = new ByteArrayOutputStream();
                IOUtils.copy(is, decryptedByteOutputStream);
                TextBody body = new TextBody(new String(decryptedByteOutputStream.toByteArray()));
                return new MimeBodyPart(body, "text/plain");
            } catch (MessagingException e) {
                Timber.e(e, "MessagingException");
            }
            return null;
        }
    };
}
Also used : TextBody(com.fsck.k9.mail.internet.TextBody) MessagingException(com.fsck.k9.mail.MessagingException) InputStream(java.io.InputStream) OpenPgpDataSink(org.openintents.openpgp.util.OpenPgpApi.OpenPgpDataSink) ByteArrayOutputStream(java.io.ByteArrayOutputStream) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart)

Example 10 with TextBody

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

the class MimeMessageHelper method setBody.

public static void setBody(Part part, Body body) throws MessagingException {
    part.setBody(body);
    if (part instanceof Message) {
        part.setHeader("MIME-Version", "1.0");
    }
    if (body instanceof Multipart) {
        Multipart multipart = ((Multipart) body);
        multipart.setParent(part);
        String mimeType = multipart.getMimeType();
        String contentType = String.format("%s; boundary=\"%s\"", mimeType, multipart.getBoundary());
        part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
        // note: if this is ever changed to 8bit, multipart/signed parts must always be 7bit!
        setEncoding(part, MimeUtil.ENC_7BIT);
    } else if (body instanceof TextBody) {
        String contentType;
        if (MimeUtility.mimeTypeMatches(part.getMimeType(), "text/*")) {
            contentType = String.format("%s;\r\n charset=utf-8", part.getMimeType());
            String name = MimeUtility.getHeaderParameter(part.getContentType(), "name");
            if (name != null) {
                contentType += String.format(";\r\n name=\"%s\"", name);
            }
        } else {
            contentType = part.getMimeType();
        }
        part.setHeader(MimeHeader.HEADER_CONTENT_TYPE, contentType);
        setEncoding(part, MimeUtil.ENC_QUOTED_PRINTABLE);
    } else if (body instanceof RawDataBody) {
        String encoding = ((RawDataBody) body).getEncoding();
        part.setHeader(MimeHeader.HEADER_CONTENT_TRANSFER_ENCODING, encoding);
    }
}
Also used : Multipart(com.fsck.k9.mail.Multipart) Message(com.fsck.k9.mail.Message)

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