summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJos van den Oever <jos@vandenoever.info>2016-12-03 15:56:07 +0100
committerJos van den Oever <jos@vandenoever.info>2016-12-03 15:56:07 +0100
commitfb01124256b82553183d529db72c66fd542bcd22 (patch)
tree8f21faef664cf77825a8fc1c4971e12b95b3c14a /src
parenta3d7179225daf64648e7fe4487ed0232aa1876c7 (diff)
Fix panic when the mail body is missing
Diffstat (limited to 'src')
-rw-r--r--src/lib.rs12
1 files changed, 11 insertions, 1 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 530dba9..dfba9e1 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -649,7 +649,9 @@ pub fn parse_mail(raw_data: &[u8]) -> Result<ParsedMail, MailParseError> {
body: &raw_data[ix_body..],
subparts: Vec::<ParsedMail>::new(),
};
- if result.ctype.mimetype.starts_with("multipart/") && result.ctype.boundary.is_some() {
+ if result.ctype.mimetype.starts_with("multipart/")
+ && result.ctype.boundary.is_some()
+ && raw_data.len() > ix_body {
let boundary = String::from("--") + result.ctype.boundary.as_ref().unwrap();
if let Some(ix_body_end) = find_from_u8(raw_data, ix_body, boundary.as_bytes()) {
result.body = &raw_data[ix_body..ix_body_end];
@@ -946,4 +948,12 @@ mod tests {
assert_eq!(mail.ctype.mimetype, "text/html");
assert_eq!(mail.get_body().unwrap(), "hello world");
}
+ #[test]
+ fn test_content_type() {
+ let parsed = parse_mail(
+ "Content-Type: multipart/related; boundary=\"----=_\"\n"
+ .as_bytes())
+ .unwrap();
+ assert_eq!(parsed.headers[0].get_key().unwrap(), "Content-Type");
+ }
}