#[non_exhaustive]pub enum MessageValidationError {
MissingFrom,
SenderWithoutFrom,
MissingRecipients,
#[non_exhaustive] ReservedHeaderName {
name: String,
},
SubjectContainsInvalidChars,
#[non_exhaustive] MailboxDisplayNameContainsInvalidChars {
location: &'static str,
},
#[non_exhaustive] AttachmentMetadataContainsInvalidChars {
field: &'static str,
},
}Expand description
Reasons a Message failed Message::validate_basic (and therefore
cannot be promoted into an OutboundMessage).
use email_message::{Address, Body, Header, Mailbox, Message, MessageValidationError};
let from: Mailbox = "alice@example.com".parse().unwrap();
let to = Address::Mailbox("bob@example.com".parse().unwrap());
// A subject carrying a CRLF injection is rejected at build time:
let error = Message::builder(Body::text("hello"))
.from_mailbox(from.clone())
.add_to(to.clone())
.subject("hi\r\nBcc: attacker@example.com")
.build()
.unwrap_err();
assert_eq!(error, MessageValidationError::SubjectContainsInvalidChars);
// A custom header that collides with a structured field is rejected:
let error = Message::builder(Body::text("hello"))
.from_mailbox(from)
.add_to(to)
.add_header(Header::new("Subject", "shadow").unwrap())
.build()
.unwrap_err();
assert!(matches!(
error,
MessageValidationError::ReservedHeaderName { ref name, .. } if name == "Subject"
));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
MissingFrom
SenderWithoutFrom
MissingRecipients
#[non_exhaustive]ReservedHeaderName
Fields
This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
SubjectContainsInvalidChars
#[non_exhaustive]MailboxDisplayNameContainsInvalidChars
Fields
This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
#[non_exhaustive]AttachmentMetadataContainsInvalidChars
Trait Implementations§
Source§impl Clone for MessageValidationError
impl Clone for MessageValidationError
Source§fn clone(&self) -> MessageValidationError
fn clone(&self) -> MessageValidationError
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for MessageValidationError
impl Debug for MessageValidationError
Source§impl Display for MessageValidationError
impl Display for MessageValidationError
Source§impl Error for MessageValidationError
impl Error for MessageValidationError
1.30.0 · Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
👎Deprecated since 1.42.0:
use the Display impl or to_string()
Source§impl PartialEq for MessageValidationError
impl PartialEq for MessageValidationError
impl Eq for MessageValidationError
impl StructuralPartialEq for MessageValidationError
Auto Trait Implementations§
impl Freeze for MessageValidationError
impl RefUnwindSafe for MessageValidationError
impl Send for MessageValidationError
impl Sync for MessageValidationError
impl Unpin for MessageValidationError
impl UnsafeUnpin for MessageValidationError
impl UnwindSafe for MessageValidationError
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more