1
0
mirror of https://github.com/moparisthebest/k-9 synced 2024-11-27 19:52:17 -05:00

Implemented data stuffing.

This commit is contained in:
cketti 2010-02-05 02:32:32 +00:00
parent 45036ae5c8
commit 0422cae33e
2 changed files with 45 additions and 2 deletions

View File

@ -0,0 +1,43 @@
package com.fsck.k9.mail.transport;
import java.io.FilterOutputStream;
import java.io.IOException;
import java.io.OutputStream;
public class SmtpDataStuffing extends FilterOutputStream
{
private static final int STATE_NORMAL = 0;
private static final int STATE_CR = 1;
private static final int STATE_CRLF = 2;
private int state = STATE_NORMAL;
public SmtpDataStuffing(OutputStream out)
{
super(out);
}
@Override
public void write(int oneByte) throws IOException
{
if (oneByte == '\r')
{
state = STATE_CR;
}
else if ((state == STATE_CR) && (oneByte == '\n'))
{
state = STATE_CRLF;
}
else if ((state == STATE_CRLF) && (oneByte == '.'))
{
// Read <CR><LF><DOT> so this line needs an additional period.
super.write('.');
state = STATE_NORMAL;
}
else
{
state = STATE_NORMAL;
}
super.write(oneByte);
}
}

View File

@ -317,9 +317,9 @@ public class SmtpTransport extends Transport
message.setRecipients(RecipientType.BCC, null);
executeSimpleCommand("DATA");
//TODO: Data stuffing (RFC 821 4.5.2.)
EOLConvertingOutputStream msgOut = new EOLConvertingOutputStream(
new BufferedOutputStream(mOut, 1024));
new SmtpDataStuffing(
new BufferedOutputStream(mOut, 1024)));
message.writeTo(msgOut);