Search in sources :

Example 46 with Body

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

the class SmtpTransportTest method sendMessage_with8BitEncoding.

@Test
public void sendMessage_with8BitEncoding() throws Exception {
    Message message = getDefaultMessage();
    MockSmtpServer server = createServerAndSetupForPlainAuthentication("8BITMIME");
    server.expect("MAIL FROM:<user@localhost> BODY=8BITMIME");
    server.output("250 OK");
    server.expect("RCPT TO:<user2@localhost>");
    server.output("250 OK");
    server.expect("DATA");
    server.output("354 End data with <CR><LF>.<CR><LF>");
    server.expect("[message data]");
    server.expect(".");
    server.output("250 OK: queued as 12345");
    server.expect("QUIT");
    server.output("221 BYE");
    server.closeConnection();
    SmtpTransport transport = startServerAndCreateSmtpTransport(server);
    transport.sendMessage(message);
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 47 with Body

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

the class SmtpTransportTest method sendMessage_with8BitEncodingExtensionNotCaseSensitive.

@Test
public void sendMessage_with8BitEncodingExtensionNotCaseSensitive() throws Exception {
    Message message = getDefaultMessage();
    MockSmtpServer server = createServerAndSetupForPlainAuthentication("8bitmime");
    server.expect("MAIL FROM:<user@localhost> BODY=8BITMIME");
    server.output("250 OK");
    server.expect("RCPT TO:<user2@localhost>");
    server.output("250 OK");
    server.expect("DATA");
    server.output("354 End data with <CR><LF>.<CR><LF>");
    server.expect("[message data]");
    server.expect(".");
    server.output("250 OK: queued as 12345");
    server.expect("QUIT");
    server.output("221 BYE");
    server.closeConnection();
    SmtpTransport transport = startServerAndCreateSmtpTransport(server);
    transport.sendMessage(message);
    server.verifyConnectionClosed();
    server.verifyInteractionCompleted();
}
Also used : MimeMessage(com.fsck.k9.mail.internet.MimeMessage) Message(com.fsck.k9.mail.Message) MockSmtpServer(com.fsck.k9.mail.transport.mockServer.MockSmtpServer) XOAuth2ChallengeParserTest(com.fsck.k9.mail.XOAuth2ChallengeParserTest) Test(org.junit.Test)

Example 48 with Body

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

the class MessageDecryptVerifier method findPrimaryPartInMixed.

@Nullable
private static Part findPrimaryPartInMixed(Part part, List<Part> outputExtraParts) {
    Body body = part.getBody();
    boolean isMultipartMixed = part.isMimeType("multipart/mixed") && body instanceof Multipart;
    if (!isMultipartMixed) {
        return null;
    }
    Multipart multipart = (Multipart) body;
    if (multipart.getCount() == 0) {
        return null;
    }
    BodyPart firstBodyPart = multipart.getBodyPart(0);
    Part foundPart;
    if (isPartEncryptedOrSigned(firstBodyPart)) {
        foundPart = firstBodyPart;
    } else {
        foundPart = findPrimaryPartInAlternative(firstBodyPart);
    }
    if (foundPart != null && outputExtraParts != null) {
        for (int i = 1; i < multipart.getCount(); i++) {
            outputExtraParts.add(multipart.getBodyPart(i));
        }
    }
    return foundPart;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Body(com.fsck.k9.mail.Body) Nullable(android.support.annotation.Nullable)

Example 49 with Body

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

the class MessageDecryptVerifier method findSignedParts.

public static List<Part> findSignedParts(Part startPart, MessageCryptoAnnotations messageCryptoAnnotations) {
    List<Part> signedParts = new ArrayList<>();
    Stack<Part> partsToCheck = new Stack<>();
    partsToCheck.push(startPart);
    while (!partsToCheck.isEmpty()) {
        Part part = partsToCheck.pop();
        if (messageCryptoAnnotations.has(part)) {
            CryptoResultAnnotation resultAnnotation = messageCryptoAnnotations.get(part);
            MimeBodyPart replacementData = resultAnnotation.getReplacementData();
            if (replacementData != null) {
                part = replacementData;
            }
        }
        Body body = part.getBody();
        if (isPartMultipartSigned(part)) {
            signedParts.add(part);
            continue;
        }
        if (body instanceof Multipart) {
            Multipart multipart = (Multipart) body;
            for (int i = multipart.getCount() - 1; i >= 0; i--) {
                BodyPart bodyPart = multipart.getBodyPart(i);
                partsToCheck.push(bodyPart);
            }
        }
    }
    return signedParts;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) CryptoResultAnnotation(com.fsck.k9.mailstore.CryptoResultAnnotation) ArrayList(java.util.ArrayList) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack)

Example 50 with Body

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

the class MessageDecryptVerifier method findEncryptedParts.

public static List<Part> findEncryptedParts(Part startPart) {
    List<Part> encryptedParts = new ArrayList<>();
    Stack<Part> partsToCheck = new Stack<>();
    partsToCheck.push(startPart);
    while (!partsToCheck.isEmpty()) {
        Part part = partsToCheck.pop();
        Body body = part.getBody();
        if (isPartMultipartEncrypted(part)) {
            encryptedParts.add(part);
            continue;
        }
        if (body instanceof Multipart) {
            Multipart multipart = (Multipart) body;
            for (int i = multipart.getCount() - 1; i >= 0; i--) {
                BodyPart bodyPart = multipart.getBodyPart(i);
                partsToCheck.push(bodyPart);
            }
        }
    }
    return encryptedParts;
}
Also used : BodyPart(com.fsck.k9.mail.BodyPart) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) Multipart(com.fsck.k9.mail.Multipart) BodyPart(com.fsck.k9.mail.BodyPart) Part(com.fsck.k9.mail.Part) MimeBodyPart(com.fsck.k9.mail.internet.MimeBodyPart) ArrayList(java.util.ArrayList) Body(com.fsck.k9.mail.Body) Stack(java.util.Stack)

Aggregations

Body (com.fsck.k9.mail.Body)44 BodyPart (com.fsck.k9.mail.BodyPart)35 Multipart (com.fsck.k9.mail.Multipart)32 MimeBodyPart (com.fsck.k9.mail.internet.MimeBodyPart)32 Part (com.fsck.k9.mail.Part)29 Test (org.junit.Test)29 TextBody (com.fsck.k9.mail.internet.TextBody)23 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)21 MimeMultipart (com.fsck.k9.mail.internet.MimeMultipart)19 ArrayList (java.util.ArrayList)16 MessagingException (com.fsck.k9.mail.MessagingException)14 BinaryTempFileBody (com.fsck.k9.mail.internet.BinaryTempFileBody)10 ByteArrayOutputStream (java.io.ByteArrayOutputStream)10 Message (com.fsck.k9.mail.Message)9 OutputStream (java.io.OutputStream)9 Stack (java.util.Stack)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)9 K9RobolectricTest (com.fsck.k9.K9RobolectricTest)7 BinaryMemoryBody (com.fsck.k9.mailstore.BinaryMemoryBody)7 InputStream (java.io.InputStream)7