From 0c0f8210005be86f992c03f7b28e147cc8327cff Mon Sep 17 00:00:00 2001 From: Manos Pitsidianakis Date: Sat, 7 Sep 2024 12:47:01 +0300 Subject: [PATCH] Add a "move to Trash" shortcut Add send_to_trash shortcut (default value: `D`) to send an entry or selected entries to the Trash folder. Closes #389 Resolves: Signed-off-by: Manos Pitsidianakis --- meli/docs/meli.conf.5 | 3 ++ meli/src/command/actions.rs | 1 + meli/src/conf/shortcuts.rs | 1 + meli/src/mail/listing.rs | 58 ++++++++++++++++++++++++++++++++++++- 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/meli/docs/meli.conf.5 b/meli/docs/meli.conf.5 index bddeef56..c6ff3755 100644 --- a/meli/docs/meli.conf.5 +++ b/meli/docs/meli.conf.5 @@ -1243,6 +1243,9 @@ Manually request a mailbox refresh. .It Ic set_seen Set thread as seen. .Pq Em n \" default value +.It Ic send_to_trash +Send entry to trash folder. +.Pq Em D \" default value .It Ic union_modifier Union modifier. .Pq Em C-u \" default value diff --git a/meli/src/command/actions.rs b/meli/src/command/actions.rs index bef21da6..74bfa1b2 100644 --- a/meli/src/command/actions.rs +++ b/meli/src/command/actions.rs @@ -49,6 +49,7 @@ pub enum ListingAction { Select(String), SetSeen, SetUnseen, + SendToTrash, CopyTo(MailboxPath), CopyToOtherAccount(AccountName, MailboxPath), MoveTo(MailboxPath), diff --git a/meli/src/conf/shortcuts.rs b/meli/src/conf/shortcuts.rs index 8afb0cba..44252c62 100644 --- a/meli/src/conf/shortcuts.rs +++ b/meli/src/conf/shortcuts.rs @@ -174,6 +174,7 @@ shortcut_key_values! { "listing", search |> "Search within list of e-mails." |> Key::Char('/'), refresh |> "Manually request a mailbox refresh." |> Key::F(5), set_seen |> "Set thread as seen." |> Key::Char('n'), + send_to_trash |> "Send entry to trash folder." |> Key::Char('D'), union_modifier |> "Union modifier." |> Key::Ctrl('u'), diff_modifier |> "Difference modifier." |> Key::Ctrl('d'), intersection_modifier |> "Intersection modifier." |> Key::Ctrl('i'), diff --git a/meli/src/mail/listing.rs b/meli/src/mail/listing.rs index a4e300c3..9d559148 100644 --- a/meli/src/mail/listing.rs +++ b/meli/src/mail/listing.rs @@ -674,6 +674,51 @@ pub trait MailListingTrait: ListingTrait { )); } } + ListingAction::SendToTrash => { + use melib::backends::SpecialUsageMailbox; + + let Some(trash_mbox_hash) = account + .special_use_mailbox(SpecialUsageMailbox::Trash) + .or_else(|| account.special_use_mailbox(SpecialUsageMailbox::Junk)) + else { + context.replies.push_back(UIEvent::StatusEvent( + StatusEvent::DisplayMessage( + "Cannot send mail to trash because no Trash folder is configured." + .to_string(), + ), + )); + return; + }; + let job = account.backend.write().unwrap().copy_messages( + env_hashes, + mailbox_hash, + trash_mbox_hash, + /* move? */ true, + ); + match job { + Err(err) => { + context.replies.push_back(UIEvent::StatusEvent( + StatusEvent::DisplayMessage(err.to_string()), + )); + } + Ok(fut) => { + let handle = account.main_loop_handler.job_executor.spawn( + "move-to-trash".into(), + fut, + account.is_async(), + ); + account.insert_job( + handle.job_id, + JobRequest::Generic { + name: "taking out the trash".into(), + handle, + on_finish: None, + log_level: LogLevel::INFO, + }, + ); + } + } + } ListingAction::Delete => { let job = account .backend @@ -1787,7 +1832,8 @@ impl Component for Listing { | Action::Listing(a @ ListingAction::MoveToOtherAccount(_, _)) | Action::Listing(a @ ListingAction::ExportMbox(_, _)) | Action::Listing(a @ ListingAction::Flag(_)) - | Action::Listing(a @ ListingAction::Tag(_)) => { + | Action::Listing(a @ ListingAction::Tag(_)) + | Action::Listing(a @ ListingAction::SendToTrash) => { let focused = self.component.get_focused_items(context); self.component.perform_action(context, focused, a); let should_be_unselected: bool = matches!( @@ -1795,6 +1841,7 @@ impl Component for Listing { ListingAction::Delete | ListingAction::MoveTo(_) | ListingAction::MoveToOtherAccount(_, _) + | ListingAction::SendToTrash ); let mut row_updates: SmallVec<[EnvelopeHash; 8]> = SmallVec::new(); for (k, v) in self.component.selection().iter_mut() { @@ -2012,6 +2059,15 @@ impl Component for Listing { return true; } } + UIEvent::Input(ref key) + if shortcut!(key == shortcuts[Shortcuts::LISTING]["send_to_trash"]) => + { + let mut event = + UIEvent::Action(Action::Listing(ListingAction::SendToTrash)); + if self.process_event(&mut event, context) { + return true; + } + } UIEvent::Input(ref key) if shortcut!(key == shortcuts[Shortcuts::LISTING]["refresh"]) => {