Skip to content

Commit

Permalink
fix(transport-smtp): Fix transparency codec
Browse files Browse the repository at this point in the history
It fails to add transparency when a period is preceded by two
successive CRLF.
  • Loading branch information
paolobarbolini authored and amousset committed May 22, 2021
1 parent 1d82491 commit 93458d0
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/transport/smtp/client/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,15 @@ impl ClientCodec {
match self.escape_count {
0 => self.escape_count = if *byte == b'\r' { 1 } else { 0 },
1 => self.escape_count = if *byte == b'\n' { 2 } else { 0 },
2 => self.escape_count = if *byte == b'.' { 3 } else { 0 },
2 => {
self.escape_count = if *byte == b'.' {
3
} else if *byte == b'\r' {
1
} else {
0
}
}
_ => unreachable!(),
}
if self.escape_count == 3 {
Expand Down Expand Up @@ -111,6 +119,7 @@ mod test {
let mut buf: Vec<u8> = vec![];

codec.encode(b"test\r\n", &mut buf);
codec.encode(b"test\r\n\r\n", &mut buf);
codec.encode(b".\r\n", &mut buf);
codec.encode(b"\r\ntest", &mut buf);
codec.encode(b"te\r\n.\r\nst", &mut buf);
Expand All @@ -121,7 +130,7 @@ mod test {
codec.encode(b"test", &mut buf);
assert_eq!(
String::from_utf8(buf).unwrap(),
"test\r\n..\r\n\r\ntestte\r\n..\r\nsttesttest.test\n.test\ntest"
"test\r\ntest\r\n\r\n..\r\n\r\ntestte\r\n..\r\nsttesttest.test\n.test\ntest"
);
}

Expand Down

0 comments on commit 93458d0

Please sign in to comment.