Search in sources :

Example 86 with Address

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

the class MimeMessageParseTest method getRecipients_withDeliveredTo.

@Test
public void getRecipients_withDeliveredTo() throws Exception {
    MimeMessage msg = parseWithoutRecurse(toStream("From: <adam@example.org>\r\n" + "To: <eva@example.org>\r\n" + "Delivered-To: <test@mail.com>\r\n" + "Subject: Testmail\r\n" + "MIME-Version: 1.0\r\n" + "Content-type: text/plain\r\n" + "Content-Transfer-Encoding: 7bit\r\n" + "\r\n" + "this is some test text."));
    Address[] deliveredToAddresses = msg.getRecipients(RecipientType.DELIVERED_TO);
    assertEquals(1, deliveredToAddresses.length);
    assertEquals(new Address("<test@mail.com>"), deliveredToAddresses[0]);
}
Also used : Address(com.fsck.k9.mail.Address) Test(org.junit.Test)

Example 87 with Address

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

the class SmtpTransport method sendMessage.

@Override
public void sendMessage(Message message) throws MessagingException {
    Set<String> addresses = new LinkedHashSet<>();
    for (Address address : message.getRecipients(RecipientType.TO)) {
        addresses.add(address.getAddress());
    }
    for (Address address : message.getRecipients(RecipientType.CC)) {
        addresses.add(address.getAddress());
    }
    for (Address address : message.getRecipients(RecipientType.BCC)) {
        addresses.add(address.getAddress());
    }
    message.removeHeader("Bcc");
    if (addresses.isEmpty()) {
        return;
    }
    close();
    open();
    // the size of messages, count the message's size before sending it
    if (largestAcceptableMessage > 0 && message.hasAttachments()) {
        if (message.calculateSize() > largestAcceptableMessage) {
            throw new MessagingException("Message too large for server", true);
        }
    }
    boolean entireMessageSent = false;
    try {
        String mailFrom = constructSmtpMailFromCommand(message.getFrom(), is8bitEncodingAllowed);
        if (isPipeliningSupported) {
            Queue<String> pipelinedCommands = new LinkedList<>();
            pipelinedCommands.add(mailFrom);
            for (String address : addresses) {
                pipelinedCommands.add(String.format("RCPT TO:<%s>", address));
            }
            executePipelinedCommands(pipelinedCommands);
            readPipelinedResponse(pipelinedCommands);
        } else {
            executeCommand(mailFrom);
            for (String address : addresses) {
                executeCommand("RCPT TO:<%s>", address);
            }
        }
        executeCommand("DATA");
        EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream(new LineWrapOutputStream(new SmtpDataStuffing(outputStream), 1000));
        message.writeTo(msgOut);
        msgOut.endWithCrLfAndFlush();
        // After the "\r\n." is attempted, we may have sent the message
        entireMessageSent = true;
        executeCommand(".");
    } catch (NegativeSmtpReplyException e) {
        throw e;
    } catch (Exception e) {
        throw new MessagingException("Unable to send message", entireMessageSent, e);
    } finally {
        close();
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) EOLConvertingOutputStream(com.fsck.k9.mail.filter.EOLConvertingOutputStream) SocketAddress(java.net.SocketAddress) InetAddress(java.net.InetAddress) InetSocketAddress(java.net.InetSocketAddress) Address(com.fsck.k9.mail.Address) Inet6Address(java.net.Inet6Address) MessagingException(com.fsck.k9.mail.MessagingException) LinkedList(java.util.LinkedList) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) SocketException(java.net.SocketException) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) SSLException(javax.net.ssl.SSLException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException) SmtpDataStuffing(com.fsck.k9.mail.filter.SmtpDataStuffing) LineWrapOutputStream(com.fsck.k9.mail.filter.LineWrapOutputStream)

Aggregations

Address (com.fsck.k9.mail.Address)72 Test (org.junit.Test)40 Uri (android.net.Uri)13 RobolectricTest (com.fsck.k9.RobolectricTest)12 Message (com.fsck.k9.mail.Message)10 Date (java.util.Date)8 MimeMessage (com.fsck.k9.mail.internet.MimeMessage)7 ArrayList (java.util.ArrayList)7 MessagingException (com.fsck.k9.mail.MessagingException)6 Contacts (com.fsck.k9.helper.Contacts)5 Recipient (com.fsck.k9.view.RecipientSelectView.Recipient)5 AddressStyle (com.zegoggles.smssync.preferences.AddressStyle)5 IOException (java.io.IOException)5 Intent (android.content.Intent)4 Cursor (android.database.Cursor)4 MatrixCursor (android.database.MatrixCursor)4 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)4 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)4 TextBody (com.fsck.k9.mail.internet.TextBody)4 SpannableString (android.text.SpannableString)3