Use of associated types + Identity and EmailSubmission helpers.
parent
1b27e6e146
commit
70df0e341c
|
@ -1,4 +1,6 @@
|
|||
use crate::{Get, core::get::GetObject, Set};
|
||||
use std::collections::HashMap;
|
||||
|
||||
use crate::{core::get::GetObject, Get, Set};
|
||||
|
||||
use super::{Address, Delivered, DeliveryStatus, Displayed, EmailSubmission, UndoStatus};
|
||||
|
||||
|
@ -7,6 +9,10 @@ impl EmailSubmission<Get> {
|
|||
self.id.as_ref().unwrap()
|
||||
}
|
||||
|
||||
pub fn unwrap_id(self) -> String {
|
||||
self.id.unwrap()
|
||||
}
|
||||
|
||||
pub fn identity_id(&self) -> &str {
|
||||
self.identity_id.as_ref().unwrap()
|
||||
}
|
||||
|
@ -35,10 +41,14 @@ impl EmailSubmission<Get> {
|
|||
self.undo_status.as_ref().unwrap()
|
||||
}
|
||||
|
||||
pub fn delivery_status(&self, email: &str) -> Option<&DeliveryStatus> {
|
||||
pub fn delivery_status_email(&self, email: &str) -> Option<&DeliveryStatus> {
|
||||
self.delivery_status.as_ref().and_then(|ds| ds.get(email))
|
||||
}
|
||||
|
||||
pub fn delivery_status(&self) -> Option<&HashMap<String, DeliveryStatus>> {
|
||||
self.delivery_status.as_ref()
|
||||
}
|
||||
|
||||
pub fn dsn_blob_ids(&self) -> Option<&[String]> {
|
||||
self.dsn_blob_ids.as_deref()
|
||||
}
|
||||
|
@ -66,6 +76,15 @@ impl Address<Get> {
|
|||
}
|
||||
|
||||
impl DeliveryStatus {
|
||||
#[cfg(feature = "debug")]
|
||||
pub fn new(smtp_reply: impl Into<String>, delivered: Delivered, displayed: Displayed) -> Self {
|
||||
Self {
|
||||
smtp_reply: smtp_reply.into(),
|
||||
delivered,
|
||||
displayed,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn smtp_reply(&self) -> &str {
|
||||
&self.smtp_reply
|
||||
}
|
||||
|
|
|
@ -34,14 +34,15 @@ impl Client {
|
|||
.created(&id)
|
||||
}
|
||||
|
||||
pub async fn email_submission_create_envelope<T, U>(
|
||||
pub async fn email_submission_create_envelope<S, T, U>(
|
||||
&mut self,
|
||||
email_id: impl Into<String>,
|
||||
identity_id: impl Into<String>,
|
||||
mail_from: U,
|
||||
mail_from: S,
|
||||
rcpt_to: T,
|
||||
) -> crate::Result<EmailSubmission<Get>>
|
||||
where
|
||||
S: Into<Address>,
|
||||
T: IntoIterator<Item = U>,
|
||||
U: Into<Address>,
|
||||
{
|
||||
|
|
|
@ -89,7 +89,7 @@ pub struct Address<State = Get> {
|
|||
parameters: Option<HashMap<String, Option<String>>>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum UndoStatus {
|
||||
#[serde(rename = "pending")]
|
||||
Pending,
|
||||
|
@ -99,7 +99,7 @@ pub enum UndoStatus {
|
|||
Canceled,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub struct DeliveryStatus {
|
||||
#[serde(rename = "smtpReply")]
|
||||
smtp_reply: String,
|
||||
|
@ -111,7 +111,7 @@ pub struct DeliveryStatus {
|
|||
displayed: Displayed,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum Delivered {
|
||||
#[serde(rename = "queued")]
|
||||
Queued,
|
||||
|
@ -123,7 +123,7 @@ pub enum Delivered {
|
|||
Unknown,
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, Serialize, Deserialize)]
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize, PartialEq, Eq)]
|
||||
pub enum Displayed {
|
||||
#[serde(rename = "unknown")]
|
||||
Unknown,
|
||||
|
|
|
@ -15,15 +15,13 @@ impl EmailSubmission<Set> {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn envelope<T, U>(&mut self, mail_from: U, rcpt_to: T) -> &mut Self
|
||||
pub fn envelope<S, T, U>(&mut self, mail_from: S, rcpt_to: T) -> &mut Self
|
||||
where
|
||||
S: Into<Address>,
|
||||
T: IntoIterator<Item = U>,
|
||||
U: Into<Address>,
|
||||
{
|
||||
self.envelope = Some(Envelope {
|
||||
mail_from: mail_from.into(),
|
||||
rcpt_to: rcpt_to.into_iter().map(|s| s.into()).collect(),
|
||||
});
|
||||
self.envelope = Some(Envelope::new(mail_from, rcpt_to));
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -70,21 +68,37 @@ impl SetObject for EmailSubmission<Get> {
|
|||
}
|
||||
}
|
||||
|
||||
impl Address {
|
||||
pub fn new(email: String) -> Address<Set> {
|
||||
Address {
|
||||
_state: Default::default(),
|
||||
email,
|
||||
parameters: None,
|
||||
impl Envelope {
|
||||
pub fn new<S, T, U>(mail_from: S, rcpt_to: T) -> Envelope
|
||||
where
|
||||
S: Into<Address>,
|
||||
T: IntoIterator<Item = U>,
|
||||
U: Into<Address>,
|
||||
{
|
||||
Envelope {
|
||||
mail_from: mail_from.into(),
|
||||
rcpt_to: rcpt_to.into_iter().map(|s| s.into()).collect(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl Address<Set> {
|
||||
pub fn parameter(mut self, parameter: String, value: Option<String>) -> Self {
|
||||
pub fn new(email: impl Into<String>) -> Address<Set> {
|
||||
Address {
|
||||
_state: Default::default(),
|
||||
email: email.into(),
|
||||
parameters: None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn parameter(
|
||||
mut self,
|
||||
parameter: impl Into<String>,
|
||||
value: Option<impl Into<String>>,
|
||||
) -> Self {
|
||||
self.parameters
|
||||
.get_or_insert_with(HashMap::new)
|
||||
.insert(parameter, value);
|
||||
.insert(parameter.into(), value.map(|s| s.into()));
|
||||
self
|
||||
}
|
||||
}
|
||||
|
@ -108,3 +122,23 @@ impl From<&str> for Address {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Address<Set>> for Address<Get> {
|
||||
fn from(addr: Address<Set>) -> Self {
|
||||
Address {
|
||||
_state: Default::default(),
|
||||
email: addr.email,
|
||||
parameters: addr.parameters,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl From<Address<Get>> for Address<Set> {
|
||||
fn from(addr: Address<Get>) -> Self {
|
||||
Address {
|
||||
_state: Default::default(),
|
||||
email: addr.email,
|
||||
parameters: addr.parameters,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue