mirror of
https://github.com/chatmail/core.git
synced 2026-04-27 02:16:29 +03:00
Strongly type stock strings
This changes the internal stock strings API to be more strongly typed, ensuring that the caller can not construct the stock string in the wrong way. The old approach left it to the callers to figure out how a stock string should be created, now each stock string has their specific arguments and callers can not make mistakes. In particular all the subtleties and different ways of calling stock_system_msg() disappear. This could not use a trait for stock strings, as this would not allow having per-message typed arguments. So we needed a type per message with a custom method, only by convention this method is .stock_str(). The type is a enum without variants to avoid allowing someone to create the type. Sadly the fallback string and substitutions are still far away from each other, but it is now only one place which needs to know how to construct the string instead of many.
This commit is contained in:
@@ -3,10 +3,12 @@ use std::future::Future;
|
||||
use std::pin::Pin;
|
||||
|
||||
use anyhow::{bail, Result};
|
||||
use charset::Charset;
|
||||
use deltachat_derive::{FromSql, ToSql};
|
||||
use lettre_email::mime::{self, Mime};
|
||||
use mailparse::{addrparse_header, DispositionType, MailHeader, MailHeaderMap, SingleInfo};
|
||||
use once_cell::sync::Lazy;
|
||||
use percent_encoding::percent_decode_str;
|
||||
|
||||
use crate::aheader::Aheader;
|
||||
use crate::blob::BlobObject;
|
||||
@@ -25,9 +27,7 @@ use crate::message;
|
||||
use crate::param::{Param, Params};
|
||||
use crate::peerstate::Peerstate;
|
||||
use crate::simplify::simplify;
|
||||
use crate::stock::StockMessage;
|
||||
use charset::Charset;
|
||||
use percent_encoding::percent_decode_str;
|
||||
use crate::stock::CantDecryptMsgBody;
|
||||
|
||||
/// A parsed MIME message.
|
||||
///
|
||||
@@ -629,7 +629,7 @@ impl MimeMessage {
|
||||
// we currently do not try to decrypt non-autocrypt messages
|
||||
// at all. If we see an encrypted part, we set
|
||||
// decrypting_failed.
|
||||
let msg_body = context.stock_str(StockMessage::CantDecryptMsgBody).await;
|
||||
let msg_body = CantDecryptMsgBody::stock_str(context).await;
|
||||
let txt = format!("[{}]", msg_body);
|
||||
|
||||
let part = Part {
|
||||
|
||||
Reference in New Issue
Block a user