mirror of
https://github.com/chatmail/core.git
synced 2026-05-01 20:36:31 +03:00
refactor: replace once_cell::sync::Lazy with std::sync::LazyLock
This commit is contained in:
3
Cargo.lock
generated
3
Cargo.lock
generated
@@ -1312,7 +1312,6 @@ dependencies = [
|
|||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"num_cpus",
|
"num_cpus",
|
||||||
"once_cell",
|
|
||||||
"parking_lot",
|
"parking_lot",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pgp",
|
"pgp",
|
||||||
@@ -1362,7 +1361,6 @@ version = "0.0.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"chrono",
|
"chrono",
|
||||||
"once_cell",
|
|
||||||
"regex",
|
"regex",
|
||||||
"rusqlite",
|
"rusqlite",
|
||||||
]
|
]
|
||||||
@@ -1455,7 +1453,6 @@ dependencies = [
|
|||||||
"human-panic",
|
"human-panic",
|
||||||
"libc",
|
"libc",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"once_cell",
|
|
||||||
"rand 0.8.5",
|
"rand 0.8.5",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"thiserror 2.0.12",
|
"thiserror 2.0.12",
|
||||||
|
|||||||
@@ -72,7 +72,6 @@ mime = "0.3.17"
|
|||||||
num_cpus = "1.16"
|
num_cpus = "1.16"
|
||||||
num-derive = "0.4"
|
num-derive = "0.4"
|
||||||
num-traits = { workspace = true }
|
num-traits = { workspace = true }
|
||||||
once_cell = { workspace = true }
|
|
||||||
parking_lot = "0.12"
|
parking_lot = "0.12"
|
||||||
percent-encoding = "2.3"
|
percent-encoding = "2.3"
|
||||||
pgp = { version = "0.15.0", default-features = false }
|
pgp = { version = "0.15.0", default-features = false }
|
||||||
@@ -185,7 +184,6 @@ log = "0.4"
|
|||||||
mailparse = "0.16.1"
|
mailparse = "0.16.1"
|
||||||
nu-ansi-term = "0.46"
|
nu-ansi-term = "0.46"
|
||||||
num-traits = "0.2"
|
num-traits = "0.2"
|
||||||
once_cell = "1.21.3"
|
|
||||||
rand = "0.8"
|
rand = "0.8"
|
||||||
regex = "1.10"
|
regex = "1.10"
|
||||||
rusqlite = "0.32"
|
rusqlite = "0.32"
|
||||||
|
|||||||
@@ -9,7 +9,6 @@ license = "MPL-2.0"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
once_cell = { workspace = true }
|
|
||||||
regex = { workspace = true }
|
regex = { workspace = true }
|
||||||
rusqlite = { workspace = true } # Needed in order to `impl rusqlite::types::ToSql for EmailAddress`. Could easily be put behind a feature.
|
rusqlite = { workspace = true } # Needed in order to `impl rusqlite::types::ToSql for EmailAddress`. Could easily be put behind a feature.
|
||||||
chrono = { workspace = true, features = ["alloc", "clock", "std"] }
|
chrono = { workspace = true, features = ["alloc", "clock", "std"] }
|
||||||
|
|||||||
@@ -29,12 +29,12 @@
|
|||||||
|
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use anyhow::bail;
|
use anyhow::bail;
|
||||||
use anyhow::Context as _;
|
use anyhow::Context as _;
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use chrono::{DateTime, NaiveDateTime};
|
use chrono::{DateTime, NaiveDateTime};
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -155,7 +155,8 @@ pub fn parse_vcard(vcard: &str) -> Vec<VcardContact> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Remove line folding, see https://datatracker.ietf.org/doc/html/rfc6350#section-3.2
|
// Remove line folding, see https://datatracker.ietf.org/doc/html/rfc6350#section-3.2
|
||||||
static NEWLINE_AND_SPACE_OR_TAB: Lazy<Regex> = Lazy::new(|| Regex::new("\r?\n[\t ]").unwrap());
|
static NEWLINE_AND_SPACE_OR_TAB: LazyLock<Regex> =
|
||||||
|
LazyLock::new(|| Regex::new("\r?\n[\t ]").unwrap());
|
||||||
let unfolded_lines = NEWLINE_AND_SPACE_OR_TAB.replace_all(vcard, "");
|
let unfolded_lines = NEWLINE_AND_SPACE_OR_TAB.replace_all(vcard, "");
|
||||||
|
|
||||||
let mut lines = unfolded_lines.lines().peekable();
|
let mut lines = unfolded_lines.lines().peekable();
|
||||||
@@ -276,7 +277,8 @@ impl rusqlite::types::ToSql for ContactAddress {
|
|||||||
/// - Removes special characters from the name, see [`sanitize_name()`]
|
/// - Removes special characters from the name, see [`sanitize_name()`]
|
||||||
/// - Removes the name if it is equal to the address by setting it to ""
|
/// - Removes the name if it is equal to the address by setting it to ""
|
||||||
pub fn sanitize_name_and_addr(name: &str, addr: &str) -> (String, String) {
|
pub fn sanitize_name_and_addr(name: &str, addr: &str) -> (String, String) {
|
||||||
static ADDR_WITH_NAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new("(.*)<(.*)>").unwrap());
|
static ADDR_WITH_NAME_REGEX: LazyLock<Regex> =
|
||||||
|
LazyLock::new(|| Regex::new("(.*)<(.*)>").unwrap());
|
||||||
let (name, addr) = if let Some(captures) = ADDR_WITH_NAME_REGEX.captures(addr.as_ref()) {
|
let (name, addr) = if let Some(captures) = ADDR_WITH_NAME_REGEX.captures(addr.as_ref()) {
|
||||||
(
|
(
|
||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
|
|||||||
@@ -24,7 +24,6 @@ tokio = { workspace = true, features = ["rt-multi-thread"] }
|
|||||||
anyhow = { workspace = true }
|
anyhow = { workspace = true }
|
||||||
thiserror = { workspace = true }
|
thiserror = { workspace = true }
|
||||||
rand = { workspace = true }
|
rand = { workspace = true }
|
||||||
once_cell = { workspace = true }
|
|
||||||
yerpc = { workspace = true, features = ["anyhow_expose"] }
|
yerpc = { workspace = true, features = ["anyhow_expose"] }
|
||||||
|
|
||||||
[features]
|
[features]
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ use std::future::Future;
|
|||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::ptr;
|
use std::ptr;
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, LazyLock};
|
||||||
use std::time::{Duration, SystemTime};
|
use std::time::{Duration, SystemTime};
|
||||||
|
|
||||||
use anyhow::Context as _;
|
use anyhow::Context as _;
|
||||||
@@ -38,7 +38,6 @@ use deltachat::{accounts::Accounts, log::LogExt};
|
|||||||
use deltachat_jsonrpc::api::CommandApi;
|
use deltachat_jsonrpc::api::CommandApi;
|
||||||
use deltachat_jsonrpc::yerpc::{OutReceiver, RpcClient, RpcSession};
|
use deltachat_jsonrpc::yerpc::{OutReceiver, RpcClient, RpcSession};
|
||||||
use num_traits::{FromPrimitive, ToPrimitive};
|
use num_traits::{FromPrimitive, ToPrimitive};
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use tokio::runtime::Runtime;
|
use tokio::runtime::Runtime;
|
||||||
use tokio::sync::RwLock;
|
use tokio::sync::RwLock;
|
||||||
@@ -68,7 +67,8 @@ const DC_GCM_INFO_ONLY: u32 = 0x02;
|
|||||||
/// Struct representing the deltachat context.
|
/// Struct representing the deltachat context.
|
||||||
pub type dc_context_t = Context;
|
pub type dc_context_t = Context;
|
||||||
|
|
||||||
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("unable to create tokio runtime"));
|
static RT: LazyLock<Runtime> =
|
||||||
|
LazyLock::new(|| Runtime::new().expect("unable to create tokio runtime"));
|
||||||
|
|
||||||
fn block_on<T>(fut: T) -> T::Output
|
fn block_on<T>(fut: T) -> T::Output
|
||||||
where
|
where
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ if __name__ == "__main__":
|
|||||||
" Config, ConfigDefault, Oauth2Authorizer, Provider, ProviderOptions, Server, Status,\n"
|
" Config, ConfigDefault, Oauth2Authorizer, Provider, ProviderOptions, Server, Status,\n"
|
||||||
"};\n"
|
"};\n"
|
||||||
"use std::collections::HashMap;\n\n"
|
"use std::collections::HashMap;\n\n"
|
||||||
"use once_cell::sync::Lazy;\n\n"
|
"use std::sync::LazyLock;\n\n"
|
||||||
)
|
)
|
||||||
|
|
||||||
process_dir(Path(sys.argv[1]))
|
process_dir(Path(sys.argv[1]))
|
||||||
@@ -224,7 +224,7 @@ if __name__ == "__main__":
|
|||||||
out_all += out_domains
|
out_all += out_domains
|
||||||
out_all += "];\n\n"
|
out_all += "];\n\n"
|
||||||
|
|
||||||
out_all += "pub(crate) static PROVIDER_IDS: Lazy<HashMap<&'static str, &'static Provider>> = Lazy::new(|| HashMap::from([\n"
|
out_all += "pub(crate) static PROVIDER_IDS: LazyLock<HashMap<&'static str, &'static Provider>> = LazyLock::new(|| HashMap::from([\n"
|
||||||
out_all += out_ids
|
out_all += out_ids
|
||||||
out_all += "]));\n\n"
|
out_all += "]));\n\n"
|
||||||
|
|
||||||
@@ -233,8 +233,8 @@ if __name__ == "__main__":
|
|||||||
else:
|
else:
|
||||||
now = datetime.datetime.fromisoformat(sys.argv[2])
|
now = datetime.datetime.fromisoformat(sys.argv[2])
|
||||||
out_all += (
|
out_all += (
|
||||||
"pub static _PROVIDER_UPDATED: Lazy<chrono::NaiveDate> = "
|
"pub static _PROVIDER_UPDATED: LazyLock<chrono::NaiveDate> = "
|
||||||
"Lazy::new(|| chrono::NaiveDate::from_ymd_opt("
|
"LazyLock::new(|| chrono::NaiveDate::from_ymd_opt("
|
||||||
+ str(now.year)
|
+ str(now.year)
|
||||||
+ ", "
|
+ ", "
|
||||||
+ str(now.month)
|
+ str(now.month)
|
||||||
|
|||||||
@@ -4,12 +4,12 @@
|
|||||||
use std::borrow::Cow;
|
use std::borrow::Cow;
|
||||||
use std::collections::BTreeSet;
|
use std::collections::BTreeSet;
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use anyhow::Result;
|
use anyhow::Result;
|
||||||
use deltachat_contact_tools::EmailAddress;
|
use deltachat_contact_tools::EmailAddress;
|
||||||
use mailparse::MailHeaderMap;
|
use mailparse::MailHeaderMap;
|
||||||
use mailparse::ParsedMail;
|
use mailparse::ParsedMail;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
@@ -107,7 +107,8 @@ fn remove_comments(header: &str) -> Cow<'_, str> {
|
|||||||
// In Pomsky, this is:
|
// In Pomsky, this is:
|
||||||
// "(" Codepoint* lazy ")"
|
// "(" Codepoint* lazy ")"
|
||||||
// See https://playground.pomsky-lang.org/?text=%22(%22%20Codepoint*%20lazy%20%22)%22
|
// See https://playground.pomsky-lang.org/?text=%22(%22%20Codepoint*%20lazy%20%22)%22
|
||||||
static RE: Lazy<regex::Regex> = Lazy::new(|| regex::Regex::new(r"\([\s\S]*?\)").unwrap());
|
static RE: LazyLock<regex::Regex> =
|
||||||
|
LazyLock::new(|| regex::Regex::new(r"\([\s\S]*?\)").unwrap());
|
||||||
|
|
||||||
RE.replace_all(header, " ")
|
RE.replace_all(header, " ")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
//! # Chat list module.
|
//! # Chat list module.
|
||||||
|
|
||||||
use anyhow::{ensure, Context as _, Result};
|
use anyhow::{ensure, Context as _, Result};
|
||||||
use once_cell::sync::Lazy;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use crate::chat::{update_special_chat_names, Chat, ChatId, ChatVisibility};
|
use crate::chat::{update_special_chat_names, Chat, ChatId, ChatVisibility};
|
||||||
use crate::constants::{
|
use crate::constants::{
|
||||||
@@ -17,8 +17,8 @@ use crate::summary::Summary;
|
|||||||
use crate::tools::IsNoneOrEmpty;
|
use crate::tools::IsNoneOrEmpty;
|
||||||
|
|
||||||
/// Regex to find out if a query should filter by unread messages.
|
/// Regex to find out if a query should filter by unread messages.
|
||||||
pub static IS_UNREAD_FILTER: Lazy<regex::Regex> =
|
pub static IS_UNREAD_FILTER: LazyLock<regex::Regex> =
|
||||||
Lazy::new(|| regex::Regex::new(r"\bis:unread\b").unwrap());
|
LazyLock::new(|| regex::Regex::new(r"\bis:unread\b").unwrap());
|
||||||
|
|
||||||
/// An object representing a single chatlist in memory.
|
/// An object representing a single chatlist in memory.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -2,14 +2,16 @@
|
|||||||
|
|
||||||
#![allow(missing_docs)]
|
#![allow(missing_docs)]
|
||||||
|
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use deltachat_derive::{FromSql, ToSql};
|
use deltachat_derive::{FromSql, ToSql};
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use percent_encoding::{AsciiSet, NON_ALPHANUMERIC};
|
use percent_encoding::{AsciiSet, NON_ALPHANUMERIC};
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::chat::ChatId;
|
use crate::chat::ChatId;
|
||||||
|
|
||||||
pub static DC_VERSION_STR: Lazy<String> = Lazy::new(|| env!("CARGO_PKG_VERSION").to_string());
|
pub static DC_VERSION_STR: LazyLock<String> =
|
||||||
|
LazyLock::new(|| env!("CARGO_PKG_VERSION").to_string());
|
||||||
|
|
||||||
/// Set of characters to percent-encode in email addresses and names.
|
/// Set of characters to percent-encode in email addresses and names.
|
||||||
pub(crate) const NON_ALPHANUMERIC_WITHOUT_DOT: &AsciiSet = &NON_ALPHANUMERIC.remove(b'.');
|
pub(crate) const NON_ALPHANUMERIC_WITHOUT_DOT: &AsciiSet = &NON_ALPHANUMERIC.remove(b'.');
|
||||||
|
|||||||
@@ -3,8 +3,8 @@
|
|||||||
//! A module to remove HTML tags from the email text
|
//! A module to remove HTML tags from the email text
|
||||||
|
|
||||||
use std::io::BufRead;
|
use std::io::BufRead;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use quick_xml::{
|
use quick_xml::{
|
||||||
events::{BytesEnd, BytesStart, BytesText},
|
events::{BytesEnd, BytesStart, BytesText},
|
||||||
Reader,
|
Reader,
|
||||||
@@ -176,7 +176,8 @@ fn dehtml_quick_xml(buf: &str) -> (String, String) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn dehtml_text_cb(event: &BytesText, dehtml: &mut Dehtml) {
|
fn dehtml_text_cb(event: &BytesText, dehtml: &mut Dehtml) {
|
||||||
static LINE_RE: Lazy<regex::Regex> = Lazy::new(|| regex::Regex::new(r"(\r?\n)+").unwrap());
|
static LINE_RE: LazyLock<regex::Regex> =
|
||||||
|
LazyLock::new(|| regex::Regex::new(r"(\r?\n)+").unwrap());
|
||||||
|
|
||||||
if dehtml.get_add_text() == AddText::YesPreserveLineEnds
|
if dehtml.get_add_text() == AddText::YesPreserveLineEnds
|
||||||
|| dehtml.get_add_text() == AddText::YesRemoveLineEnds
|
|| dehtml.get_add_text() == AddText::YesRemoveLineEnds
|
||||||
|
|||||||
@@ -456,15 +456,13 @@ impl std::str::FromStr for Fingerprint {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, LazyLock};
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::config::Config;
|
use crate::config::Config;
|
||||||
use crate::test_utils::{alice_keypair, TestContext};
|
use crate::test_utils::{alice_keypair, TestContext};
|
||||||
|
|
||||||
static KEYPAIR: Lazy<KeyPair> = Lazy::new(alice_keypair);
|
static KEYPAIR: LazyLock<KeyPair> = LazyLock::new(alice_keypair);
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_armored_string() {
|
fn test_from_armored_string() {
|
||||||
|
|||||||
@@ -44,13 +44,13 @@ use anyhow::{Context as _, Result};
|
|||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
|
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr, SocketAddr};
|
||||||
use std::str::FromStr;
|
use std::str::FromStr;
|
||||||
|
use std::sync::LazyLock;
|
||||||
use tokio::net::lookup_host;
|
use tokio::net::lookup_host;
|
||||||
use tokio::time::timeout;
|
use tokio::time::timeout;
|
||||||
|
|
||||||
use super::load_connection_timestamp;
|
use super::load_connection_timestamp;
|
||||||
use crate::context::Context;
|
use crate::context::Context;
|
||||||
use crate::tools::time;
|
use crate::tools::time;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
|
|
||||||
/// Inserts entry into DNS cache
|
/// Inserts entry into DNS cache
|
||||||
/// or updates existing one with a new timestamp.
|
/// or updates existing one with a new timestamp.
|
||||||
@@ -90,8 +90,8 @@ pub(crate) async fn prune_dns_cache(context: &Context) -> Result<()> {
|
|||||||
/// <https://docs.rs/tokio/1.40.0/tokio/sync/struct.Mutex.html#which-kind-of-mutex-should-you-use>
|
/// <https://docs.rs/tokio/1.40.0/tokio/sync/struct.Mutex.html#which-kind-of-mutex-should-you-use>
|
||||||
/// and
|
/// and
|
||||||
/// <https://stackoverflow.com/questions/63712823/why-do-i-get-a-deadlock-when-using-tokio-with-a-stdsyncmutex>.
|
/// <https://stackoverflow.com/questions/63712823/why-do-i-get-a-deadlock-when-using-tokio-with-a-stdsyncmutex>.
|
||||||
static LOOKUP_HOST_CACHE: Lazy<parking_lot::RwLock<HashMap<String, Vec<IpAddr>>>> =
|
static LOOKUP_HOST_CACHE: LazyLock<parking_lot::RwLock<HashMap<String, Vec<IpAddr>>>> =
|
||||||
Lazy::new(Default::default);
|
LazyLock::new(Default::default);
|
||||||
|
|
||||||
/// Wrapper for `lookup_host` that returns IP addresses.
|
/// Wrapper for `lookup_host` that returns IP addresses.
|
||||||
async fn lookup_ips(host: impl tokio::net::ToSocketAddrs) -> Result<impl Iterator<Item = IpAddr>> {
|
async fn lookup_ips(host: impl tokio::net::ToSocketAddrs) -> Result<impl Iterator<Item = IpAddr>> {
|
||||||
@@ -229,7 +229,7 @@ pub(crate) async fn update_connect_timestamp(
|
|||||||
///
|
///
|
||||||
/// See <https://support.delta.chat/t/no-dns-resolution-result/2778> and
|
/// See <https://support.delta.chat/t/no-dns-resolution-result/2778> and
|
||||||
/// <https://github.com/deltachat/deltachat-core-rust/issues/4920> for reasons.
|
/// <https://github.com/deltachat/deltachat-core-rust/issues/4920> for reasons.
|
||||||
static DNS_PRELOAD: Lazy<HashMap<&'static str, Vec<IpAddr>>> = Lazy::new(|| {
|
static DNS_PRELOAD: LazyLock<HashMap<&'static str, Vec<IpAddr>>> = LazyLock::new(|| {
|
||||||
HashMap::from([
|
HashMap::from([
|
||||||
(
|
(
|
||||||
"mail.sangham.net",
|
"mail.sangham.net",
|
||||||
|
|||||||
@@ -424,7 +424,7 @@ pub async fn symm_decrypt<T: std::io::Read + std::io::Seek>(
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
use once_cell::sync::Lazy;
|
use std::sync::LazyLock;
|
||||||
use tokio::sync::OnceCell;
|
use tokio::sync::OnceCell;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
@@ -502,7 +502,7 @@ mod tests {
|
|||||||
static CLEARTEXT: &[u8] = b"This is a test";
|
static CLEARTEXT: &[u8] = b"This is a test";
|
||||||
|
|
||||||
/// Initialised [TestKeys] for tests.
|
/// Initialised [TestKeys] for tests.
|
||||||
static KEYS: Lazy<TestKeys> = Lazy::new(TestKeys::new);
|
static KEYS: LazyLock<TestKeys> = LazyLock::new(TestKeys::new);
|
||||||
|
|
||||||
static CTEXT_SIGNED: OnceCell<String> = OnceCell::const_new();
|
static CTEXT_SIGNED: OnceCell<String> = OnceCell::const_new();
|
||||||
static CTEXT_UNSIGNED: OnceCell<String> = OnceCell::const_new();
|
static CTEXT_UNSIGNED: OnceCell<String> = OnceCell::const_new();
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
//! Handle plain text together with some attributes.
|
//! Handle plain text together with some attributes.
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use crate::simplify::remove_message_footer;
|
use crate::simplify::remove_message_footer;
|
||||||
|
|
||||||
@@ -25,10 +25,10 @@ impl PlainText {
|
|||||||
/// Convert plain text to HTML.
|
/// Convert plain text to HTML.
|
||||||
/// The function handles quotes, links, fixed and floating text paragraphs.
|
/// The function handles quotes, links, fixed and floating text paragraphs.
|
||||||
pub fn to_html(&self) -> String {
|
pub fn to_html(&self) -> String {
|
||||||
static LINKIFY_MAIL_RE: Lazy<regex::Regex> =
|
static LINKIFY_MAIL_RE: LazyLock<regex::Regex> =
|
||||||
Lazy::new(|| regex::Regex::new(r"\b([\w.\-+]+@[\w.\-]+)\b").unwrap());
|
LazyLock::new(|| regex::Regex::new(r"\b([\w.\-+]+@[\w.\-]+)\b").unwrap());
|
||||||
|
|
||||||
static LINKIFY_URL_RE: Lazy<regex::Regex> = Lazy::new(|| {
|
static LINKIFY_URL_RE: LazyLock<regex::Regex> = LazyLock::new(|| {
|
||||||
regex::Regex::new(r"\b((http|https|ftp|ftps):[\w.,:;$/@!?&%\-~=#+]+)").unwrap()
|
regex::Regex::new(r"\b((http|https|ftp|ftps):[\w.,:;$/@!?&%\-~=#+]+)").unwrap()
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ use crate::provider::{
|
|||||||
};
|
};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
|
|
||||||
use once_cell::sync::Lazy;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
// 163.md: 163.com
|
// 163.md: 163.com
|
||||||
static P_163: Provider = Provider {
|
static P_163: Provider = Provider {
|
||||||
@@ -2406,84 +2406,85 @@ pub(crate) static PROVIDER_DATA: [(&str, &Provider); 533] = [
|
|||||||
("zoho.com", &P_ZOHO),
|
("zoho.com", &P_ZOHO),
|
||||||
];
|
];
|
||||||
|
|
||||||
pub(crate) static PROVIDER_IDS: Lazy<HashMap<&'static str, &'static Provider>> = Lazy::new(|| {
|
pub(crate) static PROVIDER_IDS: LazyLock<HashMap<&'static str, &'static Provider>> =
|
||||||
HashMap::from([
|
LazyLock::new(|| {
|
||||||
("163", &P_163),
|
HashMap::from([
|
||||||
("aktivix.org", &P_AKTIVIX_ORG),
|
("163", &P_163),
|
||||||
("aliyun", &P_ALIYUN),
|
("aktivix.org", &P_AKTIVIX_ORG),
|
||||||
("aol", &P_AOL),
|
("aliyun", &P_ALIYUN),
|
||||||
("arcor.de", &P_ARCOR_DE),
|
("aol", &P_AOL),
|
||||||
("autistici.org", &P_AUTISTICI_ORG),
|
("arcor.de", &P_ARCOR_DE),
|
||||||
("blindzeln.org", &P_BLINDZELN_ORG),
|
("autistici.org", &P_AUTISTICI_ORG),
|
||||||
("bluewin.ch", &P_BLUEWIN_CH),
|
("blindzeln.org", &P_BLINDZELN_ORG),
|
||||||
("buzon.uy", &P_BUZON_UY),
|
("bluewin.ch", &P_BLUEWIN_CH),
|
||||||
("chello.at", &P_CHELLO_AT),
|
("buzon.uy", &P_BUZON_UY),
|
||||||
("comcast", &P_COMCAST),
|
("chello.at", &P_CHELLO_AT),
|
||||||
("daleth.cafe", &P_DALETH_CAFE),
|
("comcast", &P_COMCAST),
|
||||||
("dismail.de", &P_DISMAIL_DE),
|
("daleth.cafe", &P_DALETH_CAFE),
|
||||||
("disroot", &P_DISROOT),
|
("dismail.de", &P_DISMAIL_DE),
|
||||||
("e.email", &P_E_EMAIL),
|
("disroot", &P_DISROOT),
|
||||||
("espiv.net", &P_ESPIV_NET),
|
("e.email", &P_E_EMAIL),
|
||||||
("example.com", &P_EXAMPLE_COM),
|
("espiv.net", &P_ESPIV_NET),
|
||||||
("fastmail", &P_FASTMAIL),
|
("example.com", &P_EXAMPLE_COM),
|
||||||
("firemail.de", &P_FIREMAIL_DE),
|
("fastmail", &P_FASTMAIL),
|
||||||
("five.chat", &P_FIVE_CHAT),
|
("firemail.de", &P_FIREMAIL_DE),
|
||||||
("freenet.de", &P_FREENET_DE),
|
("five.chat", &P_FIVE_CHAT),
|
||||||
("gmail", &P_GMAIL),
|
("freenet.de", &P_FREENET_DE),
|
||||||
("gmx.net", &P_GMX_NET),
|
("gmail", &P_GMAIL),
|
||||||
("hermes.radio", &P_HERMES_RADIO),
|
("gmx.net", &P_GMX_NET),
|
||||||
("hey.com", &P_HEY_COM),
|
("hermes.radio", &P_HERMES_RADIO),
|
||||||
("i.ua", &P_I_UA),
|
("hey.com", &P_HEY_COM),
|
||||||
("i3.net", &P_I3_NET),
|
("i.ua", &P_I_UA),
|
||||||
("icloud", &P_ICLOUD),
|
("i3.net", &P_I3_NET),
|
||||||
("infomaniak.com", &P_INFOMANIAK_COM),
|
("icloud", &P_ICLOUD),
|
||||||
("kolst.com", &P_KOLST_COM),
|
("infomaniak.com", &P_INFOMANIAK_COM),
|
||||||
("kontent.com", &P_KONTENT_COM),
|
("kolst.com", &P_KOLST_COM),
|
||||||
("mail.com", &P_MAIL_COM),
|
("kontent.com", &P_KONTENT_COM),
|
||||||
("mail.de", &P_MAIL_DE),
|
("mail.com", &P_MAIL_COM),
|
||||||
("mail.ru", &P_MAIL_RU),
|
("mail.de", &P_MAIL_DE),
|
||||||
("mail2tor", &P_MAIL2TOR),
|
("mail.ru", &P_MAIL_RU),
|
||||||
("mailbox.org", &P_MAILBOX_ORG),
|
("mail2tor", &P_MAIL2TOR),
|
||||||
("mailo.com", &P_MAILO_COM),
|
("mailbox.org", &P_MAILBOX_ORG),
|
||||||
("mehl.cloud", &P_MEHL_CLOUD),
|
("mailo.com", &P_MAILO_COM),
|
||||||
("mehl.store", &P_MEHL_STORE),
|
("mehl.cloud", &P_MEHL_CLOUD),
|
||||||
("migadu", &P_MIGADU),
|
("mehl.store", &P_MEHL_STORE),
|
||||||
("nauta.cu", &P_NAUTA_CU),
|
("migadu", &P_MIGADU),
|
||||||
("naver", &P_NAVER),
|
("nauta.cu", &P_NAUTA_CU),
|
||||||
("nine.testrun.org", &P_NINE_TESTRUN_ORG),
|
("naver", &P_NAVER),
|
||||||
("nubo.coop", &P_NUBO_COOP),
|
("nine.testrun.org", &P_NINE_TESTRUN_ORG),
|
||||||
("outlook.com", &P_OUTLOOK_COM),
|
("nubo.coop", &P_NUBO_COOP),
|
||||||
("ouvaton.coop", &P_OUVATON_COOP),
|
("outlook.com", &P_OUTLOOK_COM),
|
||||||
("posteo", &P_POSTEO),
|
("ouvaton.coop", &P_OUVATON_COOP),
|
||||||
("protonmail", &P_PROTONMAIL),
|
("posteo", &P_POSTEO),
|
||||||
("purelymail.com", &P_PURELYMAIL_COM),
|
("protonmail", &P_PROTONMAIL),
|
||||||
("qq", &P_QQ),
|
("purelymail.com", &P_PURELYMAIL_COM),
|
||||||
("rambler.ru", &P_RAMBLER_RU),
|
("qq", &P_QQ),
|
||||||
("riseup.net", &P_RISEUP_NET),
|
("rambler.ru", &P_RAMBLER_RU),
|
||||||
("rogers.com", &P_ROGERS_COM),
|
("riseup.net", &P_RISEUP_NET),
|
||||||
("sonic", &P_SONIC),
|
("rogers.com", &P_ROGERS_COM),
|
||||||
("stinpriza.net", &P_STINPRIZA_NET),
|
("sonic", &P_SONIC),
|
||||||
("systemausfall.org", &P_SYSTEMAUSFALL_ORG),
|
("stinpriza.net", &P_STINPRIZA_NET),
|
||||||
("systemli.org", &P_SYSTEMLI_ORG),
|
("systemausfall.org", &P_SYSTEMAUSFALL_ORG),
|
||||||
("t-online", &P_T_ONLINE),
|
("systemli.org", &P_SYSTEMLI_ORG),
|
||||||
("testrun", &P_TESTRUN),
|
("t-online", &P_T_ONLINE),
|
||||||
("tiscali.it", &P_TISCALI_IT),
|
("testrun", &P_TESTRUN),
|
||||||
("tutanota", &P_TUTANOTA),
|
("tiscali.it", &P_TISCALI_IT),
|
||||||
("ukr.net", &P_UKR_NET),
|
("tutanota", &P_TUTANOTA),
|
||||||
("undernet.uy", &P_UNDERNET_UY),
|
("ukr.net", &P_UKR_NET),
|
||||||
("vfemail", &P_VFEMAIL),
|
("undernet.uy", &P_UNDERNET_UY),
|
||||||
("vivaldi", &P_VIVALDI),
|
("vfemail", &P_VFEMAIL),
|
||||||
("vk.com", &P_VK_COM),
|
("vivaldi", &P_VIVALDI),
|
||||||
("vodafone.de", &P_VODAFONE_DE),
|
("vk.com", &P_VK_COM),
|
||||||
("web.de", &P_WEB_DE),
|
("vodafone.de", &P_VODAFONE_DE),
|
||||||
("wkpb.de", &P_WKPB_DE),
|
("web.de", &P_WEB_DE),
|
||||||
("yahoo", &P_YAHOO),
|
("wkpb.de", &P_WKPB_DE),
|
||||||
("yandex.ru", &P_YANDEX_RU),
|
("yahoo", &P_YAHOO),
|
||||||
("yggmail", &P_YGGMAIL),
|
("yandex.ru", &P_YANDEX_RU),
|
||||||
("ziggo.nl", &P_ZIGGO_NL),
|
("yggmail", &P_YGGMAIL),
|
||||||
("zoho", &P_ZOHO),
|
("ziggo.nl", &P_ZIGGO_NL),
|
||||||
])
|
("zoho", &P_ZOHO),
|
||||||
});
|
])
|
||||||
|
});
|
||||||
|
|
||||||
pub static _PROVIDER_UPDATED: Lazy<chrono::NaiveDate> =
|
pub static _PROVIDER_UPDATED: LazyLock<chrono::NaiveDate> =
|
||||||
Lazy::new(|| chrono::NaiveDate::from_ymd_opt(2024, 9, 13).unwrap());
|
LazyLock::new(|| chrono::NaiveDate::from_ymd_opt(2024, 9, 13).unwrap());
|
||||||
|
|||||||
10
src/qr.rs
10
src/qr.rs
@@ -2,11 +2,11 @@
|
|||||||
|
|
||||||
mod dclogin_scheme;
|
mod dclogin_scheme;
|
||||||
use std::collections::BTreeMap;
|
use std::collections::BTreeMap;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use anyhow::{anyhow, bail, ensure, Context as _, Result};
|
use anyhow::{anyhow, bail, ensure, Context as _, Result};
|
||||||
pub use dclogin_scheme::LoginOptions;
|
pub use dclogin_scheme::LoginOptions;
|
||||||
use deltachat_contact_tools::{addr_normalize, may_be_valid_addr, ContactAddress};
|
use deltachat_contact_tools::{addr_normalize, may_be_valid_addr, ContactAddress};
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use percent_encoding::{percent_decode_str, percent_encode, NON_ALPHANUMERIC};
|
use percent_encoding::{percent_decode_str, percent_encode, NON_ALPHANUMERIC};
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
@@ -915,10 +915,10 @@ async fn decode_matmsg(context: &Context, qr: &str) -> Result<Qr> {
|
|||||||
Qr::from_address(context, name, &addr, None).await
|
Qr::from_address(context, name, &addr, None).await
|
||||||
}
|
}
|
||||||
|
|
||||||
static VCARD_NAME_RE: Lazy<regex::Regex> =
|
static VCARD_NAME_RE: LazyLock<regex::Regex> =
|
||||||
Lazy::new(|| regex::Regex::new(r"(?m)^N:([^;]*);([^;\n]*)").unwrap());
|
LazyLock::new(|| regex::Regex::new(r"(?m)^N:([^;]*);([^;\n]*)").unwrap());
|
||||||
static VCARD_EMAIL_RE: Lazy<regex::Regex> =
|
static VCARD_EMAIL_RE: LazyLock<regex::Regex> =
|
||||||
Lazy::new(|| regex::Regex::new(r"(?m)^EMAIL([^:\n]*):([^;\n]*)").unwrap());
|
LazyLock::new(|| regex::Regex::new(r"(?m)^EMAIL([^:\n]*):([^;\n]*)").unwrap());
|
||||||
|
|
||||||
/// Extract address for the vcard scheme.
|
/// Extract address for the vcard scheme.
|
||||||
///
|
///
|
||||||
|
|||||||
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
use std::collections::HashSet;
|
use std::collections::HashSet;
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
use anyhow::{Context as _, Result};
|
use anyhow::{Context as _, Result};
|
||||||
use data_encoding::BASE32_NOPAD;
|
use data_encoding::BASE32_NOPAD;
|
||||||
@@ -9,7 +10,6 @@ use deltachat_contact_tools::{addr_cmp, may_be_valid_addr, sanitize_single_line,
|
|||||||
use iroh_gossip::proto::TopicId;
|
use iroh_gossip::proto::TopicId;
|
||||||
use mailparse::SingleInfo;
|
use mailparse::SingleInfo;
|
||||||
use num_traits::FromPrimitive;
|
use num_traits::FromPrimitive;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::aheader::EncryptPreference;
|
use crate::aheader::EncryptPreference;
|
||||||
@@ -2717,7 +2717,7 @@ async fn group_changes_msgs(
|
|||||||
Ok(group_changes_msgs)
|
Ok(group_changes_msgs)
|
||||||
}
|
}
|
||||||
|
|
||||||
static LIST_ID_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new(r"^(.+)<(.+)>$").unwrap());
|
static LIST_ID_REGEX: LazyLock<Regex> = LazyLock::new(|| Regex::new(r"^(.+)<(.+)>$").unwrap());
|
||||||
|
|
||||||
fn mailinglist_header_listid(list_id_header: &str) -> Result<String> {
|
fn mailinglist_header_listid(list_id_header: &str) -> Result<String> {
|
||||||
Ok(match LIST_ID_REGEX.captures(list_id_header) {
|
Ok(match LIST_ID_REGEX.captures(list_id_header) {
|
||||||
@@ -2825,8 +2825,8 @@ fn compute_mailinglist_name(
|
|||||||
// (as that part is much more visible, we assume, that names is shorter and comes more to the point,
|
// (as that part is much more visible, we assume, that names is shorter and comes more to the point,
|
||||||
// than the sometimes longer part from ListId)
|
// than the sometimes longer part from ListId)
|
||||||
let subject = mime_parser.get_subject().unwrap_or_default();
|
let subject = mime_parser.get_subject().unwrap_or_default();
|
||||||
static SUBJECT: Lazy<Regex> =
|
static SUBJECT: LazyLock<Regex> =
|
||||||
Lazy::new(|| Regex::new(r"^.{0,5}\[(.+?)\](\s*\[.+\])?").unwrap()); // remove square brackets around first name
|
LazyLock::new(|| Regex::new(r"^.{0,5}\[(.+?)\](\s*\[.+\])?").unwrap()); // remove square brackets around first name
|
||||||
if let Some(cap) = SUBJECT.captures(&subject) {
|
if let Some(cap) = SUBJECT.captures(&subject) {
|
||||||
name = cap[1].to_string() + cap.get(2).map_or("", |m| m.as_str());
|
name = cap[1].to_string() + cap.get(2).map_or("", |m| m.as_str());
|
||||||
}
|
}
|
||||||
@@ -2853,8 +2853,8 @@ fn compute_mailinglist_name(
|
|||||||
// but strip some known, long hash prefixes
|
// but strip some known, long hash prefixes
|
||||||
if name.is_empty() {
|
if name.is_empty() {
|
||||||
// 51231231231231231231231232869f58.xing.com -> xing.com
|
// 51231231231231231231231232869f58.xing.com -> xing.com
|
||||||
static PREFIX_32_CHARS_HEX: Lazy<Regex> =
|
static PREFIX_32_CHARS_HEX: LazyLock<Regex> =
|
||||||
Lazy::new(|| Regex::new(r"([0-9a-fA-F]{32})\.(.{6,})").unwrap());
|
LazyLock::new(|| Regex::new(r"([0-9a-fA-F]{32})\.(.{6,})").unwrap());
|
||||||
if let Some(cap) = PREFIX_32_CHARS_HEX
|
if let Some(cap) = PREFIX_32_CHARS_HEX
|
||||||
.captures(listid)
|
.captures(listid)
|
||||||
.and_then(|caps| caps.get(2))
|
.and_then(|caps| caps.get(2))
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
//! DC release info.
|
//! DC release info.
|
||||||
|
|
||||||
use chrono::NaiveDate;
|
use chrono::NaiveDate;
|
||||||
use once_cell::sync::Lazy;
|
use std::sync::LazyLock;
|
||||||
|
|
||||||
const DATE_STR: &str = include_str!("../release-date.in");
|
const DATE_STR: &str = include_str!("../release-date.in");
|
||||||
|
|
||||||
/// Last release date.
|
/// Last release date.
|
||||||
pub static DATE: Lazy<NaiveDate> =
|
pub static DATE: LazyLock<NaiveDate> =
|
||||||
Lazy::new(|| NaiveDate::parse_from_str(DATE_STR, "%Y-%m-%d").unwrap());
|
LazyLock::new(|| NaiveDate::parse_from_str(DATE_STR, "%Y-%m-%d").unwrap());
|
||||||
|
|||||||
@@ -6,14 +6,13 @@ use std::fmt::Write;
|
|||||||
use std::ops::{Deref, DerefMut};
|
use std::ops::{Deref, DerefMut};
|
||||||
use std::panic;
|
use std::panic;
|
||||||
use std::path::Path;
|
use std::path::Path;
|
||||||
use std::sync::Arc;
|
use std::sync::{Arc, LazyLock};
|
||||||
use std::time::{Duration, Instant};
|
use std::time::{Duration, Instant};
|
||||||
|
|
||||||
use async_channel::{self as channel, Receiver, Sender};
|
use async_channel::{self as channel, Receiver, Sender};
|
||||||
use chat::ChatItem;
|
use chat::ChatItem;
|
||||||
use deltachat_contact_tools::{ContactAddress, EmailAddress};
|
use deltachat_contact_tools::{ContactAddress, EmailAddress};
|
||||||
use nu_ansi_term::Color;
|
use nu_ansi_term::Color;
|
||||||
use once_cell::sync::Lazy;
|
|
||||||
use pretty_assertions::assert_eq;
|
use pretty_assertions::assert_eq;
|
||||||
use rand::Rng;
|
use rand::Rng;
|
||||||
use tempfile::{tempdir, TempDir};
|
use tempfile::{tempdir, TempDir};
|
||||||
@@ -47,8 +46,8 @@ use crate::tools::time;
|
|||||||
pub const AVATAR_900x900_BYTES: &[u8] = include_bytes!("../test-data/image/avatar900x900.png");
|
pub const AVATAR_900x900_BYTES: &[u8] = include_bytes!("../test-data/image/avatar900x900.png");
|
||||||
|
|
||||||
/// Map of context IDs to names for [`TestContext`]s.
|
/// Map of context IDs to names for [`TestContext`]s.
|
||||||
static CONTEXT_NAMES: Lazy<std::sync::RwLock<BTreeMap<u32, String>>> =
|
static CONTEXT_NAMES: LazyLock<std::sync::RwLock<BTreeMap<u32, String>>> =
|
||||||
Lazy::new(|| std::sync::RwLock::new(BTreeMap::new()));
|
LazyLock::new(|| std::sync::RwLock::new(BTreeMap::new()));
|
||||||
|
|
||||||
/// Manage multiple [`TestContext`]s in one place.
|
/// Manage multiple [`TestContext`]s in one place.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user