Fix nightly clippy errors

This commit is contained in:
link2xt
2021-08-01 00:35:08 +03:00
parent 44bd9f93b4
commit ffb17c4e61
11 changed files with 87 additions and 87 deletions

View File

@@ -2044,15 +2044,7 @@ pub async fn get_chat_media(
}, },
], ],
|row| row.get::<_, MsgId>(0), |row| row.get::<_, MsgId>(0),
|ids| { |ids| Ok(ids.flatten().collect()),
let mut ret = Vec::new();
for id in ids {
if let Ok(msg_id) = id {
ret.push(msg_id)
}
}
Ok(ret)
},
) )
.await?; .await?;
Ok(list) Ok(list)

View File

@@ -533,14 +533,14 @@ async fn try_imap_one_param(
match imap.connect(context).await { match imap.connect(context).await {
Err(err) => { Err(err) => {
info!(context, "failure: {}", err); info!(context, "failure: {}", err);
return Err(ConfigurationError { Err(ConfigurationError {
config: inf, config: inf,
msg: err.to_string(), msg: err.to_string(),
}); })
} }
Ok(()) => { Ok(()) => {
info!(context, "success: {}", inf); info!(context, "success: {}", inf);
return Ok(imap); Ok(imap)
} }
} }
} }
@@ -618,10 +618,10 @@ pub enum Error {
}, },
#[error("Failed to get URL: {0}")] #[error("Failed to get URL: {0}")]
ReadUrlError(#[from] self::read_url::Error), ReadUrl(#[from] self::read_url::Error),
#[error("Number of redirection is exceeded")] #[error("Number of redirection is exceeded")]
RedirectionError, Redirection,
} }
#[cfg(test)] #[cfg(test)]

View File

@@ -203,7 +203,7 @@ pub(crate) async fn outlk_autodiscover(
} }
} }
} }
Err(Error::RedirectionError) Err(Error::Redirection)
} }
#[cfg(test)] #[cfg(test)]

View File

@@ -25,16 +25,20 @@ pub(crate) struct ServerParams {
} }
impl 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(); let mut res = Vec::new();
if self.username.is_empty() { if self.username.is_empty() {
self.username = addr.to_string(); res.push(Self {
res.push(self.clone()); username: addr.to_string(),
..self.clone()
});
if let Some(at) = addr.find('@') { 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 { } else {
res.push(self) res.push(self)
@@ -42,24 +46,28 @@ impl ServerParams {
res res
} }
fn expand_hostnames(mut self, param_domain: &str) -> Vec<ServerParams> { fn expand_hostnames(self, param_domain: &str) -> Vec<ServerParams> {
let mut res = Vec::new();
if self.hostname.is_empty() { if self.hostname.is_empty() {
self.hostname = param_domain.to_string(); vec![
res.push(self.clone()); Self {
hostname: param_domain.to_string(),
self.hostname = match self.protocol { ..self.clone()
Protocol::Imap => "imap.".to_string() + param_domain, },
Protocol::Smtp => "smtp.".to_string() + param_domain, Self {
}; hostname: match self.protocol {
res.push(self.clone()); Protocol::Imap => "imap.".to_string() + param_domain,
Protocol::Smtp => "smtp.".to_string() + param_domain,
self.hostname = "mail.".to_string() + param_domain; },
res.push(self); ..self.clone()
},
Self {
hostname: "mail.".to_string() + param_domain,
..self
},
]
} else { } else {
res.push(self); vec![self]
} }
res
} }
fn expand_ports(mut self) -> Vec<ServerParams> { fn expand_ports(mut self) -> Vec<ServerParams> {
@@ -78,39 +86,47 @@ impl ServerParams {
} }
} }
let mut res = Vec::new();
if self.port == 0 { if self.port == 0 {
// Neither port nor security is set. // Neither port nor security is set.
// //
// Try common secure combinations. // Try common secure combinations.
// Try STARTTLS vec![
self.socket = Socket::Starttls; // Try STARTTLS
self.port = match self.protocol { Self {
Protocol::Imap => 143, socket: Socket::Starttls,
Protocol::Smtp => 587, port: match self.protocol {
}; Protocol::Imap => 143,
res.push(self.clone()); Protocol::Smtp => 587,
},
// Try TLS ..self.clone()
self.socket = Socket::Ssl; },
self.port = match self.protocol { // Try TLS
Protocol::Imap => 993, Self {
Protocol::Smtp => 465, socket: Socket::Ssl,
}; port: match self.protocol {
res.push(self); Protocol::Imap => 993,
Protocol::Smtp => 465,
},
..self
},
]
} else if self.socket == Socket::Automatic { } else if self.socket == Socket::Automatic {
// Try TLS over user-provided port. vec![
self.socket = Socket::Ssl; // Try TLS over user-provided port.
res.push(self.clone()); Self {
socket: Socket::Ssl,
// Try STARTTLS over user-provided port. ..self.clone()
self.socket = Socket::Starttls; },
res.push(self); // Try STARTTLS over user-provided port.
Self {
socket: Socket::Starttls,
..self
},
]
} else { } else {
res.push(self); vec![self]
} }
res
} }
} }

