Skip to content

Commit 4bc9070

Browse files
Septiasr10s
andauthored
feat: Add system message when provider does not allow unencrypted messages (#5161) (#5195)
close #5161 ![Screenshot from 2024-01-19 19-56-09](https://github.com/deltachat/deltachat-core-rust/assets/39526136/27ecdd9b-1739-410b-bb26-80d5bdbbc39a) --------- Co-authored-by: bjoern <r10s@b44t.com>
1 parent 490deb9 commit 4bc9070

File tree

4 files changed

+60
-1
lines changed

4 files changed

+60
-1
lines changed

deltachat-jsonrpc/src/api/types/message.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ pub enum SystemMessageType {
345345
SecurejoinMessage,
346346
LocationStreamingEnabled,
347347
LocationOnly,
348+
InvalidUnencryptedMail,
348349

349350
/// Chat ephemeral message timer is changed.
350351
EphemeralTimerChanged,
@@ -385,6 +386,7 @@ impl From<deltachat::mimeparser::SystemMessage> for SystemMessageType {
385386
SystemMessage::MultiDeviceSync => SystemMessageType::MultiDeviceSync,
386387
SystemMessage::WebxdcStatusUpdate => SystemMessageType::WebxdcStatusUpdate,
387388
SystemMessage::WebxdcInfoMessage => SystemMessageType::WebxdcInfoMessage,
389+
SystemMessage::InvalidUnencryptedMail => SystemMessageType::InvalidUnencryptedMail,
388390
}
389391
}
390392
}

src/mimeparser.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,10 @@ pub enum SystemMessage {
176176
/// "%1$s sent a message from another device."
177177
ChatProtectionDisabled = 12,
178178

179+
/// Message can't be sent because of `Invalid unencrypted mail to <>`
180+
/// which is sent by chatmail servers.
181+
InvalidUnencryptedMail = 13,
182+
179183
/// Self-sent-message that contains only json used for multi-device-sync;
180184
/// if possible, we attach that to other messages as for locations.
181185
MultiDeviceSync = 20,

src/smtp.rs

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ use async_smtp::{self as smtp, EmailAddress, SmtpTransport};
1010
use tokio::io::BufStream;
1111
use tokio::task;
1212

13+
use crate::chat::{add_info_msg_with_cmd, ChatId};
1314
use crate::config::Config;
1415
use crate::contact::{Contact, ContactId};
1516
use crate::context::Context;
@@ -26,6 +27,7 @@ use crate::provider::Socket;
2627
use crate::scheduler::connectivity::ConnectivityStore;
2728
use crate::socks::Socks5Config;
2829
use crate::sql;
30+
use crate::stock_str::unencrypted_email;
2931

3032
/// SMTP connection, write and read timeout.
3133
const SMTP_TIMEOUT: Duration = Duration::from_secs(60);
@@ -584,7 +586,46 @@ pub(crate) async fn send_msg_to_smtp(
584586

585587
match status {
586588
SendResult::Retry => {}
587-
SendResult::Success | SendResult::Failure(_) => {
589+
SendResult::Success => {
590+
context
591+
.sql
592+
.execute("DELETE FROM smtp WHERE id=?", (rowid,))
593+
.await?;
594+
}
595+
SendResult::Failure(ref err) => {
596+
if err.to_string().contains("Invalid unencrypted mail") {
597+
let res = context
598+
.sql
599+
.query_row_optional(
600+
"SELECT chat_id, timestamp FROM msgs WHERE id=?;",
601+
(msg_id,),
602+
|row| Ok((row.get::<_, ChatId>(0)?, row.get::<_, i64>(1)?)),
603+
)
604+
.await?;
605+
606+
if let Some((chat_id, timestamp_sort)) = res {
607+
let addr = context.get_config(Config::ConfiguredAddr).await?;
608+
let text = unencrypted_email(
609+
context,
610+
addr.unwrap_or_default()
611+
.split('@')
612+
.nth(1)
613+
.unwrap_or_default(),
614+
)
615+
.await;
616+
add_info_msg_with_cmd(
617+
context,
618+
chat_id,
619+
&text,
620+
crate::mimeparser::SystemMessage::InvalidUnencryptedMail,
621+
timestamp_sort,
622+
None,
623+
None,
624+
None,
625+
)
626+
.await?;
627+
};
628+
}
588629
context
589630
.sql
590631
.execute("DELETE FROM smtp WHERE id=?", (rowid,))

src/stock_str.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -419,6 +419,11 @@ pub enum StockMessage {
419419

420420
#[strum(props(fallback = "Member %1$s added."))]
421421
MsgAddMember = 173,
422+
423+
#[strum(props(
424+
fallback = "⚠️ Your email provider %1$s requires end-to-end encryption which is not setup yet."
425+
))]
426+
InvalidUnencryptedMail = 174,
422427
}
423428

424429
impl StockMessage {
@@ -1285,6 +1290,13 @@ pub(crate) async fn aeap_addr_changed(
12851290
.replace3(new_addr)
12861291
}
12871292

1293+
/// Stock string: `⚠️ Your email provider %1$s requires end-to-end encryption which is not setup yet. Tap to learn more.`.
1294+
pub(crate) async fn unencrypted_email(context: &Context, provider: &str) -> String {
1295+
translated(context, StockMessage::InvalidUnencryptedMail)
1296+
.await
1297+
.replace1(provider)
1298+
}
1299+
12881300
pub(crate) async fn aeap_explanation_and_link(
12891301
context: &Context,
12901302
old_addr: &str,

0 commit comments

Comments
 (0)