mirror of
https://github.com/chatmail/core.git
synced 2026-05-20 23:36:30 +03:00
refactor: use Rust 1.77.0 support for recursion in async functions
This commit is contained in:
12
.github/workflows/ci.yml
vendored
12
.github/workflows/ci.yml
vendored
@@ -24,7 +24,7 @@ jobs:
|
|||||||
name: Lint Rust
|
name: Lint Rust
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
env:
|
||||||
RUSTUP_TOOLCHAIN: 1.77.0
|
RUSTUP_TOOLCHAIN: 1.77.1
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
with:
|
with:
|
||||||
@@ -83,15 +83,15 @@ jobs:
|
|||||||
matrix:
|
matrix:
|
||||||
include:
|
include:
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
rust: 1.77.0
|
rust: 1.77.1
|
||||||
- os: windows-latest
|
- os: windows-latest
|
||||||
rust: 1.77.0
|
rust: 1.77.1
|
||||||
- os: macos-latest
|
- os: macos-latest
|
||||||
rust: 1.77.0
|
rust: 1.77.1
|
||||||
|
|
||||||
# Minimum Supported Rust Version = 1.70.0
|
# Minimum Supported Rust Version = 1.77.0
|
||||||
- os: ubuntu-latest
|
- os: ubuntu-latest
|
||||||
rust: 1.70.0
|
rust: 1.77.0
|
||||||
runs-on: ${{ matrix.os }}
|
runs-on: ${{ matrix.os }}
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v4
|
- uses: actions/checkout@v4
|
||||||
|
|||||||
@@ -3,7 +3,7 @@ name = "deltachat"
|
|||||||
version = "1.137.1"
|
version = "1.137.1"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
license = "MPL-2.0"
|
license = "MPL-2.0"
|
||||||
rust-version = "1.70"
|
rust-version = "1.77"
|
||||||
repository = "https://github.com/deltachat/deltachat-core-rust"
|
repository = "https://github.com/deltachat/deltachat-core-rust"
|
||||||
|
|
||||||
[profile.dev]
|
[profile.dev]
|
||||||
|
|||||||
@@ -7,7 +7,7 @@ set -euo pipefail
|
|||||||
#
|
#
|
||||||
# Avoid using rustup here as it depends on reading /proc/self/exe and
|
# Avoid using rustup here as it depends on reading /proc/self/exe and
|
||||||
# has problems running under QEMU.
|
# has problems running under QEMU.
|
||||||
RUST_VERSION=1.77.0
|
RUST_VERSION=1.77.1
|
||||||
|
|
||||||
ARCH="$(uname -m)"
|
ARCH="$(uname -m)"
|
||||||
test -f "/lib/libc.musl-$ARCH.so.1" && LIBC=musl || LIBC=gnu
|
test -f "/lib/libc.musl-$ARCH.so.1" && LIBC=musl || LIBC=gnu
|
||||||
|
|||||||
32
src/html.rs
32
src/html.rs
@@ -7,12 +7,8 @@
|
|||||||
//! `MsgId.get_html()` will return HTML -
|
//! `MsgId.get_html()` will return HTML -
|
||||||
//! this allows nice quoting, handling linebreaks properly etc.
|
//! this allows nice quoting, handling linebreaks properly etc.
|
||||||
|
|
||||||
use std::future::Future;
|
|
||||||
use std::pin::Pin;
|
|
||||||
|
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use base64::Engine as _;
|
use base64::Engine as _;
|
||||||
use futures::future::FutureExt;
|
|
||||||
use lettre_email::mime::Mime;
|
use lettre_email::mime::Mime;
|
||||||
use lettre_email::PartBuilder;
|
use lettre_email::PartBuilder;
|
||||||
use mailparse::ParsedContentType;
|
use mailparse::ParsedContentType;
|
||||||
@@ -116,16 +112,14 @@ impl HtmlMsgParser {
|
|||||||
/// Usually, there is at most one plain-text and one HTML-text part,
|
/// Usually, there is at most one plain-text and one HTML-text part,
|
||||||
/// multiple plain-text parts might be used for mailinglist-footers,
|
/// multiple plain-text parts might be used for mailinglist-footers,
|
||||||
/// therefore we use the first one.
|
/// therefore we use the first one.
|
||||||
fn collect_texts_recursive<'a>(
|
async fn collect_texts_recursive<'a>(
|
||||||
&'a mut self,
|
&'a mut self,
|
||||||
mail: &'a mailparse::ParsedMail<'a>,
|
mail: &'a mailparse::ParsedMail<'a>,
|
||||||
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a + Send>> {
|
) -> Result<()> {
|
||||||
// Boxed future to deal with recursion
|
|
||||||
async move {
|
|
||||||
match get_mime_multipart_type(&mail.ctype) {
|
match get_mime_multipart_type(&mail.ctype) {
|
||||||
MimeMultipartType::Multiple => {
|
MimeMultipartType::Multiple => {
|
||||||
for cur_data in &mail.subparts {
|
for cur_data in &mail.subparts {
|
||||||
self.collect_texts_recursive(cur_data).await?
|
Box::pin(self.collect_texts_recursive(cur_data)).await?
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -135,7 +129,7 @@ impl HtmlMsgParser {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let mail = mailparse::parse_mail(&raw).context("failed to parse mail")?;
|
let mail = mailparse::parse_mail(&raw).context("failed to parse mail")?;
|
||||||
self.collect_texts_recursive(&mail).await
|
Box::pin(self.collect_texts_recursive(&mail)).await
|
||||||
}
|
}
|
||||||
MimeMultipartType::Single => {
|
MimeMultipartType::Single => {
|
||||||
let mimetype = mail.ctype.mimetype.parse::<Mime>()?;
|
let mimetype = mail.ctype.mimetype.parse::<Mime>()?;
|
||||||
@@ -166,22 +160,18 @@ impl HtmlMsgParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.boxed()
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Replace cid:-protocol by the data:-protocol where appropriate.
|
/// Replace cid:-protocol by the data:-protocol where appropriate.
|
||||||
/// This allows the final html-file to be self-contained.
|
/// This allows the final html-file to be self-contained.
|
||||||
fn cid_to_data_recursive<'a>(
|
async fn cid_to_data_recursive<'a>(
|
||||||
&'a mut self,
|
&'a mut self,
|
||||||
context: &'a Context,
|
context: &'a Context,
|
||||||
mail: &'a mailparse::ParsedMail<'a>,
|
mail: &'a mailparse::ParsedMail<'a>,
|
||||||
) -> Pin<Box<dyn Future<Output = Result<()>> + 'a + Send>> {
|
) -> Result<()> {
|
||||||
// Boxed future to deal with recursion
|
|
||||||
async move {
|
|
||||||
match get_mime_multipart_type(&mail.ctype) {
|
match get_mime_multipart_type(&mail.ctype) {
|
||||||
MimeMultipartType::Multiple => {
|
MimeMultipartType::Multiple => {
|
||||||
for cur_data in &mail.subparts {
|
for cur_data in &mail.subparts {
|
||||||
self.cid_to_data_recursive(context, cur_data).await?;
|
Box::pin(self.cid_to_data_recursive(context, cur_data)).await?;
|
||||||
}
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@@ -191,7 +181,7 @@ impl HtmlMsgParser {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let mail = mailparse::parse_mail(&raw).context("failed to parse mail")?;
|
let mail = mailparse::parse_mail(&raw).context("failed to parse mail")?;
|
||||||
self.cid_to_data_recursive(context, &mail).await
|
Box::pin(self.cid_to_data_recursive(context, &mail)).await
|
||||||
}
|
}
|
||||||
MimeMultipartType::Single => {
|
MimeMultipartType::Single => {
|
||||||
let mimetype = mail.ctype.mimetype.parse::<Mime>()?;
|
let mimetype = mail.ctype.mimetype.parse::<Mime>()?;
|
||||||
@@ -215,9 +205,7 @@ impl HtmlMsgParser {
|
|||||||
}
|
}
|
||||||
Err(e) => warn!(
|
Err(e) => warn!(
|
||||||
context,
|
context,
|
||||||
"Cannot create regex for cid: {} throws {}",
|
"Cannot create regex for cid: {} throws {}", re_string, e
|
||||||
re_string,
|
|
||||||
e
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -228,8 +216,6 @@ impl HtmlMsgParser {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.boxed()
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// 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).
|
||||||
|
|||||||
@@ -2,9 +2,7 @@
|
|||||||
|
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::future::Future;
|
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::pin::Pin;
|
|
||||||
use std::str;
|
use std::str;
|
||||||
|
|
||||||
use anyhow::{bail, Context as _, Result};
|
use anyhow::{bail, Context as _, Result};
|
||||||
@@ -818,16 +816,12 @@ impl MimeMessage {
|
|||||||
self.headers.get(headerdef.get_headername())
|
self.headers.get(headerdef.get_headername())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_mime_recursive<'a>(
|
async fn parse_mime_recursive<'a>(
|
||||||
&'a mut self,
|
&'a mut self,
|
||||||
context: &'a Context,
|
context: &'a Context,
|
||||||
mail: &'a mailparse::ParsedMail<'a>,
|
mail: &'a mailparse::ParsedMail<'a>,
|
||||||
is_related: bool,
|
is_related: bool,
|
||||||
) -> Pin<Box<dyn Future<Output = Result<bool>> + 'a + Send>> {
|
) -> Result<bool> {
|
||||||
use futures::future::FutureExt;
|
|
||||||
|
|
||||||
// Boxed future to deal with recursion
|
|
||||||
async move {
|
|
||||||
enum MimeS {
|
enum MimeS {
|
||||||
Multiple,
|
Multiple,
|
||||||
Single,
|
Single,
|
||||||
@@ -854,7 +848,7 @@ impl MimeMessage {
|
|||||||
|
|
||||||
let is_related = is_related || mimetype == "multipart/related";
|
let is_related = is_related || mimetype == "multipart/related";
|
||||||
match m {
|
match m {
|
||||||
MimeS::Multiple => self.handle_multiple(context, mail, is_related).await,
|
MimeS::Multiple => Box::pin(self.handle_multiple(context, mail, is_related)).await,
|
||||||
MimeS::Message => {
|
MimeS::Message => {
|
||||||
let raw = mail.get_body_raw()?;
|
let raw = mail.get_body_raw()?;
|
||||||
if raw.is_empty() {
|
if raw.is_empty() {
|
||||||
@@ -862,7 +856,7 @@ impl MimeMessage {
|
|||||||
}
|
}
|
||||||
let mail = mailparse::parse_mail(&raw).context("failed to parse mail")?;
|
let mail = mailparse::parse_mail(&raw).context("failed to parse mail")?;
|
||||||
|
|
||||||
self.parse_mime_recursive(context, &mail, is_related).await
|
Box::pin(self.parse_mime_recursive(context, &mail, is_related)).await
|
||||||
}
|
}
|
||||||
MimeS::Single => {
|
MimeS::Single => {
|
||||||
self.add_single_part_if_known(context, mail, is_related)
|
self.add_single_part_if_known(context, mail, is_related)
|
||||||
@@ -870,8 +864,6 @@ impl MimeMessage {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
.boxed()
|
|
||||||
}
|
|
||||||
|
|
||||||
async fn handle_multiple(
|
async fn handle_multiple(
|
||||||
&mut self,
|
&mut self,
|
||||||
|
|||||||
Reference in New Issue
Block a user