summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias Beyer <mail@beyermatthias.de>2019-12-23 13:05:53 +0100
committerMatthias Beyer <mail@beyermatthias.de>2019-12-26 12:23:21 +0100
commitc6810eb10537c4740d97d25fc04715cde09ffb13 (patch)
treefc88f210e28be90abde33eb23600139c05b7d0bf
parent3fc6fa65546256b254988e68ab34e25efdc1c78f (diff)
Add Disposition::{FormData, Extension} support
Therefore, let Disposition::kind() return a reference to the kind and remove the Copy derive for DispositionKind. Signed-off-by: Matthias Beyer <mail@beyermatthias.de>
-rw-r--r--headers/src/header_components/disposition.rs36
1 files changed, 31 insertions, 5 deletions
diff --git a/headers/src/header_components/disposition.rs b/headers/src/header_components/disposition.rs
index b661fd3..17882bd 100644
--- a/headers/src/header_components/disposition.rs
+++ b/headers/src/header_components/disposition.rs
@@ -33,7 +33,7 @@ pub struct Disposition {
struct DispositionParameters(FileMeta);
/// Represents what kind of disposition is used (Inline/Attachment)
-#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
+#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub enum DispositionKind {
/// Display the body "inline".
///
@@ -41,7 +41,11 @@ pub enum DispositionKind {
/// and then refers to it through its cid (e.g. in a html mail).
Inline,
/// Display the body as an attachment to of the mail.
- Attachment
+ 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 DispositionKind {
@@ -62,14 +66,22 @@ impl Disposition {
Disposition::new( DispositionKind::Attachment, FileMeta::default() )
}
+ pub fn formdata() -> Self {
+ Disposition::new( DispositionKind::FormData, FileMeta::default() )
+ }
+
+ pub fn disposition_extension(s: String) -> Self {
+ Disposition::new( DispositionKind::Extension(s), FileMeta::default() )
+ }
+
/// Create a new disposition with given parameters.
pub fn new( kind: DispositionKind, file_meta: FileMeta ) -> Self {
Disposition { kind, file_meta: DispositionParameters( file_meta ) }
}
/// Return which kind of disposition this represents.
- pub fn kind( &self ) -> DispositionKind {
- self.kind
+ pub fn kind( &self ) -> &DispositionKind {
+ &self.kind
}
/// Returns the parameters associated with the disposition.
@@ -93,7 +105,11 @@ impl Serialize for DispositionKind {
&DispositionKind::Inline =>
serializer.serialize_str("inline"),
&DispositionKind::Attachment =>
- serializer.serialize_str("attachment")
+ serializer.serialize_str("attachment"),
+ &DispositionKind::FormData =>
+ serializer.serialize_str("form-data"),
+ &DispositionKind::Extension(ref s) =>
+ serializer.serialize_str(s),
}
}
}
@@ -118,6 +134,8 @@ impl<'de> Deserialize<'de> for DispositionKind {
Ok(DispositionKind::Inline)
} else if value.eq_ignore_ascii_case("attachment") {
Ok(DispositionKind::Attachment)
+ } else if value.eq_ignore_ascii_case("form-data") {
+ Ok(DispositionKind::FormData)
} else {
Err(E::custom(format!(
"unknown disposition: {:?}", value
@@ -140,6 +158,8 @@ impl<'a> HeaderTryFrom<&'a str> for Disposition {
Ok(Disposition::inline())
} else if text.eq_ignore_ascii_case("Attachment") {
Ok(Disposition::attachment())
+ } else if text.eq_ignore_ascii_case("form-data") {
+ Ok(Disposition::formdata())
} else {
let mut err = ComponentCreationError::new("Disposition");
err.set_str_context(text);
@@ -214,6 +234,12 @@ impl EncodableInHeader for Disposition {
Attachment => {
handle.write_str(SoftAsciiStr::from_unchecked("attachment"))?;
}
+ FormData => {
+ handle.write_str(SoftAsciiStr::from_unchecked("form-data"))?;
+ }
+ Extension(ref s) => {
+ handle.write_str(SoftAsciiStr::from_unchecked(s))?;
+ }
}
self.file_meta.encode( handle )?;
Ok( () )