mirror of
https://github.com/rustmailer/bichon.git
synced 2026-08-03 07:48:34 +02:00
update
This commit is contained in:
Generated
+829
-1309
File diff suppressed because it is too large
Load Diff
+1
-1
@@ -60,7 +60,7 @@ futures = "0.3.31"
|
|||||||
utf7-imap = "0.3.2"
|
utf7-imap = "0.3.2"
|
||||||
imap-proto = "0.16.6"
|
imap-proto = "0.16.6"
|
||||||
mail-parser = { version = '0.11.1', features = ["serde"] }
|
mail-parser = { version = '0.11.1', features = ["serde"] }
|
||||||
mail-send = "0.5.2"
|
# mail-send = "0.5.2"
|
||||||
tokio-rustls = { version = "0.26.4", default-features = false, features = [
|
tokio-rustls = { version = "0.26.4", default-features = false, features = [
|
||||||
"ring",
|
"ring",
|
||||||
"tls12",
|
"tls12",
|
||||||
|
|||||||
@@ -16,19 +16,14 @@
|
|||||||
// You should have received a copy of the GNU Affero General Public License
|
// You should have received a copy of the GNU Affero General Public License
|
||||||
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
// along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
|
||||||
use super::error::code::ErrorCode;
|
use super::error::code::ErrorCode;
|
||||||
use super::error::BichonError;
|
use super::error::BichonError;
|
||||||
use mail_parser::{Addr as ImapAddr, Address as ImapAddress};
|
use mail_parser::{Addr as ImapAddr, Address as ImapAddress};
|
||||||
use mail_send::mail_builder::headers::address::Address as SmtpAddress;
|
|
||||||
use mail_send::mail_builder::headers::address::EmailAddress as SmtpEmailAddress;
|
|
||||||
use poem::error::ResponseError;
|
use poem::error::ResponseError;
|
||||||
use poem::Body;
|
use poem::Body;
|
||||||
use poem::{http::StatusCode, Error, Response};
|
use poem::{http::StatusCode, Error, Response};
|
||||||
use poem_openapi::Object;
|
use poem_openapi::Object;
|
||||||
use regex::Regex;
|
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::borrow::Cow;
|
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use tracing::error;
|
use tracing::error;
|
||||||
|
|
||||||
@@ -53,38 +48,6 @@ pub struct Addr {
|
|||||||
pub address: Option<String>,
|
pub address: Option<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Addr {
|
|
||||||
pub fn parse(s: &str) -> Self {
|
|
||||||
let re = Regex::new(r#"(?:(?P<name>.*)\s*)?<(?P<email>[^<>]+)>"#).unwrap();
|
|
||||||
if let Some(caps) = re.captures(s) {
|
|
||||||
let name: Option<String> = caps.name("name").map(|m| m.as_str().trim().into());
|
|
||||||
let email: Option<String> = caps.name("email").map(|m| m.as_str().trim().into());
|
|
||||||
Addr {
|
|
||||||
name: if let Some(n) = name {
|
|
||||||
if n.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(n)
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
address: email,
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
let s_trimmed = s.trim();
|
|
||||||
Addr {
|
|
||||||
name: None,
|
|
||||||
address: if s_trimmed.is_empty() {
|
|
||||||
None
|
|
||||||
} else {
|
|
||||||
Some(s_trimmed.into())
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl std::fmt::Display for Addr {
|
impl std::fmt::Display for Addr {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
match (&self.name, &self.address) {
|
match (&self.name, &self.address) {
|
||||||
@@ -129,50 +92,6 @@ impl<'x> From<&ImapAddress<'x>> for AddrVec {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<'x> From<SmtpEmailAddress<'x>> for Addr {
|
|
||||||
fn from(email: SmtpEmailAddress<'x>) -> Self {
|
|
||||||
Addr {
|
|
||||||
name: email.name.map(|n| n.into_owned()),
|
|
||||||
address: Some(email.email.into_owned()),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'x> From<&SmtpAddress<'x>> for AddrVec {
|
|
||||||
fn from(address: &SmtpAddress<'x>) -> Self {
|
|
||||||
fn collect_addresses<'x>(address: &SmtpAddress<'x>, result: &mut Vec<Addr>) {
|
|
||||||
match address {
|
|
||||||
SmtpAddress::Address(email) => {
|
|
||||||
let addr = Addr::from(email.clone());
|
|
||||||
result.push(addr);
|
|
||||||
}
|
|
||||||
SmtpAddress::Group(group) => {
|
|
||||||
for addr in &group.addresses {
|
|
||||||
collect_addresses(addr, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
SmtpAddress::List(list) => {
|
|
||||||
for addr in list {
|
|
||||||
collect_addresses(addr, result);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
let mut addresses = Vec::new();
|
|
||||||
collect_addresses(address, &mut addresses);
|
|
||||||
AddrVec(addresses)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<'x> From<Addr> for SmtpAddress<'x> {
|
|
||||||
fn from(addr: Addr) -> Self {
|
|
||||||
SmtpAddress::Address(SmtpEmailAddress {
|
|
||||||
name: addr.name.map(Cow::Owned),
|
|
||||||
email: Cow::Owned(addr.address.unwrap_or_default()),
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// #[derive(Serialize)]
|
// #[derive(Serialize)]
|
||||||
// pub struct ErrorResponse {
|
// pub struct ErrorResponse {
|
||||||
// pub message: String,
|
// pub message: String,
|
||||||
|
|||||||
Reference in New Issue
Block a user