Skip to content

Commit c70f7d0

Browse files
link2xtstaktrace
authored andcommitted
fix: don't panic if multipart message has no starting boundary
1 parent d6494b9 commit c70f7d0

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

src/lib.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ pub(crate) fn find_from(line: &str, ix_start: usize, key: &str) -> Option<usize>
120120

121121
fn find_from_u8(line: &[u8], ix_start: usize, key: &[u8]) -> Option<usize> {
122122
assert!(!key.is_empty());
123-
assert!(ix_start < line.len());
123+
assert!(ix_start <= line.len());
124124
if line.len() < key.len() {
125125
return None;
126126
}
@@ -2165,4 +2165,25 @@ mod tests {
21652165
assert_eq!(parts.next().unwrap().ctype.mimetype, "text/plain");
21662166
assert!(parts.next().is_none());
21672167
}
2168+
2169+
#[test]
2170+
fn test_no_parts() {
2171+
let mail = parse_mail(
2172+
concat!(
2173+
"Content-Type: multipart/mixed; boundary=\"foobar\"\n",
2174+
"\n",
2175+
"--foobar--\n"
2176+
)
2177+
.as_bytes(),
2178+
)
2179+
.unwrap();
2180+
2181+
let mut parts = mail.parts();
2182+
let part = parts.next().unwrap();
2183+
assert_eq!(part.ctype.mimetype, "multipart/mixed");
2184+
2185+
let part = parts.next().unwrap();
2186+
assert_eq!(part.ctype.mimetype, "text/plain");
2187+
assert!(parts.next().is_none());
2188+
}
21682189
}

0 commit comments

Comments
 (0)