Search in sources :

Example 1 with LineWrapOutputStream

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

the class SmtpTransport method sendMessageTo.

private void sendMessageTo(List<String> addresses, Message message) throws MessagingException {
    close();
    open();
    if (!m8bitEncodingAllowed) {
        Log.d(LOG_TAG, "Server does not support 8bit transfer encoding");
    }
    // the size of messages, count the message's size before sending it
    if (mLargestAcceptableMessage > 0 && message.hasAttachments()) {
        if (message.calculateSize() > mLargestAcceptableMessage) {
            throw new MessagingException("Message too large for server", true);
        }
    }
    boolean entireMessageSent = false;
    Address[] from = message.getFrom();
    try {
        String fromAddress = from[0].getAddress();
        if (m8bitEncodingAllowed) {
            executeCommand("MAIL FROM:<%s> BODY=8BITMIME", fromAddress);
        } else {
            executeCommand("MAIL FROM:<%s>", fromAddress);
        }
        for (String address : addresses) {
            executeCommand("RCPT TO:<%s>", address);
        }
        executeCommand("DATA");
        EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream(new LineWrapOutputStream(new SmtpDataStuffing(mOut), 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) {
        MessagingException me = new MessagingException("Unable to send message", e);
        me.setPermanentFailure(entireMessageSent);
        throw me;
    } finally {
        close();
    }
}
Also used : EOLConvertingOutputStream(com.fsck.k9.mail.filter.EOLConvertingOutputStream) SmtpDataStuffing(com.fsck.k9.mail.filter.SmtpDataStuffing) SocketAddress(java.net.SocketAddress) InetAddress(java.net.InetAddress) InetSocketAddress(java.net.InetSocketAddress) Address(com.fsck.k9.mail.Address) Inet6Address(java.net.Inet6Address) LineWrapOutputStream(com.fsck.k9.mail.filter.LineWrapOutputStream) MessagingException(com.fsck.k9.mail.MessagingException) URISyntaxException(java.net.URISyntaxException) CertificateValidationException(com.fsck.k9.mail.CertificateValidationException) GeneralSecurityException(java.security.GeneralSecurityException) SSLException(javax.net.ssl.SSLException) SocketException(java.net.SocketException) IOException(java.io.IOException) MessagingException(com.fsck.k9.mail.MessagingException) AuthenticationFailedException(com.fsck.k9.mail.AuthenticationFailedException)

Aggregations

Address (com.fsck.k9.mail.Address)1 AuthenticationFailedException (com.fsck.k9.mail.AuthenticationFailedException)1 CertificateValidationException (com.fsck.k9.mail.CertificateValidationException)1 MessagingException (com.fsck.k9.mail.MessagingException)1 EOLConvertingOutputStream (com.fsck.k9.mail.filter.EOLConvertingOutputStream)1 LineWrapOutputStream (com.fsck.k9.mail.filter.LineWrapOutputStream)1 SmtpDataStuffing (com.fsck.k9.mail.filter.SmtpDataStuffing)1 IOException (java.io.IOException)1 Inet6Address (java.net.Inet6Address)1 InetAddress (java.net.InetAddress)1 InetSocketAddress (java.net.InetSocketAddress)1 SocketAddress (java.net.SocketAddress)1 SocketException (java.net.SocketException)1 URISyntaxException (java.net.URISyntaxException)1 GeneralSecurityException (java.security.GeneralSecurityException)1 SSLException (javax.net.ssl.SSLException)1