Skip to content

Commit

Permalink
feat(host): Support return receipt
Browse files Browse the repository at this point in the history
  • Loading branch information
Frederick888 committed Mar 12, 2023
1 parent 6bf8be2 commit 27c3c06
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/model/messaging.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ const HEADER_ATTACH_VCARD: &str = "X-ExtEditorR-Attach-vCard";
const HEADER_LOWER_ATTACH_VCARD: &str = "x-exteditorr-attach-vcard"; // cspell: disable-line
const HEADER_DELIVERY_STATUS_NOTIFICATION: &str = "X-ExtEditorR-Delivery-Status-Notification";
const HEADER_LOWER_DELIVERY_STATUS_NOTIFICATION: &str = "x-exteditorr-delivery-status-notification"; // cspell: disable-line
const HEADER_RETURN_RECEIPT: &str = "X-ExtEditorR-Return-Receipt";
const HEADER_LOWER_RETURN_RECEIPT: &str = "x-exteditorr-return-receipt"; // cspell: disable-line
const HEADER_SEND_ON_EXIT: &str = "X-ExtEditorR-Send-On-Exit";
const HEADER_LOWER_SEND_ON_EXIT: &str = "x-exteditorr-send-on-exit"; // cspell: disable-line
const HEADER_HELP: &str = "X-ExtEditorR-Help";
Expand Down Expand Up @@ -110,6 +112,9 @@ impl Compose {
delivery_status_notification
)?;
}
if let Some(return_receipt) = self.compose_details.return_receipt {
writeln_crlf!(w, "{}: {}", HEADER_RETURN_RECEIPT, return_receipt)?;
}
writeln_crlf!(
w,
"{}: {}",
Expand Down Expand Up @@ -191,6 +196,9 @@ impl Compose {
self.compose_details.delivery_status_notification =
Some(bool::from_str(header_value)?);
}
HEADER_LOWER_RETURN_RECEIPT => {
self.compose_details.return_receipt = Some(bool::from_str(header_value)?);
}
HEADER_LOWER_SEND_ON_EXIT => {
self.configuration.send_on_exit = header_value == "true"
}
Expand Down Expand Up @@ -640,6 +648,30 @@ pub mod tests {
responses[0].compose_details.delivery_status_notification
);
}

#[test]
fn merge_return_receipt_test() {
let mut request = get_blank_compose();

let mut buf = Vec::new();
let result = request.to_eml(&mut buf);
assert!(result.is_ok());
let output = String::from_utf8(buf).unwrap();
assert!(!output.contains("X-ExtEditorR-Return-Receipt:"));

request.compose_details.return_receipt = Some(false);
let mut buf = Vec::new();
let result = request.to_eml(&mut buf);
assert!(result.is_ok());
let output = String::from_utf8(buf).unwrap();
assert!(output.contains("X-ExtEditorR-Return-Receipt: false"));

let mut eml = "X-ExtEditorR-Return-Receipt: true\r\n\r\nThis is a test.\r\n".as_bytes();
let responses = request.merge_from_eml(&mut eml, 512).unwrap();
assert_eq!(1, responses.len());
assert_eq!(Some(true), responses[0].compose_details.return_receipt);
}

#[test]
fn merge_send_on_exit_test() {
let mut eml = "X-ExtEditorR-Send-On-Exit: true\r\n\r\nThis is a test.\r\n".as_bytes();
Expand Down
3 changes: 3 additions & 0 deletions src/model/thunderbird.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,8 @@ pub struct ComposeDetails {
pub attach_vcard: TrackedOptionBool,
#[serde(rename = "deliveryStatusNotification")]
pub delivery_status_notification: Option<bool>,
#[serde(rename = "returnReceipt")]
pub return_receipt: Option<bool>,
}

impl ComposeDetails {
Expand Down Expand Up @@ -589,6 +591,7 @@ pub mod tests {
priority: None,
attach_vcard: TrackedOptionBool::default(),
delivery_status_notification: None,
return_receipt: None,
}
}
}

0 comments on commit 27c3c06

Please sign in to comment.