summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/command.rs16
-rw-r--r--src/command/actions.rs2
-rw-r--r--src/components/mail/listing.rs22
3 files changed, 40 insertions, 0 deletions
diff --git a/src/command.rs b/src/command.rs
index 967be772..370ff833 100644
--- a/src/command.rs
+++ b/src/command.rs
@@ -303,6 +303,21 @@ define_commands!([
}
)
},
+ { tags: ["import "],
+ desc: "import FILESYSTEM_PATH MAILBOX_PATH",
+ tokens: &[One(Literal("import")), One(Filepath), One(MailboxPath)],
+ parser:(
+ fn import(input: &[u8]) -> IResult<&[u8], Action> {
+ let (input, _) = tag("import")(input.trim())?;
+ let (input, _) = is_a(" ")(input)?;
+ let (input, file) = quoted_argument(input)?;
+ let (input, _) = is_a(" ")(input)?;
+ let (input, mailbox_path) = quoted_argument(input)?;
+ let (input, _) = eof(input)?;
+ Ok((input, Listing(Import(file.to_string().into(), mailbox_path.to_string()))))
+ }
+ )
+ },
{ tags: ["close"],
desc: "close non-sticky tabs",
tokens: &[One(Literal("close"))],
@@ -769,6 +784,7 @@ fn listing_action(input: &[u8]) -> IResult<&[u8], Action> {
seen_flag,
delete_message,
copymove,
+ import,
search,
select,
toggle_thread_snooze,
diff --git a/src/command/actions.rs b/src/command/actions.rs
index fd6b9891..d4144599 100644
--- a/src/command/actions.rs
+++ b/src/command/actions.rs
@@ -25,6 +25,7 @@
use crate::components::Component;
pub use melib::thread::{SortField, SortOrder};
+use std::path::PathBuf;
extern crate uuid;
use uuid::Uuid;
@@ -49,6 +50,7 @@ pub enum ListingAction {
CopyToOtherAccount(AccountName, MailboxPath),
MoveTo(MailboxPath),
MoveToOtherAccount(AccountName, MailboxPath),
+ Import(PathBuf, MailboxPath),
Delete,
OpenInNewTab,
Tag(TagAction),
diff --git a/src/components/mail/listing.rs b/src/components/mail/listing.rs
index 7baa2cda..e347e86b 100644
--- a/src/components/mail/listing.rs
+++ b/src/components/mail/listing.rs
@@ -750,6 +750,28 @@ impl Component for Listing {
self.component.set_style(IndexStyle::Conversations);
return true;
}
+ Action::Listing(ListingAction::Import(file_path, mailbox_path)) => {
+ let account = &mut context.accounts[self.cursor_pos.0];
+ if let Err(err) = account
+ .mailbox_by_path(&mailbox_path)
+ .and_then(|mailbox_hash| {
+ Ok((
+ std::fs::read(&file_path).chain_err_summary(|| {
+ format!("Could not read {}", file_path.display())
+ })?,
+ mailbox_hash,
+ ))
+ })
+ .and_then(|(bytes, mailbox_hash)| {
+ account.save(&bytes, mailbox_hash, None)
+ })
+ {
+ context.replies.push_back(UIEvent::StatusEvent(
+ StatusEvent::DisplayMessage(err.to_string()),
+ ));
+ }
+ return true;
+ }
Action::Listing(a @ ListingAction::SetSeen)
| Action::Listing(a @ ListingAction::SetUnseen)
| Action::Listing(a @ ListingAction::Delete)