mirror of
https://github.com/chatmail/core.git
synced 2026-08-14 12:59:36 +03:00
refactor: use the new regex! macro
It was introduced in regex crate 1.13.0
This commit is contained in:
@@ -29,11 +29,10 @@
|
||||
|
||||
use std::fmt;
|
||||
use std::ops::Deref;
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use anyhow::bail;
|
||||
use anyhow::Result;
|
||||
use regex::Regex;
|
||||
use regex::regex;
|
||||
|
||||
mod vcard;
|
||||
pub use vcard::{make_vcard, parse_vcard, VcardContact};
|
||||
@@ -88,9 +87,7 @@ impl rusqlite::types::ToSql for ContactAddress {
|
||||
/// - Removes special characters from the name, see [`sanitize_name()`]
|
||||
/// - 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) {
|
||||
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) = regex!("(.*)<(.*)>").captures(addr.as_ref()) {
|
||||
(
|
||||
if name.is_empty() {
|
||||
captures.get(1).map_or("", |m| m.as_str())
|
||||
|
||||
@@ -1,10 +1,8 @@
|
||||
use std::sync::LazyLock;
|
||||
|
||||
use anyhow::Context as _;
|
||||
use anyhow::Result;
|
||||
use chrono::DateTime;
|
||||
use chrono::NaiveDateTime;
|
||||
use regex::Regex;
|
||||
use regex::regex;
|
||||
|
||||
use crate::sanitize_name_and_addr;
|
||||
|
||||
@@ -210,9 +208,7 @@ pub fn parse_vcard(vcard: &str) -> Vec<VcardContact> {
|
||||
}
|
||||
|
||||
// Remove line folding, see https://datatracker.ietf.org/doc/html/rfc6350#section-3.2
|
||||
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 = regex!("\r?\n[\t ]").replace_all(vcard, "");
|
||||
|
||||
let mut lines = unfolded_lines.lines().peekable();
|
||||
let mut contacts = Vec::new();
|
||||
|
||||
@@ -12,7 +12,7 @@ use deltachat_contact_tools::{
|
||||
sanitize_single_line,
|
||||
};
|
||||
use mailparse::SingleInfo;
|
||||
use regex::Regex;
|
||||
use regex::{Regex, regex};
|
||||
|
||||
use crate::chat::{
|
||||
self, Chat, ChatId, ChatIdBlocked, ChatVisibility, is_contact_in_chat, save_broadcast_secret,
|
||||
@@ -3636,9 +3636,8 @@ fn compute_mailinglist_name(
|
||||
// (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)
|
||||
let subject = mime_parser.get_subject().unwrap_or_default();
|
||||
static SUBJECT: LazyLock<Regex> =
|
||||
LazyLock::new(|| Regex::new(r"^.{0,5}\[(.+?)\](\s*\[.+\])?").unwrap()); // remove square brackets around first name
|
||||
if let Some(cap) = SUBJECT.captures(&subject) {
|
||||
let subject_re: &Regex = regex!(r"^.{0,5}\[(.+?)\](\s*\[.+\])?"); // remove square brackets around first name
|
||||
if let Some(cap) = subject_re.captures(&subject) {
|
||||
name = cap[1].to_string() + cap.get(2).map_or("", |m| m.as_str());
|
||||
}
|
||||
|
||||
@@ -3663,9 +3662,8 @@ fn compute_mailinglist_name(
|
||||
// but strip some known, long hash prefixes
|
||||
if name.is_empty() {
|
||||
// 51231231231231231231231232869f58.xing.com -> xing.com
|
||||
static PREFIX_32_CHARS_HEX: LazyLock<Regex> =
|
||||
LazyLock::new(|| Regex::new(r"([0-9a-fA-F]{32})\.(.{6,})").unwrap());
|
||||
if let Some(cap) = PREFIX_32_CHARS_HEX
|
||||
let prefix_32_chars_hex: &Regex = regex!(r"([0-9a-fA-F]{32})\.(.{6,})");
|
||||
if let Some(cap) = prefix_32_chars_hex
|
||||
.captures(listid)
|
||||
.and_then(|caps| caps.get(2))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user