Add import mail action
parent
afe7eed9ef
commit
3ec1ecb349
|
@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||
|
||||
## [Unreleased]
|
||||
|
||||
### Added
|
||||
- Add import command to import email from files into accounts
|
||||
|
||||
## [alpha-0.6.2] - 2020-09-24
|
||||
|
||||
### Added
|
||||
|
|
|
@ -408,6 +408,8 @@ select threads matching
|
|||
query.
|
||||
.It Cm set seen, set unseen
|
||||
Set seen status of message.
|
||||
.It Cm import Ar FILEPATH Ar MAILBOX_PATH
|
||||
Import mail from file into given mailbox.
|
||||
.It Cm copyto, moveto Ar MAILBOX_PATH
|
||||
Copy or move to other mailbox.
|
||||
.It Cm copyto, moveto Ar ACCOUNT Ar MAILBOX_PATH
|
||||
|
|
|
@ -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,
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue