use of com.fsck.k9.mail.filter.SmtpDataStuffing 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();
}
}
use of com.fsck.k9.mail.filter.SmtpDataStuffing 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();
}
}
Aggregations