commit
47b86f6146
2 changed files with 56 additions and 1 deletions
|
@ -9,7 +9,7 @@ public class SmtpDataStuffing extends FilterOutputStream {
|
|||
private static final int STATE_CR = 1;
|
||||
private static final int STATE_CRLF = 2;
|
||||
|
||||
private int state = STATE_NORMAL;
|
||||
private int state = STATE_CRLF;
|
||||
|
||||
public SmtpDataStuffing(OutputStream out) {
|
||||
super(out);
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
package com.fsck.k9.mail.filter;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import okio.Buffer;
|
||||
import okio.ByteString;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static junit.framework.Assert.assertEquals;
|
||||
|
||||
|
||||
public class SmtpDataStuffingTest {
|
||||
private Buffer buffer;
|
||||
private SmtpDataStuffing smtpDataStuffing;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
buffer = new Buffer();
|
||||
smtpDataStuffing = new SmtpDataStuffing(buffer.outputStream());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dotAtStartOfLine() throws IOException {
|
||||
smtpDataStuffing.write(bytesFor("Hello dot\r\n."));
|
||||
|
||||
assertEquals("Hello dot\r\n..", buffer.readUtf8());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dotAtStartOfStream() throws IOException {
|
||||
smtpDataStuffing.write(bytesFor(".Hello dots"));
|
||||
|
||||
assertEquals("..Hello dots", buffer.readUtf8());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void linesNotStartingWithDot() throws IOException {
|
||||
smtpDataStuffing.write(bytesFor("Hello\r\nworld\r\n"));
|
||||
|
||||
assertEquals("Hello\r\nworld\r\n", buffer.readUtf8());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void dotsThatNeedStuffingMixedWithOnesThatDoNot() throws IOException {
|
||||
smtpDataStuffing.write(bytesFor("\r\n.Hello . dots.\r\n..\r\n.\r\n..."));
|
||||
|
||||
assertEquals("\r\n..Hello . dots.\r\n...\r\n..\r\n....", buffer.readUtf8());
|
||||
}
|
||||
|
||||
private byte[] bytesFor(String input) {
|
||||
return ByteString.encodeUtf8(input).toByteArray();
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue