mirror of
https://github.com/chatmail/core.git
synced 2026-04-20 06:56:29 +03:00
Fix nightly clippy errors
This commit is contained in:
10
src/chat.rs
10
src/chat.rs
@@ -2044,15 +2044,7 @@ pub async fn get_chat_media(
|
||||
},
|
||||
],
|
||||
|row| row.get::<_, MsgId>(0),
|
||||
|ids| {
|
||||
let mut ret = Vec::new();
|
||||
for id in ids {
|
||||
if let Ok(msg_id) = id {
|
||||
ret.push(msg_id)
|
||||
}
|
||||
}
|
||||
Ok(ret)
|
||||
},
|
||||
|ids| Ok(ids.flatten().collect()),
|
||||
)
|
||||
.await?;
|
||||
Ok(list)
|
||||
|
||||
@@ -533,14 +533,14 @@ async fn try_imap_one_param(
|
||||
match imap.connect(context).await {
|
||||
Err(err) => {
|
||||
info!(context, "failure: {}", err);
|
||||
return Err(ConfigurationError {
|
||||
Err(ConfigurationError {
|
||||
config: inf,
|
||||
msg: err.to_string(),
|
||||
});
|
||||
})
|
||||
}
|
||||
Ok(()) => {
|
||||
info!(context, "success: {}", inf);
|
||||
return Ok(imap);
|
||||
Ok(imap)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -618,10 +618,10 @@ pub enum Error {
|
||||
},
|
||||
|
||||
#[error("Failed to get URL: {0}")]
|
||||
ReadUrlError(#[from] self::read_url::Error),
|
||||
ReadUrl(#[from] self::read_url::Error),
|
||||
|
||||
#[error("Number of redirection is exceeded")]
|
||||
RedirectionError,
|
||||
Redirection,
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -203,7 +203,7 @@ pub(crate) async fn outlk_autodiscover(
|
||||
}
|
||||
}
|
||||
}
|
||||
Err(Error::RedirectionError)
|
||||
Err(Error::Redirection)
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -25,16 +25,20 @@ pub(crate) struct ServerParams {
|
||||
}
|
||||
|
||||
impl ServerParams {
|
||||
fn expand_usernames(mut self, addr: &str) -> Vec<ServerParams> {
|
||||
fn expand_usernames(self, addr: &str) -> Vec<ServerParams> {
|
||||
let mut res = Vec::new();
|
||||
|
||||
if self.username.is_empty() {
|
||||
self.username = addr.to_string();
|
||||
res.push(self.clone());
|
||||
res.push(Self {
|
||||
username: addr.to_string(),
|
||||
..self.clone()
|
||||
});
|
||||
|
||||
if let Some(at) = addr.find('@') {
|
||||
self.username = addr.split_at(at).0.to_string();
|
||||
res.push(self);
|
||||
res.push(Self {
|
||||
username: addr.split_at(at).0.to_string(),
|
||||
..self
|
||||
});
|
||||
}
|
||||
} else {
|
||||
res.push(self)
|
||||
@@ -42,24 +46,28 @@ impl ServerParams {
|
||||
res
|
||||
}
|
||||
|
||||
fn expand_hostnames(mut self, param_domain: &str) -> Vec<ServerParams> {
|
||||
let mut res = Vec::new();
|
||||
fn expand_hostnames(self, param_domain: &str) -> Vec<ServerParams> {
|
||||
if self.hostname.is_empty() {
|
||||
self.hostname = param_domain.to_string();
|
||||
res.push(self.clone());
|
||||
|
||||
self.hostname = match self.protocol {
|
||||
Protocol::Imap => "imap.".to_string() + param_domain,
|
||||
Protocol::Smtp => "smtp.".to_string() + param_domain,
|
||||
};
|
||||
res.push(self.clone());
|
||||
|
||||
self.hostname = "mail.".to_string() + param_domain;
|
||||
res.push(self);
|
||||
vec![
|
||||
Self {
|
||||
hostname: param_domain.to_string(),
|
||||
..self.clone()
|
||||
},
|
||||
Self {
|
||||
hostname: match self.protocol {
|
||||
Protocol::Imap => "imap.".to_string() + param_domain,
|
||||
Protocol::Smtp => "smtp.".to_string() + param_domain,
|
||||
},
|
||||
..self.clone()
|
||||
},
|
||||
Self {
|
||||
hostname: "mail.".to_string() + param_domain,
|
||||
..self
|
||||
},
|
||||
]
|
||||
} else {
|
||||
res.push(self);
|
||||
vec![self]
|
||||
}
|
||||
res
|
||||
}
|
||||
|
||||
fn expand_ports(mut self) -> Vec<ServerParams> {
|
||||
@@ -78,39 +86,47 @@ impl ServerParams {
|
||||
}
|
||||
}
|
||||
|
||||
let mut res = Vec::new();
|
||||
if self.port == 0 {
|
||||
// Neither port nor security is set.
|
||||
//
|
||||
// Try common secure combinations.
|
||||
|
||||
// Try STARTTLS
|
||||
self.socket = Socket::Starttls;
|
||||
self.port = match self.protocol {
|
||||
Protocol::Imap => 143,
|
||||
Protocol::Smtp => 587,
|
||||
};
|
||||
res.push(self.clone());
|
||||
|
||||
// Try TLS
|
||||
self.socket = Socket::Ssl;
|
||||
self.port = match self.protocol {
|
||||
Protocol::Imap => 993,
|
||||
Protocol::Smtp => 465,
|
||||
};
|
||||
res.push(self);
|
||||
vec![
|
||||
// Try STARTTLS
|
||||
Self {
|
||||
socket: Socket::Starttls,
|
||||
port: match self.protocol {
|
||||
Protocol::Imap => 143,
|
||||
Protocol::Smtp => 587,
|
||||
},
|
||||
..self.clone()
|
||||
},
|
||||
// Try TLS
|
||||
Self {
|
||||
socket: Socket::Ssl,
|
||||
port: match self.protocol {
|
||||
Protocol::Imap => 993,
|
||||
Protocol::Smtp => 465,
|
||||
},
|
||||
..self
|
||||
},
|
||||
]
|
||||
} else if self.socket == Socket::Automatic {
|
||||
// Try TLS over user-provided port.
|
||||
self.socket = Socket::Ssl;
|
||||
res.push(self.clone());
|
||||
|
||||
// Try STARTTLS over user-provided port.
|
||||
self.socket = Socket::Starttls;
|
||||
res.push(self);
|
||||
vec![
|
||||
// Try TLS over user-provided port.
|
||||
Self {
|
||||
socket: Socket::Ssl,
|
||||
..self.clone()
|
||||
},
|
||||
// Try STARTTLS over user-provided port.
|
||||
Self {
|
||||
socket: Socket::Starttls,
|
||||
..self
|
||||
},
|
||||
]
|
||||
} else {
|
||||
res.push(self);
|
||||
vec![self]
|
||||
}
|
||||
res
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -913,7 +913,7 @@ async fn add_parts(
|
||||
|
||||
let subject = mime_parser.get_subject().unwrap_or_default();
|
||||
|
||||
let mut parts = std::mem::replace(&mut mime_parser.parts, Vec::new());
|
||||
let mut parts = std::mem::take(&mut mime_parser.parts);
|
||||
let is_system_message = mime_parser.is_system_message;
|
||||
|
||||
// if indicated by the parser,
|
||||
|
||||
@@ -104,13 +104,13 @@ pub fn unformat_flowed(text: &str, delsp: bool) -> String {
|
||||
|
||||
for line in text.split('\n') {
|
||||
// Revert space-stuffing
|
||||
let line = line.strip_prefix(" ").unwrap_or(line);
|
||||
let line = line.strip_prefix(' ').unwrap_or(line);
|
||||
|
||||
if !skip_newline {
|
||||
result.push('\n');
|
||||
}
|
||||
|
||||
if let Some(line) = line.strip_suffix(" ") {
|
||||
if let Some(line) = line.strip_suffix(' ') {
|
||||
// Flowed line
|
||||
result += line;
|
||||
if !delsp {
|
||||
|
||||
17
src/job.rs
17
src/job.rs
@@ -252,7 +252,7 @@ impl Job {
|
||||
smtp.connectivity.set_working(context).await;
|
||||
|
||||
let status = match smtp.send(context, recipients, message, job_id).await {
|
||||
Err(crate::smtp::send::Error::SendError(err)) => {
|
||||
Err(crate::smtp::send::Error::SmtpSend(err)) => {
|
||||
// Remote error, retry later.
|
||||
warn!(context, "SMTP failed to send: {:?}", &err);
|
||||
smtp.connectivity.set_err(context, &err).await;
|
||||
@@ -329,7 +329,7 @@ impl Job {
|
||||
|
||||
res
|
||||
}
|
||||
Err(crate::smtp::send::Error::EnvelopeError(err)) => {
|
||||
Err(crate::smtp::send::Error::Envelope(err)) => {
|
||||
// Local error, job is invalid, do not retry.
|
||||
smtp.disconnect().await;
|
||||
warn!(context, "SMTP job is invalid: {}", err);
|
||||
@@ -1022,16 +1022,9 @@ pub(crate) enum Connection<'a> {
|
||||
}
|
||||
|
||||
pub(crate) async fn load_imap_deletion_job(context: &Context) -> Result<Option<Job>> {
|
||||
let res = if let Some(msg_id) = load_imap_deletion_msgid(context).await? {
|
||||
Some(Job::new(
|
||||
Action::DeleteMsgOnImap,
|
||||
msg_id.to_u32(),
|
||||
Params::new(),
|
||||
0,
|
||||
))
|
||||
} else {
|
||||
None
|
||||
};
|
||||
let res = load_imap_deletion_msgid(context)
|
||||
.await?
|
||||
.map(|msg_id| Job::new(Action::DeleteMsgOnImap, msg_id.to_u32(), Params::new(), 0));
|
||||
Ok(res)
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ impl PlainText {
|
||||
// flowed text as of RFC 3676 -
|
||||
// a leading space shall be removed
|
||||
// and is only there to allow > at the beginning of a line that is no quote.
|
||||
line = line.strip_prefix(" ").unwrap_or(&line).to_string();
|
||||
line = line.strip_prefix(' ').unwrap_or(&line).to_string();
|
||||
if is_quote {
|
||||
line = "<em>".to_owned() + &line + "</em>";
|
||||
}
|
||||
|
||||
@@ -153,8 +153,8 @@ fn remove_bottom_quote<'a>(lines: &'a [&str]) -> (&'a [&'a str], Option<String>)
|
||||
let quoted_text = lines[l_last..first_quoted_line]
|
||||
.iter()
|
||||
.map(|s| {
|
||||
s.strip_prefix(">")
|
||||
.map_or(*s, |u| u.strip_prefix(" ").unwrap_or(u))
|
||||
s.strip_prefix('>')
|
||||
.map_or(*s, |u| u.strip_prefix(' ').unwrap_or(u))
|
||||
})
|
||||
.join("\n");
|
||||
if l_last > 1 && is_empty_line(lines[l_last - 1]) {
|
||||
@@ -199,8 +199,8 @@ fn remove_top_quote<'a>(lines: &'a [&str]) -> (&'a [&'a str], Option<String>) {
|
||||
lines[first_quoted_line..last_quoted_line + 1]
|
||||
.iter()
|
||||
.map(|s| {
|
||||
s.strip_prefix(">")
|
||||
.map_or(*s, |u| u.strip_prefix(" ").unwrap_or(u))
|
||||
s.strip_prefix('>')
|
||||
.map_or(*s, |u| u.strip_prefix(' ').unwrap_or(u))
|
||||
})
|
||||
.join("\n"),
|
||||
),
|
||||
|
||||
@@ -32,7 +32,7 @@ pub enum Error {
|
||||
#[error("SMTP failed to setup connection: {0}")]
|
||||
ConnectionSetupFailure(#[source] smtp::error::Error),
|
||||
#[error("SMTP oauth2 error {address}")]
|
||||
Oauth2Error { address: String },
|
||||
Oauth2 { address: String },
|
||||
#[error("TLS error {0}")]
|
||||
Tls(#[from] async_native_tls::Error),
|
||||
#[error("{0}")]
|
||||
@@ -159,7 +159,7 @@ impl Smtp {
|
||||
let send_pw = &lp.password;
|
||||
let access_token = dc_get_oauth2_access_token(context, addr, send_pw, false).await?;
|
||||
if access_token.is_none() {
|
||||
return Err(Error::Oauth2Error {
|
||||
return Err(Error::Oauth2 {
|
||||
address: addr.to_string(),
|
||||
});
|
||||
}
|
||||
|
||||
@@ -14,9 +14,9 @@ pub type Result<T> = std::result::Result<T, Error>;
|
||||
#[derive(Debug, thiserror::Error)]
|
||||
pub enum Error {
|
||||
#[error("Envelope error: {}", _0)]
|
||||
EnvelopeError(#[from] async_smtp::error::Error),
|
||||
Envelope(#[from] async_smtp::error::Error),
|
||||
#[error("Send error: {}", _0)]
|
||||
SendError(#[from] async_smtp::smtp::error::Error),
|
||||
SmtpSend(#[from] async_smtp::smtp::error::Error),
|
||||
#[error("SMTP has no transport")]
|
||||
NoTransport,
|
||||
#[error("{}", _0)]
|
||||
@@ -46,8 +46,7 @@ impl Smtp {
|
||||
let recipients = recipients_chunk.to_vec();
|
||||
let recipients_display = recipients.iter().map(|x| x.to_string()).join(",");
|
||||
|
||||
let envelope =
|
||||
Envelope::new(self.from.clone(), recipients).map_err(Error::EnvelopeError)?;
|
||||
let envelope = Envelope::new(self.from.clone(), recipients).map_err(Error::Envelope)?;
|
||||
let mail = SendableEmail::new(
|
||||
envelope,
|
||||
format!("{}", job_id), // only used for internal logging
|
||||
@@ -60,7 +59,7 @@ impl Smtp {
|
||||
transport
|
||||
.send_with_timeout(mail, Some(&Duration::from_secs(timeout)))
|
||||
.await
|
||||
.map_err(Error::SendError)?;
|
||||
.map_err(Error::SmtpSend)?;
|
||||
|
||||
context.emit_event(EventType::SmtpMessageSent(format!(
|
||||
"Message len={} was smtp-sent to {}",
|
||||
|
||||
Reference in New Issue
Block a user