mirror of
https://github.com/chatmail/core.git
synced 2026-05-15 04:46:38 +03:00
Repair errors saved for messages
This commit is contained in:
@@ -2328,6 +2328,7 @@ mod tests {
|
|||||||
#[async_std::test]
|
#[async_std::test]
|
||||||
async fn test_parse_ndn() {
|
async fn test_parse_ndn() {
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
|
use std::{thread, time};
|
||||||
|
|
||||||
let t = dummy_context().await;
|
let t = dummy_context().await;
|
||||||
t.ctx
|
t.ctx
|
||||||
@@ -2369,25 +2370,17 @@ mod tests {
|
|||||||
.await
|
.await
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
|
thread::sleep(time::Duration::from_millis(1000));
|
||||||
|
|
||||||
println!("Loading msg {}…", msg_id);
|
println!("Loading msg {}…", msg_id);
|
||||||
let msg = Message::load_from_db(&t.ctx, msg_id).await.unwrap();
|
let msg = Message::load_from_db(&t.ctx, msg_id).await.unwrap();
|
||||||
std::io::stdout().flush().unwrap();
|
std::io::stdout().flush().unwrap();
|
||||||
|
thread::sleep(time::Duration::from_millis(1000));
|
||||||
|
|
||||||
assert_eq!(msg.state, MessageState::OutFailed);
|
assert_eq!(msg.state, MessageState::OutFailed);
|
||||||
assert_eq!(
|
assert_eq!(
|
||||||
msg.param.get(Param::Error),
|
msg.error.as_ref().map(|s| s.as_str()),
|
||||||
Some(
|
Some("Delivery Status Notification (Failure) – ** Die Adresse wurde nicht gefunden **\n\nIhre Nachricht wurde nicht an assidhfaaspocwaeofi@gmail.com zugestellt, weil die Adresse nicht gefunden wurde oder keine E-Mails empfangen kann.\n\nHier erfahren Sie mehr: https://support.google.com/mail/?p=NoSuchUser\n\nAntwort:\n\n550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient\'s email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/?p=NoSuchUser i18sor6261697wrs.38 - gsmtp")
|
||||||
r"** Die Adresse wurde nicht gefunden **
|
|
||||||
|
|
||||||
Ihre Nachricht wurde nicht an assidhfaaspocwaeofi@gmail.com zugestellt, weil die Adresse nicht gefunden wurde oder keine E-Mails empfangen kann.
|
|
||||||
|
|
||||||
Hier erfahren Sie mehr: https://support.google.com/mail/?p=NoSuchUser
|
|
||||||
|
|
||||||
Antwort:
|
|
||||||
|
|
||||||
550 5.1.1 The email account that you tried to reach does not exist. Please try double-checking the recipient's email address for typos or unnecessary spaces. Learn more at https://support.google.com/mail/?p=NoSuchUser i18sor6261697wrs.38 - gsmtp
|
|
||||||
"
|
|
||||||
)
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -255,6 +255,7 @@ pub struct Message {
|
|||||||
pub(crate) starred: bool,
|
pub(crate) starred: bool,
|
||||||
pub(crate) chat_blocked: Blocked,
|
pub(crate) chat_blocked: Blocked,
|
||||||
pub(crate) location_id: u32,
|
pub(crate) location_id: u32,
|
||||||
|
pub(crate) error: Option<String>,
|
||||||
pub(crate) param: Params,
|
pub(crate) param: Params,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -289,6 +290,7 @@ impl Message {
|
|||||||
" m.timestamp_rcvd AS timestamp_rcvd,",
|
" m.timestamp_rcvd AS timestamp_rcvd,",
|
||||||
" m.type AS type,",
|
" m.type AS type,",
|
||||||
" m.state AS state,",
|
" m.state AS state,",
|
||||||
|
" m.error AS error,",
|
||||||
" m.msgrmsg AS msgrmsg,",
|
" m.msgrmsg AS msgrmsg,",
|
||||||
" m.txt AS txt,",
|
" m.txt AS txt,",
|
||||||
" m.param AS param,",
|
" m.param AS param,",
|
||||||
@@ -316,6 +318,7 @@ impl Message {
|
|||||||
msg.timestamp_rcvd = row.get("timestamp_rcvd")?;
|
msg.timestamp_rcvd = row.get("timestamp_rcvd")?;
|
||||||
msg.viewtype = row.get("type")?;
|
msg.viewtype = row.get("type")?;
|
||||||
msg.state = row.get("state")?;
|
msg.state = row.get("state")?;
|
||||||
|
msg.error = row.get("error")?;
|
||||||
msg.is_dc_message = row.get("msgrmsg")?;
|
msg.is_dc_message = row.get("msgrmsg")?;
|
||||||
|
|
||||||
let text;
|
let text;
|
||||||
@@ -937,7 +940,7 @@ pub async fn get_msg_info(context: &Context, msg_id: MsgId) -> String {
|
|||||||
}
|
}
|
||||||
|
|
||||||
ret += "\n";
|
ret += "\n";
|
||||||
if let Some(err) = msg.param.get(Param::Error) {
|
if let Some(err) = &msg.error {
|
||||||
ret += &format!("Error: {}", err)
|
ret += &format!("Error: {}", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1251,27 +1254,33 @@ pub async fn exists(context: &Context, msg_id: MsgId) -> bool {
|
|||||||
|
|
||||||
pub async fn set_msg_failed(context: &Context, msg_id: MsgId, error: Option<impl AsRef<str>>) {
|
pub async fn set_msg_failed(context: &Context, msg_id: MsgId, error: Option<impl AsRef<str>>) {
|
||||||
if let Ok(mut msg) = Message::load_from_db(context, msg_id).await {
|
if let Ok(mut msg) = Message::load_from_db(context, msg_id).await {
|
||||||
|
let error = error.map(|e| e.as_ref().to_string()).unwrap_or_default();
|
||||||
if msg.state.can_fail() {
|
if msg.state.can_fail() {
|
||||||
msg.state = MessageState::OutFailed;
|
msg.state = MessageState::OutFailed;
|
||||||
}
|
warn!(context, "{} failed: {}", msg_id, error);
|
||||||
if let Some(error) = error {
|
} else {
|
||||||
msg.param.set(Param::Error, error.as_ref());
|
warn!(
|
||||||
warn!(context, "{} failed: {}", msg_id, error.as_ref());
|
context,
|
||||||
|
"{} seems to have failed ({}), but state is {}", msg_id, error, msg.state
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
if context
|
match context
|
||||||
.sql
|
.sql
|
||||||
.execute(
|
.execute(
|
||||||
"UPDATE msgs SET state=?, param=? WHERE id=?;",
|
"UPDATE msgs SET state=?, error=? WHERE id=?;",
|
||||||
paramsv![msg.state, msg.param.to_string(), msg_id],
|
paramsv![msg.state, error, msg_id],
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
.is_ok()
|
|
||||||
{
|
{
|
||||||
context.emit_event(Event::MsgFailed {
|
Ok(_) => context.emit_event(Event::MsgFailed {
|
||||||
chat_id: msg.chat_id,
|
chat_id: msg.chat_id,
|
||||||
msg_id,
|
msg_id,
|
||||||
});
|
}),
|
||||||
|
Err(e) => {
|
||||||
|
error!(context, "{:?}", e);
|
||||||
|
println!("{:?}", e)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,9 +65,6 @@ pub enum Param {
|
|||||||
/// For Messages
|
/// For Messages
|
||||||
Arg4 = b'H',
|
Arg4 = b'H',
|
||||||
|
|
||||||
/// For Messages
|
|
||||||
Error = b'L',
|
|
||||||
|
|
||||||
/// For Messages
|
/// For Messages
|
||||||
AttachGroupImage = b'A',
|
AttachGroupImage = b'A',
|
||||||
|
|
||||||
|
|||||||
10
src/sql.rs
10
src/sql.rs
@@ -779,6 +779,7 @@ async fn open(
|
|||||||
timestamp INTEGER DEFAULT 0, \
|
timestamp INTEGER DEFAULT 0, \
|
||||||
type INTEGER DEFAULT 0, \
|
type INTEGER DEFAULT 0, \
|
||||||
state INTEGER DEFAULT 0, \
|
state INTEGER DEFAULT 0, \
|
||||||
|
error TEXT DEFAULT '', \
|
||||||
msgrmsg INTEGER DEFAULT 1, \
|
msgrmsg INTEGER DEFAULT 1, \
|
||||||
bytes INTEGER DEFAULT 0, \
|
bytes INTEGER DEFAULT 0, \
|
||||||
txt TEXT DEFAULT '', \
|
txt TEXT DEFAULT '', \
|
||||||
@@ -1241,6 +1242,15 @@ async fn open(
|
|||||||
.await?;
|
.await?;
|
||||||
sql.set_raw_config_int(context, "dbversion", 63).await?;
|
sql.set_raw_config_int(context, "dbversion", 63).await?;
|
||||||
}
|
}
|
||||||
|
if dbversion < 64 {
|
||||||
|
info!(context, "[migration] v63");
|
||||||
|
sql.execute(
|
||||||
|
"ALTER TABLE chats ADD COLUMN error TEXT DEFAULT '';",
|
||||||
|
paramsv![],
|
||||||
|
)
|
||||||
|
.await?;
|
||||||
|
sql.set_raw_config_int(context, "dbversion", 64).await?;
|
||||||
|
}
|
||||||
|
|
||||||
// (2) updates that require high-level objects
|
// (2) updates that require high-level objects
|
||||||
// (the structure is complete now and all objects are usable)
|
// (the structure is complete now and all objects are usable)
|
||||||
|
|||||||
Reference in New Issue
Block a user