mirror of
https://github.com/chatmail/core.git
synced 2026-05-08 01:16:31 +03:00
Switch from lazy_static to once_cell
This commit is contained in:
committed by
link2xt
parent
bf72ae4ccc
commit
67cddedf7e
2
Cargo.lock
generated
2
Cargo.lock
generated
@@ -1033,7 +1033,6 @@ dependencies = [
|
|||||||
"indexmap",
|
"indexmap",
|
||||||
"itertools",
|
"itertools",
|
||||||
"kamadak-exif",
|
"kamadak-exif",
|
||||||
"lazy_static",
|
|
||||||
"lettre_email",
|
"lettre_email",
|
||||||
"libc",
|
"libc",
|
||||||
"log",
|
"log",
|
||||||
@@ -1041,6 +1040,7 @@ dependencies = [
|
|||||||
"native-tls",
|
"native-tls",
|
||||||
"num-derive",
|
"num-derive",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
|
"once_cell",
|
||||||
"percent-encoding",
|
"percent-encoding",
|
||||||
"pgp",
|
"pgp",
|
||||||
"pretty_assertions",
|
"pretty_assertions",
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ serde_json = "1.0"
|
|||||||
chrono = "0.4.6"
|
chrono = "0.4.6"
|
||||||
indexmap = "1.3.0"
|
indexmap = "1.3.0"
|
||||||
kamadak-exif = "0.5"
|
kamadak-exif = "0.5"
|
||||||
lazy_static = "1.4.0"
|
once_cell = "1.4.1"
|
||||||
regex = "1.1.6"
|
regex = "1.1.6"
|
||||||
rusqlite = { version = "0.24", features = ["bundled"] }
|
rusqlite = { version = "0.24", features = ["bundled"] }
|
||||||
r2d2_sqlite = "0.17.0"
|
r2d2_sqlite = "0.17.0"
|
||||||
|
|||||||
@@ -1,11 +1,9 @@
|
|||||||
//! # Constants
|
//! # Constants
|
||||||
use deltachat_derive::*;
|
use deltachat_derive::*;
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
lazy_static! {
|
pub static DC_VERSION_STR: Lazy<String> = Lazy::new(|| env!("CARGO_PKG_VERSION").to_string());
|
||||||
pub static ref DC_VERSION_STR: String = env!("CARGO_PKG_VERSION").to_string();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(
|
#[derive(
|
||||||
Debug,
|
Debug,
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
use async_std::path::PathBuf;
|
use async_std::path::PathBuf;
|
||||||
use deltachat_derive::*;
|
use deltachat_derive::*;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
use regex::Regex;
|
use regex::Regex;
|
||||||
|
|
||||||
use crate::aheader::EncryptPreference;
|
use crate::aheader::EncryptPreference;
|
||||||
@@ -1053,9 +1053,7 @@ pub fn addr_normalize(addr: &str) -> &str {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn sanitize_name_and_addr(name: impl AsRef<str>, addr: impl AsRef<str>) -> (String, String) {
|
fn sanitize_name_and_addr(name: impl AsRef<str>, addr: impl AsRef<str>) -> (String, String) {
|
||||||
lazy_static! {
|
static ADDR_WITH_NAME_REGEX: Lazy<Regex> = Lazy::new(|| Regex::new("(.*)<(.*)>").unwrap());
|
||||||
static ref ADDR_WITH_NAME_REGEX: Regex = Regex::new("(.*)<(.*)>").unwrap();
|
|
||||||
}
|
|
||||||
if let Some(captures) = ADDR_WITH_NAME_REGEX.captures(addr.as_ref()) {
|
if let Some(captures) = ADDR_WITH_NAME_REGEX.captures(addr.as_ref()) {
|
||||||
(
|
(
|
||||||
if name.as_ref().is_empty() {
|
if name.as_ref().is_empty() {
|
||||||
|
|||||||
@@ -2,12 +2,10 @@
|
|||||||
//!
|
//!
|
||||||
//! A module to remove HTML tags from the email text
|
//! A module to remove HTML tags from the email text
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
|
use quick_xml::events::{BytesEnd, BytesStart, BytesText};
|
||||||
|
|
||||||
lazy_static! {
|
static LINE_RE: Lazy<regex::Regex> = Lazy::new(|| regex::Regex::new(r"(\r?\n)+").unwrap());
|
||||||
static ref LINE_RE: regex::Regex = regex::Regex::new(r"(\r?\n)+").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
struct Dehtml {
|
struct Dehtml {
|
||||||
strbuilder: String,
|
strbuilder: String,
|
||||||
|
|||||||
@@ -431,11 +431,9 @@ mod tests {
|
|||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
|
|
||||||
use async_std::sync::Arc;
|
use async_std::sync::Arc;
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
lazy_static! {
|
static KEYPAIR: Lazy<KeyPair> = Lazy::new(alice_keypair);
|
||||||
static ref KEYPAIR: KeyPair = alice_keypair();
|
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_from_armored_string() {
|
fn test_from_armored_string() {
|
||||||
|
|||||||
@@ -3,9 +3,9 @@ use std::future::Future;
|
|||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
use deltachat_derive::{FromSql, ToSql};
|
use deltachat_derive::{FromSql, ToSql};
|
||||||
use lazy_static::lazy_static;
|
|
||||||
use lettre_email::mime::{self, Mime};
|
use lettre_email::mime::{self, Mime};
|
||||||
use mailparse::{addrparse_header, DispositionType, MailHeader, MailHeaderMap, SingleInfo};
|
use mailparse::{addrparse_header, DispositionType, MailHeader, MailHeaderMap, SingleInfo};
|
||||||
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
use crate::aheader::Aheader;
|
use crate::aheader::Aheader;
|
||||||
use crate::blob::BlobObject;
|
use crate::blob::BlobObject;
|
||||||
@@ -1004,9 +1004,8 @@ impl MimeMessage {
|
|||||||
false
|
false
|
||||||
};
|
};
|
||||||
if maybe_ndn && self.failure_report.is_none() {
|
if maybe_ndn && self.failure_report.is_none() {
|
||||||
lazy_static! {
|
static RE: Lazy<regex::Regex> =
|
||||||
static ref RE: regex::Regex = regex::Regex::new(r"Message-ID:(.*)").unwrap();
|
Lazy::new(|| regex::Regex::new(r"Message-ID:(.*)").unwrap());
|
||||||
}
|
|
||||||
for captures in self
|
for captures in self
|
||||||
.parts
|
.parts
|
||||||
.iter()
|
.iter()
|
||||||
|
|||||||
41
src/pgp.rs
41
src/pgp.rs
@@ -381,7 +381,7 @@ pub async fn symm_decrypt<T: std::io::Read + std::io::Seek>(
|
|||||||
mod tests {
|
mod tests {
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::test_utils::*;
|
use crate::test_utils::*;
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_split_armored_data_1() {
|
fn test_split_armored_data_1() {
|
||||||
@@ -449,26 +449,29 @@ mod tests {
|
|||||||
/// The original text of [CTEXT_SIGNED]
|
/// The original text of [CTEXT_SIGNED]
|
||||||
static CLEARTEXT: &[u8] = b"This is a test";
|
static CLEARTEXT: &[u8] = b"This is a test";
|
||||||
|
|
||||||
lazy_static! {
|
/// Initialised [TestKeys] for tests.
|
||||||
/// Initialised [TestKeys] for tests.
|
static KEYS: Lazy<TestKeys> = Lazy::new(TestKeys::new);
|
||||||
static ref KEYS: TestKeys = TestKeys::new();
|
|
||||||
|
|
||||||
/// A cyphertext encrypted to Alice & Bob, signed by Alice.
|
/// A cyphertext encrypted to Alice & Bob, signed by Alice.
|
||||||
static ref CTEXT_SIGNED: String = {
|
static CTEXT_SIGNED: Lazy<String> = Lazy::new(|| {
|
||||||
let mut keyring = Keyring::new();
|
let mut keyring = Keyring::new();
|
||||||
keyring.add(KEYS.alice_public.clone());
|
keyring.add(KEYS.alice_public.clone());
|
||||||
keyring.add(KEYS.bob_public.clone());
|
keyring.add(KEYS.bob_public.clone());
|
||||||
futures_lite::future::block_on(pk_encrypt(CLEARTEXT, keyring, Some(KEYS.alice_secret.clone()))).unwrap()
|
futures_lite::future::block_on(pk_encrypt(
|
||||||
};
|
CLEARTEXT,
|
||||||
|
keyring,
|
||||||
|
Some(KEYS.alice_secret.clone()),
|
||||||
|
))
|
||||||
|
.unwrap()
|
||||||
|
});
|
||||||
|
|
||||||
/// A cyphertext encrypted to Alice & Bob, not signed.
|
/// A cyphertext encrypted to Alice & Bob, not signed.
|
||||||
static ref CTEXT_UNSIGNED: String = {
|
static CTEXT_UNSIGNED: Lazy<String> = Lazy::new(|| {
|
||||||
let mut keyring = Keyring::new();
|
let mut keyring = Keyring::new();
|
||||||
keyring.add(KEYS.alice_public.clone());
|
keyring.add(KEYS.alice_public.clone());
|
||||||
keyring.add(KEYS.bob_public.clone());
|
keyring.add(KEYS.bob_public.clone());
|
||||||
futures_lite::future::block_on(pk_encrypt(CLEARTEXT, keyring, None)).unwrap()
|
futures_lite::future::block_on(pk_encrypt(CLEARTEXT, keyring, None)).unwrap()
|
||||||
};
|
});
|
||||||
}
|
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_encrypt_signed() {
|
fn test_encrypt_signed() {
|
||||||
|
|||||||
1507
src/provider/data.rs
1507
src/provider/data.rs
File diff suppressed because it is too large
Load Diff
@@ -42,8 +42,8 @@ def process_config_defaults(data):
|
|||||||
config_defaults = data.get("config_defaults", "")
|
config_defaults = data.get("config_defaults", "")
|
||||||
for key in config_defaults:
|
for key in config_defaults:
|
||||||
value = str(config_defaults[key])
|
value = str(config_defaults[key])
|
||||||
defaults += " ConfigDefault { key: Config::" + camel(key) + ", value: \"" + value + "\" },\n"
|
defaults += " ConfigDefault { key: Config::" + camel(key) + ", value: \"" + value + "\" },\n"
|
||||||
defaults += " ])"
|
defaults += " ])"
|
||||||
return defaults
|
return defaults
|
||||||
|
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ def process_data(data, file):
|
|||||||
raise TypeError("domain used twice: " + domain)
|
raise TypeError("domain used twice: " + domain)
|
||||||
domains_dict[domain] = True
|
domains_dict[domain] = True
|
||||||
|
|
||||||
domains += " (\"" + domain + "\", &*" + file2varname(file) + "),\n"
|
domains += " (\"" + domain + "\", &*" + file2varname(file) + "),\n"
|
||||||
comment += domain + ", "
|
comment += domain + ", "
|
||||||
|
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ def process_data(data, file):
|
|||||||
if username_pattern != "EMAIL" and username_pattern != "EMAILLOCALPART":
|
if username_pattern != "EMAIL" and username_pattern != "EMAILLOCALPART":
|
||||||
raise TypeError("bad username pattern")
|
raise TypeError("bad username pattern")
|
||||||
|
|
||||||
server += (" Server { protocol: " + protocol + ", socket: " + socket + ", hostname: \""
|
server += (" Server { protocol: " + protocol + ", socket: " + socket + ", hostname: \""
|
||||||
+ hostname + "\", port: " + str(port) + ", username_pattern: " + username_pattern + " },\n")
|
+ hostname + "\", port: " + str(port) + ", username_pattern: " + username_pattern + " },\n")
|
||||||
|
|
||||||
config_defaults = process_config_defaults(data)
|
config_defaults = process_config_defaults(data)
|
||||||
@@ -111,16 +111,16 @@ def process_data(data, file):
|
|||||||
before_login_hint = cleanstr(data.get("before_login_hint", ""))
|
before_login_hint = cleanstr(data.get("before_login_hint", ""))
|
||||||
after_login_hint = cleanstr(data.get("after_login_hint", ""))
|
after_login_hint = cleanstr(data.get("after_login_hint", ""))
|
||||||
if (not has_imap and not has_smtp) or (has_imap and has_smtp):
|
if (not has_imap and not has_smtp) or (has_imap and has_smtp):
|
||||||
provider += " static ref " + file2varname(file) + ": Provider = Provider {\n"
|
provider += "static " + file2varname(file) + ": Lazy<Provider> = Lazy::new(|| Provider {\n"
|
||||||
provider += " status: Status::" + status + ",\n"
|
provider += " status: Status::" + status + ",\n"
|
||||||
provider += " before_login_hint: \"" + before_login_hint + "\",\n"
|
provider += " before_login_hint: \"" + before_login_hint + "\",\n"
|
||||||
provider += " after_login_hint: \"" + after_login_hint + "\",\n"
|
provider += " after_login_hint: \"" + after_login_hint + "\",\n"
|
||||||
provider += " overview_page: \"" + file2url(file) + "\",\n"
|
provider += " overview_page: \"" + file2url(file) + "\",\n"
|
||||||
provider += " server: vec![\n" + server + " ],\n"
|
provider += " server: vec![\n" + server + " ],\n"
|
||||||
provider += " config_defaults: " + config_defaults + ",\n"
|
provider += " config_defaults: " + config_defaults + ",\n"
|
||||||
provider += " strict_tls: " + strict_tls + ",\n"
|
provider += " strict_tls: " + strict_tls + ",\n"
|
||||||
provider += " oauth2_authorizer: " + oauth2 + ",\n"
|
provider += " oauth2_authorizer: " + oauth2 + ",\n"
|
||||||
provider += " };\n\n"
|
provider += "});\n\n"
|
||||||
else:
|
else:
|
||||||
raise TypeError("SMTP and IMAP must be specified together or left out both")
|
raise TypeError("SMTP and IMAP must be specified together or left out both")
|
||||||
|
|
||||||
@@ -129,7 +129,7 @@ def process_data(data, file):
|
|||||||
|
|
||||||
# finally, add the provider
|
# finally, add the provider
|
||||||
global out_all, out_domains
|
global out_all, out_domains
|
||||||
out_all += " // " + file[file.rindex("/")+1:] + ": " + comment.strip(", ") + "\n"
|
out_all += "// " + file[file.rindex("/")+1:] + ": " + comment.strip(", ") + "\n"
|
||||||
|
|
||||||
# also add provider with no special things to do -
|
# also add provider with no special things to do -
|
||||||
# eg. _not_ supporting oauth2 is also an information and we can skip the mx-lookup in this case
|
# eg. _not_ supporting oauth2 is also an information and we can skip the mx-lookup in this case
|
||||||
@@ -164,18 +164,16 @@ if __name__ == "__main__":
|
|||||||
"use crate::provider::UsernamePattern::*;\n"
|
"use crate::provider::UsernamePattern::*;\n"
|
||||||
"use crate::provider::*;\n"
|
"use crate::provider::*;\n"
|
||||||
"use std::collections::HashMap;\n\n"
|
"use std::collections::HashMap;\n\n"
|
||||||
"lazy_static::lazy_static! {\n\n")
|
"use once_cell::sync::Lazy;\n\n")
|
||||||
|
|
||||||
process_dir(sys.argv[1])
|
process_dir(sys.argv[1])
|
||||||
|
|
||||||
out_all += " pub static ref PROVIDER_DATA: HashMap<&'static str, &'static Provider> = [\n"
|
out_all += "pub static PROVIDER_DATA: Lazy<HashMap<&'static str, &'static Provider>> = Lazy::new(|| [\n"
|
||||||
out_all += out_domains;
|
out_all += out_domains;
|
||||||
out_all += " ].iter().copied().collect();\n\n"
|
out_all += "].iter().copied().collect());\n\n"
|
||||||
|
|
||||||
now = datetime.datetime.utcnow()
|
now = datetime.datetime.utcnow()
|
||||||
out_all += " pub static ref PROVIDER_UPDATED: chrono::NaiveDate = "\
|
out_all += "pub static PROVIDER_UPDATED: Lazy<chrono::NaiveDate> = "\
|
||||||
"chrono::NaiveDate::from_ymd("+str(now.year)+", "+str(now.month)+", "+str(now.day)+");\n"
|
"Lazy::new(|| chrono::NaiveDate::from_ymd("+str(now.year)+", "+str(now.month)+", "+str(now.day)+"));\n"
|
||||||
|
|
||||||
out_all += "}"
|
|
||||||
|
|
||||||
print(out_all)
|
print(out_all)
|
||||||
|
|||||||
12
src/qr.rs
12
src/qr.rs
@@ -1,6 +1,6 @@
|
|||||||
//! # QR code module
|
//! # QR code module
|
||||||
|
|
||||||
use lazy_static::lazy_static;
|
use once_cell::sync::Lazy;
|
||||||
use percent_encoding::percent_decode_str;
|
use percent_encoding::percent_decode_str;
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
|
|
||||||
@@ -358,12 +358,10 @@ async fn decode_matmsg(context: &Context, qr: &str) -> Lot {
|
|||||||
Lot::from_address(context, name, addr).await
|
Lot::from_address(context, name, addr).await
|
||||||
}
|
}
|
||||||
|
|
||||||
lazy_static! {
|
static VCARD_NAME_RE: Lazy<regex::Regex> =
|
||||||
static ref VCARD_NAME_RE: regex::Regex =
|
Lazy::new(|| regex::Regex::new(r"(?m)^N:([^;]*);([^;\n]*)").unwrap());
|
||||||
regex::Regex::new(r"(?m)^N:([^;]*);([^;\n]*)").unwrap();
|
static VCARD_EMAIL_RE: Lazy<regex::Regex> =
|
||||||
static ref VCARD_EMAIL_RE: regex::Regex =
|
Lazy::new(|| regex::Regex::new(r"(?m)^EMAIL([^:\n]*):([^;\n]*)").unwrap());
|
||||||
regex::Regex::new(r"(?m)^EMAIL([^:\n]*):([^;\n]*)").unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Extract address for the matmsg scheme.
|
/// Extract address for the matmsg scheme.
|
||||||
///
|
///
|
||||||
|
|||||||
Reference in New Issue
Block a user