diff --git a/src/chat.rs b/src/chat.rs index 2debcf535..945672a46 100644 --- a/src/chat.rs +++ b/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) diff --git a/src/configure.rs b/src/configure.rs index 28e596a41..70196d816 100644 --- a/src/configure.rs +++ b/src/configure.rs @@ -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)] diff --git a/src/configure/auto_outlook.rs b/src/configure/auto_outlook.rs index 493ec39a7..c3acbfb28 100644 --- a/src/configure/auto_outlook.rs +++ b/src/configure/auto_outlook.rs @@ -203,7 +203,7 @@ pub(crate) async fn outlk_autodiscover( } } } - Err(Error::RedirectionError) + Err(Error::Redirection) } #[cfg(test)] diff --git a/src/configure/server_params.rs b/src/configure/server_params.rs index c5dfd265d..fdc723d56 100644 --- a/src/configure/server_params.rs +++ b/src/configure/server_params.rs @@ -25,16 +25,20 @@ pub(crate) struct ServerParams { } impl ServerParams { - fn expand_usernames(mut self, addr: &str) -> Vec { + fn expand_usernames(self, addr: &str) -> Vec { 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 { - let mut res = Vec::new(); + fn expand_hostnames(self, param_domain: &str) -> Vec { 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 { @@ -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 } } diff --git a/src/dc_receive_imf.rs b/src/dc_receive_imf.rs index 269167b4d..f0c0eeea7 100644 --- a/src/dc_receive_imf.rs +++ b/src/dc_receive_imf.rs @@ -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, diff --git a/src/format_flowed.rs b/src/format_flowed.rs index abbc00fff..ff21b9bd0 100644 --- a/src/format_flowed.rs +++ b/src/format_flowed.rs @@ -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 { diff --git a/src/job.rs b/src/job.rs index 387012ddf..71d29e6fc 100644 --- a/src/job.rs +++ b/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> { - 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) } diff --git a/src/plaintext.rs b/src/plaintext.rs index e78d3f85a..f00f4ed19 100644 --- a/src/plaintext.rs +++ b/src/plaintext.rs @@ -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 = "".to_owned() + &line + ""; } diff --git a/src/simplify.rs b/src/simplify.rs index e0b6334b1..b4096a80e 100644 --- a/src/simplify.rs +++ b/src/simplify.rs @@ -153,8 +153,8 @@ fn remove_bottom_quote<'a>(lines: &'a [&str]) -> (&'a [&'a str], Option) 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) { 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"), ), diff --git a/src/smtp.rs b/src/smtp.rs index 635996028..7a90ad975 100644 --- a/src/smtp.rs +++ b/src/smtp.rs @@ -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(), }); } diff --git a/src/smtp/send.rs b/src/smtp/send.rs index 3b9acd973..fe1e813a7 100644 --- a/src/smtp/send.rs +++ b/src/smtp/send.rs @@ -14,9 +14,9 @@ pub type Result = std::result::Result; #[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 {}",