Returng String instead of Option<String> from create_incoming_rfc724_mid

This commit is contained in:
Alexander Krotov
2020-01-11 16:25:49 +03:00
parent 47b937f880
commit 7f8355298c

View File

@@ -155,20 +155,12 @@ pub fn dc_receive_imf(
// Add parts // Add parts
let rfc724_mid = match mime_parser.get_rfc724_mid() { let rfc724_mid = mime_parser.get_rfc724_mid().unwrap_or_else(|| {
Some(x) => x, // missing Message-IDs may come if the mail was set from this account with another
None => { // client that relies on the SMTP server to generate one.
// missing Message-IDs may come if the mail was set from this account with another // true eg. for the Webmailer used in all-inkl-KAS
// client that relies in the SMTP server to generate one. create_incoming_rfc724_mid(sent_timestamp, from_id, &to_ids)
// true eg. for the Webmailer used in all-inkl-KAS });
match dc_create_incoming_rfc724_mid(sent_timestamp, from_id, &to_ids) {
Some(x) => x,
None => {
bail!("No Message-Id found and could not create incoming rfc724_mid");
}
}
}
};
if mime_parser.parts.last().is_some() { if mime_parser.parts.last().is_some() {
if let Err(err) = add_parts( if let Err(err) = add_parts(
context, context,
@@ -1584,20 +1576,19 @@ fn add_or_lookup_contact_by_addr(
Ok(row_id) Ok(row_id)
} }
fn dc_create_incoming_rfc724_mid( fn create_incoming_rfc724_mid(
message_timestamp: i64, message_timestamp: i64,
contact_id_from: u32, contact_id_from: u32,
contact_ids_to: &ContactIds, contact_ids_to: &ContactIds,
) -> Option<String> { ) -> String {
/* create a deterministic rfc724_mid from input such that /* create a deterministic rfc724_mid from input such that
repeatedly calling it with the same input results in the same Message-id */ repeatedly calling it with the same input results in the same Message-id */
let largest_id_to = contact_ids_to.iter().max().copied().unwrap_or_default(); let largest_id_to = contact_ids_to.iter().max().copied().unwrap_or_default();
let result = format!( format!(
"{}-{}-{}@stub", "{}-{}-{}@stub",
message_timestamp, contact_id_from, largest_id_to message_timestamp, contact_id_from, largest_id_to
); )
Some(result)
} }
#[cfg(test)] #[cfg(test)]
@@ -1644,22 +1635,22 @@ mod tests {
} }
#[test] #[test]
fn test_dc_create_incoming_rfc724_mid() { fn test_create_incoming_rfc724_mid() {
let mut members = ContactIds::new(); let mut members = ContactIds::new();
assert_eq!( assert_eq!(
dc_create_incoming_rfc724_mid(123, 45, &members), create_incoming_rfc724_mid(123, 45, &members),
Some("123-45-0@stub".into()) "123-45-0@stub".to_string()
); );
members.insert(7); members.insert(7);
members.insert(3); members.insert(3);
assert_eq!( assert_eq!(
dc_create_incoming_rfc724_mid(123, 45, &members), create_incoming_rfc724_mid(123, 45, &members),
Some("123-45-7@stub".into()) "123-45-7@stub".to_string()
); );
members.insert(9); members.insert(9);
assert_eq!( assert_eq!(
dc_create_incoming_rfc724_mid(123, 45, &members), create_incoming_rfc724_mid(123, 45, &members),
Some("123-45-9@stub".into()) "123-45-9@stub".to_string()
); );
} }
} }