Merge pull request #1971 from deltachat/accessible-msg-error

Accessible msg error and type changes
This commit is contained in:
René Rössler
2020-10-08 12:54:20 +02:00
committed by GitHub
5 changed files with 68 additions and 16 deletions

View File

@@ -3524,6 +3524,27 @@ char* dc_msg_get_setupcodebegin (const dc_msg_t* msg);
*/
char* dc_msg_get_videochat_url (const dc_msg_t* msg);
/**
* Gets the error status of the message.
* If there is no error associated with the message, NULL is returned.
*
* A message can have an associated error status if something went wrong when sending or
* receiving message itself. The error status is free-form text and should not be further parsed,
* rather it's presence is meant to indicate *something* went wrong with the message and the
* text of the error is detailed information on what.
*
* Some common reasons error can be associated with messages are:
* * Lack of valid signature on an e2ee message, usually for received messages.
* * Failure to decrypt an e2ee message, usually for received messages.
* * When a message could not be delivered to one or more recipients the non-delivery
* notification text can be stored in the error status.
*
* @memberof dc_msg_t
* @param msg The message object.
* @return Error or NULL. The result must be released using dc_str_unref().
*/
char* dc_msg_get_error (const dc_msg_t* msg);
/**
* Get type of videochat.

View File

@@ -2962,6 +2962,19 @@ pub unsafe extern "C" fn dc_msg_latefiling_mediasize(
});
}
#[no_mangle]
pub unsafe extern "C" fn dc_msg_get_error(msg: *mut dc_msg_t) -> *mut libc::c_char {
if msg.is_null() {
eprintln!("ignoring careless call to dc_msg_get_error()");
return ptr::null_mut();
}
let ffi_msg = &*msg;
match ffi_msg.message.error() {
Some(error) => error.strdup(),
None => ptr::null_mut(),
}
}
// dc_contact_t
/// FFI struct for [dc_contact_t]

View File

@@ -815,7 +815,7 @@ async fn add_parts(
mime_headers,
mime_in_reply_to,
mime_references,
part.error,
part.error.take().unwrap_or_default(),
ephemeral_timer,
ephemeral_timestamp
])?;
@@ -2455,7 +2455,7 @@ mod tests {
"shenauithz@testrun.org",
"Mr.un2NYERi1RM.lbQ5F9q-QyJ@tiscali.it",
include_bytes!("../test-data/message/tiscali_ndn.eml"),
"",
None,
)
.await;
}
@@ -2467,7 +2467,7 @@ mod tests {
"hcksocnsofoejx@five.chat",
"Mr.A7pTA5IgrUA.q4bP41vAJOp@testrun.org",
include_bytes!("../test-data/message/testrun_ndn.eml"),
"Undelivered Mail Returned to Sender This is the mail system at host hq5.merlinux.eu.\n\nI\'m sorry to have to inform you that your message could not\nbe delivered to one or more recipients. It\'s attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can\ndelete your own text from the attached returned message.\n\n The mail system\n\n<hcksocnsofoejx@five.chat>: host mail.five.chat[195.62.125.103] said: 550 5.1.1\n <hcksocnsofoejx@five.chat>: Recipient address rejected: User unknown in\n virtual mailbox table (in reply to RCPT TO command)"
Some("Undelivered Mail Returned to Sender This is the mail system at host hq5.merlinux.eu.\n\nI\'m sorry to have to inform you that your message could not\nbe delivered to one or more recipients. It\'s attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can\ndelete your own text from the attached returned message.\n\n The mail system\n\n<hcksocnsofoejx@five.chat>: host mail.five.chat[195.62.125.103] said: 550 5.1.1\n <hcksocnsofoejx@five.chat>: Recipient address rejected: User unknown in\n virtual mailbox table (in reply to RCPT TO command)"),
)
.await;
}
@@ -2479,7 +2479,7 @@ mod tests {
"haeclirth.sinoenrat@yahoo.com",
"1680295672.3657931.1591783872936@mail.yahoo.com",
include_bytes!("../test-data/message/yahoo_ndn.eml"),
"Failure Notice Sorry, we were unable to deliver your message to the following address.\n\n<haeclirth.sinoenrat@yahoo.com>:\n554: delivery error: dd Not a valid recipient - atlas117.free.mail.ne1.yahoo.com [...]"
Some("Failure Notice Sorry, we were unable to deliver your message to the following address.\n\n<haeclirth.sinoenrat@yahoo.com>:\n554: delivery error: dd Not a valid recipient - atlas117.free.mail.ne1.yahoo.com [...]"),
)
.await;
}
@@ -2491,7 +2491,7 @@ mod tests {
"assidhfaaspocwaeofi@gmail.com",
"CABXKi8zruXJc_6e4Dr087H5wE7sLp+u250o0N2q5DdjF_r-8wg@mail.gmail.com",
include_bytes!("../test-data/message/gmail_ndn.eml"),
"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",
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"),
)
.await;
}
@@ -2503,7 +2503,7 @@ mod tests {
"snaerituhaeirns@gmail.com",
"9c9c2a32-056b-3592-c372-d7e8f0bd4bc2@gmx.de",
include_bytes!("../test-data/message/gmx_ndn.eml"),
"Mail delivery failed: returning message to sender This message was created automatically by mail delivery software.\n\nA message that you sent could not be delivered to one or more of\nits recipients. This is a permanent error. The following address(es)\nfailed:\n\nsnaerituhaeirns@gmail.com:\nSMTP error from remote server for RCPT TO command, host: gmail-smtp-in.l.google.com (66.102.1.27) reason: 550-5.1.1 The email account that you tried to reach does not exist. Please\n try\n550-5.1.1 double-checking the recipient\'s email address for typos or\n550-5.1.1 unnecessary spaces. Learn more at\n550 5.1.1 https://support.google.com/mail/?p=NoSuchUser f6si2517766wmc.21\n9 - gsmtp [...]"
Some("Mail delivery failed: returning message to sender This message was created automatically by mail delivery software.\n\nA message that you sent could not be delivered to one or more of\nits recipients. This is a permanent error. The following address(es)\nfailed:\n\nsnaerituhaeirns@gmail.com:\nSMTP error from remote server for RCPT TO command, host: gmail-smtp-in.l.google.com (66.102.1.27) reason: 550-5.1.1 The email account that you tried to reach does not exist. Please\n try\n550-5.1.1 double-checking the recipient\'s email address for typos or\n550-5.1.1 unnecessary spaces. Learn more at\n550 5.1.1 https://support.google.com/mail/?p=NoSuchUser f6si2517766wmc.21\n9 - gsmtp [...]"),
)
.await;
}
@@ -2515,7 +2515,7 @@ mod tests {
"hanerthaertidiuea@gmx.de",
"04422840-f884-3e37-5778-8192fe22d8e1@posteo.de",
include_bytes!("../test-data/message/posteo_ndn.eml"),
"Undelivered Mail Returned to Sender This is the mail system at host mout01.posteo.de.\n\nI\'m sorry to have to inform you that your message could not\nbe delivered to one or more recipients. It\'s attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can\ndelete your own text from the attached returned message.\n\n The mail system\n\n<hanerthaertidiuea@gmx.de>: host mx01.emig.gmx.net[212.227.17.5] said: 550\n Requested action not taken: mailbox unavailable (in reply to RCPT TO\n command)",
Some("Undelivered Mail Returned to Sender This is the mail system at host mout01.posteo.de.\n\nI\'m sorry to have to inform you that your message could not\nbe delivered to one or more recipients. It\'s attached below.\n\nFor further assistance, please send mail to postmaster.\n\nIf you do so, please include this problem report. You can\ndelete your own text from the attached returned message.\n\n The mail system\n\n<hanerthaertidiuea@gmx.de>: host mx01.emig.gmx.net[212.227.17.5] said: 550\n Requested action not taken: mailbox unavailable (in reply to RCPT TO\n command)"),
)
.await;
}
@@ -2526,7 +2526,7 @@ mod tests {
foreign_addr: &str,
rfc724_mid_outgoing: &str,
raw_ndn: &[u8],
error_msg: &str,
error_msg: Option<&str>,
) {
let t = TestContext::new().await;
t.configure_addr(self_addr).await;
@@ -2569,7 +2569,8 @@ mod tests {
let msg = Message::load_from_db(&t.ctx, msg_id).await.unwrap();
assert_eq!(msg.state, MessageState::OutFailed);
assert_eq!(msg.error, error_msg);
assert_eq!(msg.error(), error_msg.map(|error| error.to_string()));
}
#[async_std::test]

View File

@@ -265,7 +265,7 @@ pub struct Message {
pub(crate) is_dc_message: MessengerMessage,
pub(crate) chat_blocked: Blocked,
pub(crate) location_id: u32,
pub(crate) error: String,
error: Option<String>,
pub(crate) param: Params,
}
@@ -331,7 +331,8 @@ impl Message {
msg.ephemeral_timestamp = row.get("ephemeral_timestamp")?;
msg.viewtype = row.get("type")?;
msg.state = row.get("state")?;
msg.error = row.get("error")?;
let error: String = row.get("error")?;
msg.error = Some(error).filter(|error| !error.is_empty());
msg.is_dc_message = row.get("msgrmsg")?;
let text;
@@ -750,6 +751,22 @@ impl Message {
.await
.is_ok()
}
/// Gets the error status of the message.
///
/// A message can have an associated error status if something went wrong when sending or
/// receiving message itself. The error status is free-form text and should not be further parsed,
/// rather it's presence is meant to indicate *something* went wrong with the message and the
/// text of the error is detailed information on what.
///
/// Some common reasons error can be associated with messages are:
/// * Lack of valid signature on an e2ee message, usually for received messages.
/// * Failure to decrypt an e2ee message, usually for received messages.
/// * When a message could not be delivered to one or more recipients the non-delivery
/// notification text can be stored in the error status.
pub fn error(&self) -> Option<String> {
self.error.clone()
}
}
#[derive(
@@ -1044,8 +1061,8 @@ pub async fn get_msg_info(context: &Context, msg_id: MsgId) -> String {
ret += "\n";
if !msg.error.is_empty() {
ret += &format!("Error: {}", msg.error);
if let Some(error) = msg.error.as_ref() {
ret += &format!("Error: {}", error);
}
if let Some(path) = msg.get_file(context) {

View File

@@ -223,7 +223,7 @@ impl MimeMessage {
if warn_empty_signature && parser.signatures.is_empty() {
for part in parser.parts.iter_mut() {
part.error = "No valid signature".to_string();
part.error = Some("No valid signature".to_string());
}
}
@@ -589,7 +589,7 @@ impl MimeMessage {
part.typ = Viewtype::Text;
part.msg_raw = Some(txt.clone());
part.msg = txt;
part.error = "Decryption failed".to_string();
part.error = Some("Decryption failed".to_string());
self.parts.push(part);
@@ -1179,7 +1179,7 @@ pub struct Part {
pub bytes: usize,
pub param: Params,
org_filename: Option<String>,
pub error: String,
pub error: Option<String>,
}
/// return mimetype and viewtype for a parsed mail