View File

@@ -913,7 +913,7 @@ async fn add_parts(
let subject = mime_parser.get_subject().unwrap_or_default(); 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; let is_system_message = mime_parser.is_system_message;
// if indicated by the parser, // if indicated by the parser,

View File

@@ -104,13 +104,13 @@ pub fn unformat_flowed(text: &str, delsp: bool) -> String {
for line in text.split('\n') { for line in text.split('\n') {
// Revert space-stuffing // Revert space-stuffing
let line = line.strip_prefix(" ").unwrap_or(line); let line = line.strip_prefix(' ').unwrap_or(line);
if !skip_newline { if !skip_newline {
result.push('\n'); result.push('\n');
} }
if let Some(line) = line.strip_suffix(" ") { if let Some(line) = line.strip_suffix(' ') {
// Flowed line // Flowed line
result += line; result += line;
if !delsp { if !delsp {

View File

@@ -252,7 +252,7 @@ impl Job {
smtp.connectivity.set_working(context).await; smtp.connectivity.set_working(context).await;
let status = match smtp.send(context, recipients, message, job_id).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. // Remote error, retry later.
warn!(context, "SMTP failed to send: {:?}", &err); warn!(context, "SMTP failed to send: {:?}", &err);
smtp.connectivity.set_err(context, &err).await; smtp.connectivity.set_err(context, &err).await;
@@ -329,7 +329,7 @@ impl Job {
res res
} }
Err(crate::smtp::send::Error::EnvelopeError(err)) => { Err(crate::smtp::send::Error::Envelope(err)) => {
// Local error, job is invalid, do not retry. // Local error, job is invalid, do not retry.
smtp.disconnect().await; smtp.disconnect().await;
warn!(context, "SMTP job is invalid: {}", err); 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>> { 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? { let res = load_imap_deletion_msgid(context)
Some(Job::new( .await?
Action::DeleteMsgOnImap, .map(|msg_id| Job::new(Action::DeleteMsgOnImap, msg_id.to_u32(), Params::new(), 0));
msg_id.to_u32(),
Params::new(),
0,
))
} else {
None
};
Ok(res) Ok(res)
} }

View File

@@ -64,7 +64,7 @@ impl PlainText {
// flowed text as of RFC 3676 - // flowed text as of RFC 3676 -
// a leading space shall be removed // a leading space shall be removed
// and is only there to allow > at the beginning of a line that is no quote. // 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 { if is_quote {
line = "<em>".to_owned() + &line + "</em>"; line = "<em>".to_owned() + &line + "</em>";
} }

View File

@@ -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] let quoted_text = lines[l_last..first_quoted_line]
.iter() .iter()
.map(|s| { .map(|s| {
s.strip_prefix(">") s.strip_prefix('>')
.map_or(*s, |u| u.strip_prefix(" ").unwrap_or(u)) .map_or(*s, |u| u.strip_prefix(' ').unwrap_or(u))
}) })
.join("\n"); .join("\n");
if l_last > 1 && is_empty_line(lines[l_last - 1]) { 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] lines[first_quoted_line..last_quoted_line + 1]
.iter() .iter()
.map(|s| { .map(|s| {
s.strip_prefix(">") s.strip_prefix('>')
.map_or(*s, |u| u.strip_prefix(" ").unwrap_or(u)) .map_or(*s, |u| u.strip_prefix(' ').unwrap_or(u))
}) })
.join("\n"), .join("\n"),
), ),

View File

@@ -32,7 +32,7 @@ pub enum Error {
#[error("SMTP failed to setup connection: {0}")] #[error("SMTP failed to setup connection: {0}")]
ConnectionSetupFailure(#[source] smtp::error::Error), ConnectionSetupFailure(#[source] smtp::error::Error),
#[error("SMTP oauth2 error {address}")] #[error("SMTP oauth2 error {address}")]
Oauth2Error { address: String }, Oauth2 { address: String },
#[error("TLS error {0}")] #[error("TLS error {0}")]
Tls(#[from] async_native_tls::Error), Tls(#[from] async_native_tls::Error),
#[error("{0}")] #[error("{0}")]
@@ -159,7 +159,7 @@ impl Smtp {
let send_pw = &lp.password; let send_pw = &lp.password;
let access_token = dc_get_oauth2_access_token(context, addr, send_pw, false).await?; let access_token = dc_get_oauth2_access_token(context, addr, send_pw, false).await?;
if access_token.is_none() { if access_token.is_none() {
return Err(Error::Oauth2Error { return Err(Error::Oauth2 {
address: addr.to_string(), address: addr.to_string(),
}); });
} }

View File

@@ -14,9 +14,9 @@ pub type Result<T> = std::result::Result<T, Error>;
#[derive(Debug, thiserror::Error)] #[derive(Debug, thiserror::Error)]
pub enum Error { pub enum Error {
#[error("Envelope error: {}", _0)] #[error("Envelope error: {}", _0)]
EnvelopeError(#[from] async_smtp::error::Error), Envelope(#[from] async_smtp::error::Error),
#[error("Send error: {}", _0)] #[error("Send error: {}", _0)]
SendError(#[from] async_smtp::smtp::error::Error), SmtpSend(#[from] async_smtp::smtp::error::Error),
#[error("SMTP has no transport")] #[error("SMTP has no transport")]
NoTransport, NoTransport,
#[error("{}", _0)] #[error("{}", _0)]
@@ -46,8 +46,7 @@ impl Smtp {
let recipients = recipients_chunk.to_vec(); let recipients = recipients_chunk.to_vec();
let recipients_display = recipients.iter().map(|x| x.to_string()).join(","); let recipients_display = recipients.iter().map(|x| x.to_string()).join(",");
let envelope = let envelope = Envelope::new(self.from.clone(), recipients).map_err(Error::Envelope)?;
Envelope::new(self.from.clone(), recipients).map_err(Error::EnvelopeError)?;
let mail = SendableEmail::new( let mail = SendableEmail::new(
envelope, envelope,
format!("{}", job_id), // only used for internal logging format!("{}", job_id), // only used for internal logging
@@ -60,7 +59,7 @@ impl Smtp {
transport transport
.send_with_timeout(mail, Some(&Duration::from_secs(timeout))) .send_with_timeout(mail, Some(&Duration::from_secs(timeout)))
.await .await
.map_err(Error::SendError)?; .map_err(Error::SmtpSend)?;
context.emit_event(EventType::SmtpMessageSent(format!( context.emit_event(EventType::SmtpMessageSent(format!(
"Message len={} was smtp-sent to {}", "Message len={} was smtp-sent to {}",