summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-12-26 12:32:41 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-12-26 12:32:41 +0100
commiteb3c61811fda288237ec6824da41da099b1d5131 (patch)
tree70dd2a747236a39411fa33a213842f20aee7ed4a
parent6ab56858d225fd097ba1c60da7f3f7ba126e7e38 (diff)
fixup! Add Disposition::{FormData, Extension} support
-rw-r--r--parser/src/parser.rs49
1 files changed, 13 insertions, 36 deletions
diff --git a/parser/src/parser.rs b/parser/src/parser.rs
index a1cbb53..41cca95 100644
--- a/parser/src/parser.rs
+++ b/parser/src/parser.rs
@@ -4,6 +4,8 @@ use failure::Fallible as Result;
use charset::decode_latin1;
use charset::Charset;
+use mail_headers::header_components::DispositionKind;
+
use crate::body::Body;
use crate::util::*;
use crate::header::*;
@@ -89,38 +91,13 @@ pub fn parse_content_type(header: &str) -> ParsedContentType {
}
}
-/// The possible disposition types in a Content-Disposition header. A more
-/// comprehensive list of IANA-recognized types can be found at
-/// https://www.iana.org/assignments/cont-disp/cont-disp.xhtml. This library
-/// only enumerates the types most commonly found in email messages, and
-/// provides the `Extension` value for holding all other types.
-#[derive(Debug, Clone, PartialEq)]
-pub enum DispositionType {
- /// Default value, indicating the content is to be displayed inline as
- /// part of the enclosing document.
- Inline,
- /// A disposition indicating the content is not meant for inline display,
- /// but whose content can be accessed for use.
- Attachment,
- /// A disposition indicating the content contains a form submission.
- FormData,
- /// Extension type to hold any disposition not explicitly enumerated.
- Extension(String),
-}
-
-impl Default for DispositionType {
- fn default() -> Self {
- DispositionType::Inline
- }
-}
-
/// Convert the string represented disposition type to enum.
-fn parse_disposition_type(disposition: &str) -> DispositionType {
+fn parse_disposition_type(disposition: &str) -> DispositionKind {
match &disposition.to_lowercase()[..] {
- "inline" => DispositionType::Inline,
- "attachment" => DispositionType::Attachment,
- "form-data" => DispositionType::FormData,
- extension => DispositionType::Extension(extension.to_string()),
+ "inline" => DispositionKind::Inline,
+ "attachment" => DispositionKind::Attachment,
+ "form-data" => DispositionKind::FormData,
+ extension => DispositionKind::Extension(extension.to_string()),
}
}
@@ -131,7 +108,7 @@ fn parse_disposition_type(disposition: &str) -> DispositionType {
pub struct ParsedContentDisposition {
/// The disposition type of the Content-Disposition header. If this
/// is an extension type, the string will be lowercased.
- pub disposition: DispositionType,
+ pub disposition: DispositionKind,
/// The additional params of Content-Disposition, e.g. filename. The
/// keys in the map will be lowercased, and the values will have any
/// enclosing quotes stripped.
@@ -145,12 +122,12 @@ pub struct ParsedContentDisposition {
/// # Examples
/// ```
/// use header::parse_header;
-/// use parser::{parse_content_disposition, DispositionType};
+/// use parser::{parse_content_disposition, DispositionKind};
/// let (parsed, _) = parse_header(
/// b"Content-Disposition: attachment; filename=\"yummy dummy\"")
/// .unwrap();
/// let dis = parse_content_disposition(&parsed.get_value().unwrap());
-/// assert_eq!(dis.disposition, DispositionType::Attachment);
+/// assert_eq!(dis.disposition, DispositionKind::Attachment);
/// assert_eq!(dis.params.get("name"), None);
/// assert_eq!(dis.params.get("filename"), Some(&"yummy dummy".to_string()));
/// ```
@@ -678,14 +655,14 @@ mod tests {
#[test]
fn test_parse_content_disposition() {
let dis = parse_content_disposition("inline");
- assert_eq!(dis.disposition, DispositionType::Inline);
+ assert_eq!(dis.disposition, DispositionKind::Inline);
assert_eq!(dis.params.get("name"), None);
assert_eq!(dis.params.get("filename"), None);
let dis = parse_content_disposition(
" attachment; x=y; charset=\"fake\" ; x2=y2; name=\"King Joffrey.death\"",
);
- assert_eq!(dis.disposition, DispositionType::Attachment);
+ assert_eq!(dis.disposition, DispositionKind::Attachment);
assert_eq!(
dis.params.get("name"),
Some(&"King Joffrey.death".to_string())
@@ -693,7 +670,7 @@ mod tests {
assert_eq!(dis.params.get("filename"), None);
let dis = parse_content_disposition(" form-data");
- assert_eq!(dis.disposition, DispositionType::FormData);
+ assert_eq!(dis.disposition, DispositionKind::FormData);
assert_eq!(dis.params.get("name"), None);
assert_eq!(dis.params.get("filename"), None);
}