mirror of
https://github.com/chatmail/core.git
synced 2026-04-17 21:46:35 +03:00
Enable clippy::unused_async lint
This commit is contained in:
@@ -1391,11 +1391,7 @@ impl Chat {
|
|||||||
} else {
|
} else {
|
||||||
msg.param.get(Param::SendHtml).map(|s| s.to_string())
|
msg.param.get(Param::SendHtml).map(|s| s.to_string())
|
||||||
};
|
};
|
||||||
if let Some(html) = html {
|
html.map(|html| new_html_mimepart(html).build().as_string())
|
||||||
Some(new_html_mimepart(html).await.build().as_string())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
None
|
None
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -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
|
/// 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.
|
/// fingerprints for which there is a valid signature.
|
||||||
async fn validate_detached_signature(
|
fn validate_detached_signature(
|
||||||
mail: &ParsedMail<'_>,
|
mail: &ParsedMail<'_>,
|
||||||
public_keyring_for_validate: &Keyring<SignedPublicKey>,
|
public_keyring_for_validate: &Keyring<SignedPublicKey>,
|
||||||
) -> Result<Option<(Vec<u8>, HashSet<Fingerprint>)>> {
|
) -> Result<Option<(Vec<u8>, HashSet<Fingerprint>)>> {
|
||||||
@@ -328,7 +328,7 @@ async fn validate_detached_signature(
|
|||||||
let content = first_part.raw_bytes;
|
let content = first_part.raw_bytes;
|
||||||
let signature = second_part.get_body_raw()?;
|
let signature = second_part.get_body_raw()?;
|
||||||
let ret_valid_signatures =
|
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)))
|
Ok(Some((content.to_vec(), ret_valid_signatures)))
|
||||||
} else {
|
} else {
|
||||||
@@ -352,7 +352,7 @@ async fn decrypt_part(
|
|||||||
// If decrypted part is a multipart/signed, then there is a detached signature.
|
// If decrypted part is a multipart/signed, then there is a detached signature.
|
||||||
let decrypted_part = mailparse::parse_mail(&plain)?;
|
let decrypted_part = mailparse::parse_mail(&plain)?;
|
||||||
if let Some((content, valid_detached_signatures)) =
|
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)));
|
return Ok(Some((content, valid_detached_signatures)));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
12
src/html.rs
12
src/html.rs
@@ -64,7 +64,7 @@ enum MimeMultipartType {
|
|||||||
|
|
||||||
/// Function takes a content type from a ParsedMail structure
|
/// Function takes a content type from a ParsedMail structure
|
||||||
/// and checks and returns the rough mime-type.
|
/// 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();
|
let mimetype = ctype.mimetype.to_lowercase();
|
||||||
if mimetype.starts_with("multipart") && ctype.params.get("boundary").is_some() {
|
if mimetype.starts_with("multipart") && ctype.params.get("boundary").is_some() {
|
||||||
MimeMultipartType::Multiple
|
MimeMultipartType::Multiple
|
||||||
@@ -122,7 +122,7 @@ impl HtmlMsgParser {
|
|||||||
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a + Send>> {
|
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a + Send>> {
|
||||||
// Boxed future to deal with recursion
|
// Boxed future to deal with recursion
|
||||||
async move {
|
async move {
|
||||||
match get_mime_multipart_type(&mail.ctype).await {
|
match get_mime_multipart_type(&mail.ctype) {
|
||||||
MimeMultipartType::Multiple => {
|
MimeMultipartType::Multiple => {
|
||||||
for cur_data in mail.subparts.iter() {
|
for cur_data in mail.subparts.iter() {
|
||||||
self.collect_texts_recursive(context, cur_data).await?
|
self.collect_texts_recursive(context, cur_data).await?
|
||||||
@@ -178,7 +178,7 @@ impl HtmlMsgParser {
|
|||||||
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a + Send>> {
|
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a + Send>> {
|
||||||
// Boxed future to deal with recursion
|
// Boxed future to deal with recursion
|
||||||
async move {
|
async move {
|
||||||
match get_mime_multipart_type(&mail.ctype).await {
|
match get_mime_multipart_type(&mail.ctype) {
|
||||||
MimeMultipartType::Multiple => {
|
MimeMultipartType::Multiple => {
|
||||||
for cur_data in mail.subparts.iter() {
|
for cur_data in mail.subparts.iter() {
|
||||||
self.cid_to_data_recursive(context, cur_data).await?;
|
self.cid_to_data_recursive(context, cur_data).await?;
|
||||||
@@ -198,7 +198,7 @@ impl HtmlMsgParser {
|
|||||||
if mimetype.type_() == mime::IMAGE {
|
if mimetype.type_() == mime::IMAGE {
|
||||||
if let Some(cid) = mail.headers.get_header_value(HeaderDef::ContentId) {
|
if let Some(cid) = mail.headers.get_header_value(HeaderDef::ContentId) {
|
||||||
if let Ok(cid) = parse_message_id(&cid) {
|
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!(
|
let re_string = format!(
|
||||||
"(<img[^>]*src[^>]*=[^>]*)(cid:{})([^>]*>)",
|
"(<img[^>]*src[^>]*=[^>]*)(cid:{})([^>]*>)",
|
||||||
regex::escape(&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).
|
/// 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<String> {
|
fn mimepart_to_data_url(mail: &mailparse::ParsedMail<'_>) -> Result<String> {
|
||||||
let data = mail.get_body_raw()?;
|
let data = mail.get_body_raw()?;
|
||||||
let data = base64::encode(&data);
|
let data = base64::encode(&data);
|
||||||
Ok(format!("data:{};base64,{}", mail.ctype.mimetype, 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
|
/// Used on forwarding messages to avoid leaking the original mime structure
|
||||||
/// and also to avoid sending too much, maybe large data.
|
/// 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()
|
PartBuilder::new()
|
||||||
.content_type(&"text/html; charset=utf-8".parse::<mime::Mime>().unwrap())
|
.content_type(&"text/html; charset=utf-8".parse::<mime::Mime>().unwrap())
|
||||||
.body(html)
|
.body(html)
|
||||||
|
|||||||
@@ -8,7 +8,8 @@
|
|||||||
clippy::indexing_slicing,
|
clippy::indexing_slicing,
|
||||||
clippy::wildcard_imports,
|
clippy::wildcard_imports,
|
||||||
clippy::needless_borrow,
|
clippy::needless_borrow,
|
||||||
clippy::cast_lossless
|
clippy::cast_lossless,
|
||||||
|
clippy::unused_async
|
||||||
)]
|
)]
|
||||||
#![allow(
|
#![allow(
|
||||||
clippy::match_bool,
|
clippy::match_bool,
|
||||||
|
|||||||
@@ -1128,7 +1128,7 @@ impl<'a> MimeFactory<'a> {
|
|||||||
main_part = PartBuilder::new()
|
main_part = PartBuilder::new()
|
||||||
.message_type(MimeMultipartType::Alternative)
|
.message_type(MimeMultipartType::Alternative)
|
||||||
.child(main_part.build())
|
.child(main_part.build())
|
||||||
.child(new_html_mimepart(html).await.build());
|
.child(new_html_mimepart(html).build());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -311,7 +311,7 @@ pub async fn pk_decrypt(
|
|||||||
}
|
}
|
||||||
|
|
||||||
/// Validates detached signature.
|
/// Validates detached signature.
|
||||||
pub async fn pk_validate(
|
pub fn pk_validate(
|
||||||
content: &[u8],
|
content: &[u8],
|
||||||
signature: &[u8],
|
signature: &[u8],
|
||||||
public_keys_for_validation: &Keyring<SignedPublicKey>,
|
public_keys_for_validation: &Keyring<SignedPublicKey>,
|
||||||
|
|||||||
@@ -547,12 +547,12 @@ impl Context {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn parse_webxdc_manifest(bytes: &[u8]) -> Result<WebxdcManifest> {
|
fn parse_webxdc_manifest(bytes: &[u8]) -> Result<WebxdcManifest> {
|
||||||
let manifest: WebxdcManifest = toml::from_slice(bytes)?;
|
let manifest: WebxdcManifest = toml::from_slice(bytes)?;
|
||||||
Ok(manifest)
|
Ok(manifest)
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn get_blob(archive: &mut ZipArchive<File>, name: &str) -> Result<Vec<u8>> {
|
fn get_blob(archive: &mut ZipArchive<File>, name: &str) -> Result<Vec<u8>> {
|
||||||
let mut file = archive.by_name(name)?;
|
let mut file = archive.by_name(name)?;
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
file.read_to_end(&mut buf)?;
|
file.read_to_end(&mut buf)?;
|
||||||
@@ -591,8 +591,8 @@ impl Message {
|
|||||||
let mut archive = self.get_webxdc_archive(context).await?;
|
let mut archive = self.get_webxdc_archive(context).await?;
|
||||||
|
|
||||||
if name == "index.html" {
|
if name == "index.html" {
|
||||||
if let Ok(bytes) = get_blob(&mut archive, "manifest.toml").await {
|
if let Ok(bytes) = get_blob(&mut archive, "manifest.toml") {
|
||||||
if let Ok(manifest) = parse_webxdc_manifest(&bytes).await {
|
if let Ok(manifest) = parse_webxdc_manifest(&bytes) {
|
||||||
if let Some(min_api) = manifest.min_api {
|
if let Some(min_api) = manifest.min_api {
|
||||||
if min_api > WEBXDC_API_VERSION {
|
if min_api > WEBXDC_API_VERSION {
|
||||||
return Ok(Vec::from(
|
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.
|
/// Return info from manifest.toml or from fallbacks.
|
||||||
@@ -612,8 +612,8 @@ impl Message {
|
|||||||
ensure!(self.viewtype == Viewtype::Webxdc, "No webxdc instance.");
|
ensure!(self.viewtype == Viewtype::Webxdc, "No webxdc instance.");
|
||||||
let mut archive = self.get_webxdc_archive(context).await?;
|
let mut archive = self.get_webxdc_archive(context).await?;
|
||||||
|
|
||||||
let mut manifest = if let Ok(bytes) = get_blob(&mut archive, "manifest.toml").await {
|
let mut manifest = if let Ok(bytes) = get_blob(&mut archive, "manifest.toml") {
|
||||||
if let Ok(manifest) = parse_webxdc_manifest(&bytes).await {
|
if let Ok(manifest) = parse_webxdc_manifest(&bytes) {
|
||||||
manifest
|
manifest
|
||||||
} else {
|
} else {
|
||||||
WebxdcManifest {
|
WebxdcManifest {
|
||||||
@@ -1486,21 +1486,20 @@ mod tests {
|
|||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_parse_webxdc_manifest() -> Result<()> {
|
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());
|
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);
|
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()));
|
assert_eq!(manifest.name, Some("name, no icon".to_string()));
|
||||||
|
|
||||||
let manifest = parse_webxdc_manifest(
|
let manifest = parse_webxdc_manifest(
|
||||||
r#"name = "foo"
|
r#"name = "foo"
|
||||||
icon = "bar""#
|
icon = "bar""#
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)
|
)?;
|
||||||
.await?;
|
|
||||||
assert_eq!(manifest.name, Some("foo".to_string()));
|
assert_eq!(manifest.name, Some("foo".to_string()));
|
||||||
|
|
||||||
let manifest = parse_webxdc_manifest(
|
let manifest = parse_webxdc_manifest(
|
||||||
@@ -1511,21 +1510,20 @@ add_item = "that should be just ignored"
|
|||||||
[section]
|
[section]
|
||||||
sth_for_the = "future""#
|
sth_for_the = "future""#
|
||||||
.as_bytes(),
|
.as_bytes(),
|
||||||
)
|
)?;
|
||||||
.await?;
|
|
||||||
assert_eq!(manifest.name, Some("foz".to_string()));
|
assert_eq!(manifest.name, Some("foz".to_string()));
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_parse_webxdc_manifest_min_api() -> Result<()> {
|
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));
|
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());
|
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());
|
assert!(result.is_err());
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
@@ -1533,11 +1531,10 @@ sth_for_the = "future""#
|
|||||||
|
|
||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_parse_webxdc_manifest_source_code_url() -> Result<()> {
|
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());
|
assert!(result.is_err());
|
||||||
|
|
||||||
let manifest =
|
let manifest = parse_webxdc_manifest(r#"source_code_url = "https://foo.bar""#.as_bytes())?;
|
||||||
parse_webxdc_manifest(r#"source_code_url = "https://foo.bar""#.as_bytes()).await?;
|
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
manifest.source_code_url,
|
manifest.source_code_url,
|
||||||
Some("https://foo.bar".to_string())
|
Some("https://foo.bar".to_string())
|
||||||
|
|||||||
Reference in New Issue
Block a user