From 0a51db3005e2fcb4b85c8bd9d98077cc0784b087 Mon Sep 17 00:00:00 2001 From: link2xt Date: Thu, 2 Jun 2022 10:12:04 +0000 Subject: [PATCH] Enable clippy::unused_async lint --- src/chat.rs | 6 +----- src/e2ee.rs | 6 +++--- src/html.rs | 12 ++++++------ src/lib.rs | 3 ++- src/mimefactory.rs | 2 +- src/pgp.rs | 2 +- src/webxdc.rs | 37 +++++++++++++++++-------------------- 7 files changed, 31 insertions(+), 37 deletions(-) diff --git a/src/chat.rs b/src/chat.rs index 9ca6e0424..dc47e5849 100644 --- a/src/chat.rs +++ b/src/chat.rs @@ -1391,11 +1391,7 @@ impl Chat { } else { msg.param.get(Param::SendHtml).map(|s| s.to_string()) }; - if let Some(html) = html { - Some(new_html_mimepart(html).await.build().as_string()) - } else { - None - } + html.map(|html| new_html_mimepart(html).build().as_string()) } else { None }; diff --git a/src/e2ee.rs b/src/e2ee.rs index 8d19b44b0..c84753a43 100644 --- a/src/e2ee.rs +++ b/src/e2ee.rs @@ -315,7 +315,7 @@ async fn decrypt_if_autocrypt_message( /// /// Returns `None` if the part is not a Multipart/Signed part, otherwise retruns the set of key /// fingerprints for which there is a valid signature. -async fn validate_detached_signature( +fn validate_detached_signature( mail: &ParsedMail<'_>, public_keyring_for_validate: &Keyring, ) -> Result, HashSet)>> { @@ -328,7 +328,7 @@ async fn validate_detached_signature( let content = first_part.raw_bytes; let signature = second_part.get_body_raw()?; let ret_valid_signatures = - pgp::pk_validate(content, &signature, public_keyring_for_validate).await?; + pgp::pk_validate(content, &signature, public_keyring_for_validate)?; Ok(Some((content.to_vec(), ret_valid_signatures))) } else { @@ -352,7 +352,7 @@ async fn decrypt_part( // If decrypted part is a multipart/signed, then there is a detached signature. let decrypted_part = mailparse::parse_mail(&plain)?; if let Some((content, valid_detached_signatures)) = - validate_detached_signature(&decrypted_part, &public_keyring_for_validate).await? + validate_detached_signature(&decrypted_part, &public_keyring_for_validate)? { return Ok(Some((content, valid_detached_signatures))); } else { diff --git a/src/html.rs b/src/html.rs index d156780ed..43a63b2df 100644 --- a/src/html.rs +++ b/src/html.rs @@ -64,7 +64,7 @@ enum MimeMultipartType { /// Function takes a content type from a ParsedMail structure /// and checks and returns the rough mime-type. -async fn get_mime_multipart_type(ctype: &ParsedContentType) -> MimeMultipartType { +fn get_mime_multipart_type(ctype: &ParsedContentType) -> MimeMultipartType { let mimetype = ctype.mimetype.to_lowercase(); if mimetype.starts_with("multipart") && ctype.params.get("boundary").is_some() { MimeMultipartType::Multiple @@ -122,7 +122,7 @@ impl HtmlMsgParser { ) -> Pin> + 'a + Send>> { // Boxed future to deal with recursion async move { - match get_mime_multipart_type(&mail.ctype).await { + match get_mime_multipart_type(&mail.ctype) { MimeMultipartType::Multiple => { for cur_data in mail.subparts.iter() { self.collect_texts_recursive(context, cur_data).await? @@ -178,7 +178,7 @@ impl HtmlMsgParser { ) -> Pin> + 'a + Send>> { // Boxed future to deal with recursion async move { - match get_mime_multipart_type(&mail.ctype).await { + match get_mime_multipart_type(&mail.ctype) { MimeMultipartType::Multiple => { for cur_data in mail.subparts.iter() { self.cid_to_data_recursive(context, cur_data).await?; @@ -198,7 +198,7 @@ impl HtmlMsgParser { if mimetype.type_() == mime::IMAGE { if let Some(cid) = mail.headers.get_header_value(HeaderDef::ContentId) { if let Ok(cid) = parse_message_id(&cid) { - if let Ok(replacement) = mimepart_to_data_url(mail).await { + if let Ok(replacement) = mimepart_to_data_url(mail) { let re_string = format!( "(]*src[^>]*=[^>]*)(cid:{})([^>]*>)", regex::escape(&cid) @@ -233,7 +233,7 @@ impl HtmlMsgParser { } /// Convert a mime part to a data: url as defined in [RFC 2397](https://tools.ietf.org/html/rfc2397). -async fn mimepart_to_data_url(mail: &mailparse::ParsedMail<'_>) -> Result { +fn mimepart_to_data_url(mail: &mailparse::ParsedMail<'_>) -> Result { let data = mail.get_body_raw()?; let data = base64::encode(&data); Ok(format!("data:{};base64,{}", mail.ctype.mimetype, data)) @@ -267,7 +267,7 @@ impl MsgId { /// /// Used on forwarding messages to avoid leaking the original mime structure /// and also to avoid sending too much, maybe large data. -pub async fn new_html_mimepart(html: String) -> PartBuilder { +pub fn new_html_mimepart(html: String) -> PartBuilder { PartBuilder::new() .content_type(&"text/html; charset=utf-8".parse::().unwrap()) .body(html) diff --git a/src/lib.rs b/src/lib.rs index 62214f21e..515af0729 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -8,7 +8,8 @@ clippy::indexing_slicing, clippy::wildcard_imports, clippy::needless_borrow, - clippy::cast_lossless + clippy::cast_lossless, + clippy::unused_async )] #![allow( clippy::match_bool, diff --git a/src/mimefactory.rs b/src/mimefactory.rs index ab77900fe..3c892ab0f 100644 --- a/src/mimefactory.rs +++ b/src/mimefactory.rs @@ -1128,7 +1128,7 @@ impl<'a> MimeFactory<'a> { main_part = PartBuilder::new() .message_type(MimeMultipartType::Alternative) .child(main_part.build()) - .child(new_html_mimepart(html).await.build()); + .child(new_html_mimepart(html).build()); } } diff --git a/src/pgp.rs b/src/pgp.rs index fb527dfa4..f470736c2 100644 --- a/src/pgp.rs +++ b/src/pgp.rs @@ -311,7 +311,7 @@ pub async fn pk_decrypt( } /// Validates detached signature. -pub async fn pk_validate( +pub fn pk_validate( content: &[u8], signature: &[u8], public_keys_for_validation: &Keyring, diff --git a/src/webxdc.rs b/src/webxdc.rs index 3789511e1..5693d9671 100644 --- a/src/webxdc.rs +++ b/src/webxdc.rs @@ -547,12 +547,12 @@ impl Context { } } -async fn parse_webxdc_manifest(bytes: &[u8]) -> Result { +fn parse_webxdc_manifest(bytes: &[u8]) -> Result { let manifest: WebxdcManifest = toml::from_slice(bytes)?; Ok(manifest) } -async fn get_blob(archive: &mut ZipArchive, name: &str) -> Result> { +fn get_blob(archive: &mut ZipArchive, name: &str) -> Result> { let mut file = archive.by_name(name)?; let mut buf = Vec::new(); file.read_to_end(&mut buf)?; @@ -591,8 +591,8 @@ impl Message { let mut archive = self.get_webxdc_archive(context).await?; if name == "index.html" { - if let Ok(bytes) = get_blob(&mut archive, "manifest.toml").await { - if let Ok(manifest) = parse_webxdc_manifest(&bytes).await { + if let Ok(bytes) = get_blob(&mut archive, "manifest.toml") { + if let Ok(manifest) = parse_webxdc_manifest(&bytes) { if let Some(min_api) = manifest.min_api { if min_api > WEBXDC_API_VERSION { return Ok(Vec::from( @@ -604,7 +604,7 @@ impl Message { } } - get_blob(&mut archive, name).await + get_blob(&mut archive, name) } /// Return info from manifest.toml or from fallbacks. @@ -612,8 +612,8 @@ impl Message { ensure!(self.viewtype == Viewtype::Webxdc, "No webxdc instance."); let mut archive = self.get_webxdc_archive(context).await?; - let mut manifest = if let Ok(bytes) = get_blob(&mut archive, "manifest.toml").await { - if let Ok(manifest) = parse_webxdc_manifest(&bytes).await { + let mut manifest = if let Ok(bytes) = get_blob(&mut archive, "manifest.toml") { + if let Ok(manifest) = parse_webxdc_manifest(&bytes) { manifest } else { WebxdcManifest { @@ -1486,21 +1486,20 @@ mod tests { #[async_std::test] async fn test_parse_webxdc_manifest() -> Result<()> { - let result = parse_webxdc_manifest(r#"key = syntax error"#.as_bytes()).await; + let result = parse_webxdc_manifest(r#"key = syntax error"#.as_bytes()); assert!(result.is_err()); - let manifest = parse_webxdc_manifest(r#"no_name = "no name, no icon""#.as_bytes()).await?; + let manifest = parse_webxdc_manifest(r#"no_name = "no name, no icon""#.as_bytes())?; assert_eq!(manifest.name, None); - let manifest = parse_webxdc_manifest(r#"name = "name, no icon""#.as_bytes()).await?; + let manifest = parse_webxdc_manifest(r#"name = "name, no icon""#.as_bytes())?; assert_eq!(manifest.name, Some("name, no icon".to_string())); let manifest = parse_webxdc_manifest( r#"name = "foo" icon = "bar""# .as_bytes(), - ) - .await?; + )?; assert_eq!(manifest.name, Some("foo".to_string())); let manifest = parse_webxdc_manifest( @@ -1511,21 +1510,20 @@ add_item = "that should be just ignored" [section] sth_for_the = "future""# .as_bytes(), - ) - .await?; + )?; assert_eq!(manifest.name, Some("foz".to_string())); Ok(()) } #[async_std::test] async fn test_parse_webxdc_manifest_min_api() -> Result<()> { - let manifest = parse_webxdc_manifest(r#"min_api = 3"#.as_bytes()).await?; + let manifest = parse_webxdc_manifest(r#"min_api = 3"#.as_bytes())?; assert_eq!(manifest.min_api, Some(3)); - let result = parse_webxdc_manifest(r#"min_api = "1""#.as_bytes()).await; + let result = parse_webxdc_manifest(r#"min_api = "1""#.as_bytes()); assert!(result.is_err()); - let result = parse_webxdc_manifest(r#"min_api = 1.2"#.as_bytes()).await; + let result = parse_webxdc_manifest(r#"min_api = 1.2"#.as_bytes()); assert!(result.is_err()); Ok(()) @@ -1533,11 +1531,10 @@ sth_for_the = "future""# #[async_std::test] async fn test_parse_webxdc_manifest_source_code_url() -> Result<()> { - let result = parse_webxdc_manifest(r#"source_code_url = 3"#.as_bytes()).await; + let result = parse_webxdc_manifest(r#"source_code_url = 3"#.as_bytes()); assert!(result.is_err()); - let manifest = - parse_webxdc_manifest(r#"source_code_url = "https://foo.bar""#.as_bytes()).await?; + let manifest = parse_webxdc_manifest(r#"source_code_url = "https://foo.bar""#.as_bytes())?; assert_eq!( manifest.source_code_url, Some("https://foo.bar".to_string())