mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-08 18:45:13 +00:00
add copy/move/delete features
This commit is contained in:
parent
8dbd7c1e7a
commit
8d1f1e5ed1
|
@ -12,6 +12,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
- IDLE support [#29]
|
- IDLE support [#29]
|
||||||
- Improve choice after editing msg [#30]
|
- Improve choice after editing msg [#30]
|
||||||
- Flags management [#41]
|
- Flags management [#41]
|
||||||
|
- Copy feature [#35]
|
||||||
|
- Move feature [#31]
|
||||||
|
- Delete feature [#36]
|
||||||
|
|
||||||
### Changed
|
### Changed
|
||||||
|
|
||||||
|
@ -83,7 +86,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||||
[#25]: https://github.com/soywod/himalaya/issues/25
|
[#25]: https://github.com/soywod/himalaya/issues/25
|
||||||
[#29]: https://github.com/soywod/himalaya/issues/29
|
[#29]: https://github.com/soywod/himalaya/issues/29
|
||||||
[#30]: https://github.com/soywod/himalaya/issues/30
|
[#30]: https://github.com/soywod/himalaya/issues/30
|
||||||
|
[#31]: https://github.com/soywod/himalaya/issues/31
|
||||||
[#32]: https://github.com/soywod/himalaya/issues/32
|
[#32]: https://github.com/soywod/himalaya/issues/32
|
||||||
|
[#34]: https://github.com/soywod/himalaya/issues/34
|
||||||
|
[#35]: https://github.com/soywod/himalaya/issues/35
|
||||||
[#38]: https://github.com/soywod/himalaya/issues/38
|
[#38]: https://github.com/soywod/himalaya/issues/38
|
||||||
[#39]: https://github.com/soywod/himalaya/issues/39
|
[#39]: https://github.com/soywod/himalaya/issues/39
|
||||||
[#40]: https://github.com/soywod/himalaya/issues/40
|
[#40]: https://github.com/soywod/himalaya/issues/40
|
||||||
|
|
27
README.md
27
README.md
|
@ -21,6 +21,9 @@ Minimalist CLI email client, written in Rust.
|
||||||
* [Write a new message](#write-a-new-message)
|
* [Write a new message](#write-a-new-message)
|
||||||
* [Reply to a message](#reply-to-a-message)
|
* [Reply to a message](#reply-to-a-message)
|
||||||
* [Forward a message](#forward-a-message)
|
* [Forward a message](#forward-a-message)
|
||||||
|
* [Copy a message](#copy-a-message)
|
||||||
|
* [Move a message](#move-a-message)
|
||||||
|
* [Delete a message](#delete-a-message)
|
||||||
* [Listen to new messages](#listen-to-new-messages)
|
* [Listen to new messages](#listen-to-new-messages)
|
||||||
* [License](https://github.com/soywod/himalaya/blob/master/LICENSE)
|
* [License](https://github.com/soywod/himalaya/blob/master/LICENSE)
|
||||||
* [Changelog](https://github.com/soywod/himalaya/blob/master/CHANGELOG.md)
|
* [Changelog](https://github.com/soywod/himalaya/blob/master/CHANGELOG.md)
|
||||||
|
@ -167,6 +170,30 @@ himalaya forward 5123
|
||||||
|
|
||||||
Opens your default editor to forward a message.
|
Opens your default editor to forward a message.
|
||||||
|
|
||||||
|
### Copy a message
|
||||||
|
|
||||||
|
```bash
|
||||||
|
himalaya copy 5123 Sent
|
||||||
|
```
|
||||||
|
|
||||||
|
Copies a message to the targetted mailbox.
|
||||||
|
|
||||||
|
### Move a message
|
||||||
|
|
||||||
|
```bash
|
||||||
|
himalaya move 5123 Drafts
|
||||||
|
```
|
||||||
|
|
||||||
|
Moves a message to the targetted mailbox.
|
||||||
|
|
||||||
|
### Delete a message
|
||||||
|
|
||||||
|
```bash
|
||||||
|
himalaya delete 5123
|
||||||
|
```
|
||||||
|
|
||||||
|
Moves a message.
|
||||||
|
|
||||||
### Listen to new messages
|
### Listen to new messages
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
use error_chain::error_chain;
|
use error_chain::error_chain;
|
||||||
|
|
||||||
|
use crate::msg::cli::uid_arg;
|
||||||
use crate::{config::model::Config, imap::model::ImapConnector};
|
use crate::{config::model::Config, imap::model::ImapConnector};
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
|
@ -10,13 +11,6 @@ error_chain! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uid_arg<'a, 'b>() -> Arg<'a, 'b> {
|
|
||||||
Arg::with_name("uid")
|
|
||||||
.help("Message UID")
|
|
||||||
.value_name("UID")
|
|
||||||
.required(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn flags_arg<'a, 'b>() -> Arg<'a, 'b> {
|
fn flags_arg<'a, 'b>() -> Arg<'a, 'b> {
|
||||||
Arg::with_name("flags")
|
Arg::with_name("flags")
|
||||||
.help("IMAP flags (see https://tools.ietf.org/html/rfc3501#page-11)")
|
.help("IMAP flags (see https://tools.ietf.org/html/rfc3501#page-11)")
|
||||||
|
|
|
@ -5,6 +5,7 @@ use std::net::TcpStream;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::model::{Account, Config},
|
config::model::{Account, Config},
|
||||||
|
flag::model::Flag,
|
||||||
mbox::model::{Mbox, Mboxes},
|
mbox::model::{Mbox, Mboxes},
|
||||||
msg::model::Msg,
|
msg::model::Msg,
|
||||||
};
|
};
|
||||||
|
@ -203,7 +204,7 @@ impl<'ic> ImapConnector<'ic> {
|
||||||
|
|
||||||
match self
|
match self
|
||||||
.sess
|
.sess
|
||||||
.uid_fetch(uid, "BODY[]")
|
.uid_fetch(uid, "(FLAGS BODY[])")
|
||||||
.chain_err(|| "Cannot fetch bodies")?
|
.chain_err(|| "Cannot fetch bodies")?
|
||||||
.first()
|
.first()
|
||||||
{
|
{
|
||||||
|
@ -212,10 +213,10 @@ impl<'ic> ImapConnector<'ic> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn append_msg(&mut self, mbox: &str, msg: &[u8]) -> Result<()> {
|
pub fn append_msg(&mut self, mbox: &str, msg: &[u8], flags: &[Flag]) -> Result<()> {
|
||||||
self.sess
|
self.sess
|
||||||
.append_with_flags(mbox, msg, &[imap::types::Flag::Seen])
|
.append_with_flags(mbox, msg, flags)
|
||||||
.chain_err(|| format!("Cannot append message to `{}` with \\Seen flag", mbox))?;
|
.chain_err(|| format!("Cannot append message to `{}`", mbox))?;
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,7 +34,7 @@ use crate::{
|
||||||
config::cli::account_arg,
|
config::cli::account_arg,
|
||||||
flag::cli::{flag_matches, flag_subcmds},
|
flag::cli::{flag_matches, flag_subcmds},
|
||||||
imap::cli::{imap_matches, imap_subcmds},
|
imap::cli::{imap_matches, imap_subcmds},
|
||||||
mbox::cli::{mbox_arg, mbox_matches, mbox_subcmds},
|
mbox::cli::{mbox_matches, mbox_source_arg, mbox_subcmds},
|
||||||
msg::cli::{msg_matches, msg_subcmds},
|
msg::cli::{msg_matches, msg_subcmds},
|
||||||
output::cli::output_arg,
|
output::cli::output_arg,
|
||||||
};
|
};
|
||||||
|
@ -55,7 +55,7 @@ fn run() -> Result<()> {
|
||||||
.author(env!("CARGO_PKG_AUTHORS"))
|
.author(env!("CARGO_PKG_AUTHORS"))
|
||||||
.arg(output_arg())
|
.arg(output_arg())
|
||||||
.arg(account_arg())
|
.arg(account_arg())
|
||||||
.arg(mbox_arg())
|
.arg(mbox_source_arg())
|
||||||
.subcommands(flag_subcmds())
|
.subcommands(flag_subcmds())
|
||||||
.subcommands(imap_subcmds())
|
.subcommands(imap_subcmds())
|
||||||
.subcommands(mbox_subcmds())
|
.subcommands(mbox_subcmds())
|
||||||
|
|
|
@ -12,15 +12,21 @@ error_chain! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn mbox_arg<'a>() -> Arg<'a, 'a> {
|
pub fn mbox_source_arg<'a>() -> Arg<'a, 'a> {
|
||||||
Arg::with_name("mailbox")
|
Arg::with_name("mailbox")
|
||||||
.short("m")
|
.short("m")
|
||||||
.long("mailbox")
|
.long("mailbox")
|
||||||
.help("Selects a specific mailbox")
|
.help("Selects a specific mailbox")
|
||||||
.value_name("STRING")
|
.value_name("MAILBOX")
|
||||||
.default_value("INBOX")
|
.default_value("INBOX")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn mbox_target_arg<'a>() -> Arg<'a, 'a> {
|
||||||
|
Arg::with_name("target")
|
||||||
|
.help("Specifies the targetted mailbox")
|
||||||
|
.value_name("TARGET")
|
||||||
|
}
|
||||||
|
|
||||||
pub fn mbox_subcmds<'a>() -> Vec<App<'a, 'a>> {
|
pub fn mbox_subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||||
vec![SubCommand::with_name("mailboxes")
|
vec![SubCommand::with_name("mailboxes")
|
||||||
.aliases(&["mailbox", "mboxes", "mbox", "m"])
|
.aliases(&["mailbox", "mboxes", "mbox", "m"])
|
||||||
|
|
|
@ -1,11 +1,13 @@
|
||||||
use clap::{self, App, Arg, ArgMatches, SubCommand};
|
use clap::{self, App, Arg, ArgMatches, SubCommand};
|
||||||
use error_chain::error_chain;
|
use error_chain::error_chain;
|
||||||
use std::fs;
|
use std::{fs, ops::Deref};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::model::Config,
|
config::model::Config,
|
||||||
|
flag::model::Flag,
|
||||||
imap::model::ImapConnector,
|
imap::model::ImapConnector,
|
||||||
input,
|
input,
|
||||||
|
mbox::cli::mbox_target_arg,
|
||||||
msg::model::{Attachments, Msg, Msgs, ReadableMsg},
|
msg::model::{Attachments, Msg, Msgs, ReadableMsg},
|
||||||
output::utils::print,
|
output::utils::print,
|
||||||
smtp,
|
smtp,
|
||||||
|
@ -22,9 +24,9 @@ error_chain! {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn uid_arg<'a>() -> Arg<'a, 'a> {
|
pub fn uid_arg<'a>() -> Arg<'a, 'a> {
|
||||||
Arg::with_name("uid")
|
Arg::with_name("uid")
|
||||||
.help("Message UID")
|
.help("Specifies the targetted message")
|
||||||
.value_name("UID")
|
.value_name("UID")
|
||||||
.required(true)
|
.required(true)
|
||||||
}
|
}
|
||||||
|
@ -95,16 +97,30 @@ pub fn msg_subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||||
),
|
),
|
||||||
SubCommand::with_name("attachments")
|
SubCommand::with_name("attachments")
|
||||||
.aliases(&["attach", "att", "a"])
|
.aliases(&["attach", "att", "a"])
|
||||||
.about("Downloads all attachments from an email")
|
.about("Downloads all message attachments")
|
||||||
.arg(uid_arg()),
|
.arg(uid_arg()),
|
||||||
SubCommand::with_name("reply")
|
SubCommand::with_name("reply")
|
||||||
.aliases(&["rep", "re"])
|
.aliases(&["rep", "re"])
|
||||||
.about("Answers to an email")
|
.about("Answers to a message")
|
||||||
.arg(uid_arg())
|
.arg(uid_arg())
|
||||||
.arg(reply_all_arg()),
|
.arg(reply_all_arg()),
|
||||||
SubCommand::with_name("forward")
|
SubCommand::with_name("forward")
|
||||||
.aliases(&["fwd", "f"])
|
.aliases(&["fwd", "f"])
|
||||||
.about("Forwards an email")
|
.about("Forwards a message")
|
||||||
|
.arg(uid_arg()),
|
||||||
|
SubCommand::with_name("copy")
|
||||||
|
.aliases(&["cp", "c"])
|
||||||
|
.about("Copy a message to the targetted mailbox")
|
||||||
|
.arg(uid_arg())
|
||||||
|
.arg(mbox_target_arg()),
|
||||||
|
SubCommand::with_name("move")
|
||||||
|
.aliases(&["mv", "m"])
|
||||||
|
.about("Move a message to the targetted mailbox")
|
||||||
|
.arg(uid_arg())
|
||||||
|
.arg(mbox_target_arg()),
|
||||||
|
SubCommand::with_name("delete")
|
||||||
|
.aliases(&["remove", "rm", "del", "d"])
|
||||||
|
.about("Delete a message")
|
||||||
.arg(uid_arg()),
|
.arg(uid_arg()),
|
||||||
SubCommand::with_name("template")
|
SubCommand::with_name("template")
|
||||||
.aliases(&["tpl", "t"])
|
.aliases(&["tpl", "t"])
|
||||||
|
@ -243,13 +259,13 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
println!("Sending…");
|
println!("Sending…");
|
||||||
let msg = msg.to_sendable_msg()?;
|
let msg = msg.to_sendable_msg()?;
|
||||||
smtp::send(&account, &msg)?;
|
smtp::send(&account, &msg)?;
|
||||||
imap_conn.append_msg("Sent", &msg.formatted())?;
|
imap_conn.append_msg("Sent", &msg.formatted(), &[Flag::Seen])?;
|
||||||
println!("Done!");
|
println!("Done!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
input::Choice::Draft => {
|
input::Choice::Draft => {
|
||||||
println!("Saving to draft…");
|
println!("Saving to draft…");
|
||||||
imap_conn.append_msg("Drafts", &msg.to_vec()?)?;
|
imap_conn.append_msg("Drafts", &msg.to_vec()?, &[Flag::Seen])?;
|
||||||
println!("Done!");
|
println!("Done!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -294,6 +310,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
let tpl = msg.build_forward_tpl(&config, &account)?;
|
let tpl = msg.build_forward_tpl(&config, &account)?;
|
||||||
|
|
||||||
print(&output_fmt, &tpl)?;
|
print(&output_fmt, &tpl)?;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
@ -318,14 +335,14 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
input::Choice::Send => {
|
input::Choice::Send => {
|
||||||
println!("Sending…");
|
println!("Sending…");
|
||||||
smtp::send(&account, &msg.to_sendable_msg()?)?;
|
smtp::send(&account, &msg.to_sendable_msg()?)?;
|
||||||
imap_conn.append_msg("Sent", &msg.to_vec()?)?;
|
imap_conn.append_msg("Sent", &msg.to_vec()?, &[Flag::Seen])?;
|
||||||
imap_conn.add_flags(mbox, uid, "\\Answered")?;
|
imap_conn.add_flags(mbox, uid, "\\Answered")?;
|
||||||
println!("Done!");
|
println!("Done!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
input::Choice::Draft => {
|
input::Choice::Draft => {
|
||||||
println!("Saving to draft…");
|
println!("Saving to draft…");
|
||||||
imap_conn.append_msg("Drafts", &msg.to_vec()?)?;
|
imap_conn.append_msg("Drafts", &msg.to_vec()?, &[Flag::Seen])?;
|
||||||
println!("Done!");
|
println!("Done!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -356,13 +373,13 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
input::Choice::Send => {
|
input::Choice::Send => {
|
||||||
println!("Sending…");
|
println!("Sending…");
|
||||||
smtp::send(&account, &msg.to_sendable_msg()?)?;
|
smtp::send(&account, &msg.to_sendable_msg()?)?;
|
||||||
imap_conn.append_msg("Sent", &msg.to_vec()?)?;
|
imap_conn.append_msg("Sent", &msg.to_vec()?, &[Flag::Seen])?;
|
||||||
println!("Done!");
|
println!("Done!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
input::Choice::Draft => {
|
input::Choice::Draft => {
|
||||||
println!("Saving to draft…");
|
println!("Saving to draft…");
|
||||||
imap_conn.append_msg("Drafts", &msg.to_vec()?)?;
|
imap_conn.append_msg("Drafts", &msg.to_vec()?, &[Flag::Seen])?;
|
||||||
println!("Done!");
|
println!("Done!");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -379,13 +396,44 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if let Some(matches) = matches.subcommand_matches("copy") {
|
||||||
|
let uid = matches.value_of("uid").unwrap();
|
||||||
|
let target = matches.value_of("target").unwrap();
|
||||||
|
|
||||||
|
let msg = Msg::from(imap_conn.read_msg(&mbox, &uid)?);
|
||||||
|
let mut flags = msg.flags.deref().to_vec();
|
||||||
|
flags.push(Flag::Seen);
|
||||||
|
|
||||||
|
imap_conn.append_msg(target, &msg.to_vec()?, &flags)?;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(matches) = matches.subcommand_matches("move") {
|
||||||
|
let uid = matches.value_of("uid").unwrap();
|
||||||
|
let target = matches.value_of("target").unwrap();
|
||||||
|
|
||||||
|
let msg = Msg::from(imap_conn.read_msg(&mbox, &uid)?);
|
||||||
|
let mut flags = msg.flags.deref().to_vec();
|
||||||
|
flags.push(Flag::Seen);
|
||||||
|
|
||||||
|
imap_conn.append_msg(target, &msg.to_vec()?, msg.flags.deref())?;
|
||||||
|
imap_conn.add_flags(mbox, uid, "\\Seen \\Deleted")?;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if let Some(matches) = matches.subcommand_matches("delete") {
|
||||||
|
let uid = matches.value_of("uid").unwrap();
|
||||||
|
imap_conn.add_flags(mbox, uid, "\\Seen \\Deleted")?;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
if let Some(matches) = matches.subcommand_matches("send") {
|
if let Some(matches) = matches.subcommand_matches("send") {
|
||||||
let msg = matches.value_of("message").unwrap();
|
let msg = matches.value_of("message").unwrap();
|
||||||
let msg = Msg::from(msg.to_string());
|
let msg = Msg::from(msg.to_string());
|
||||||
let msg = msg.to_sendable_msg()?;
|
let msg = msg.to_sendable_msg()?;
|
||||||
|
|
||||||
smtp::send(&account, &msg)?;
|
smtp::send(&account, &msg)?;
|
||||||
imap_conn.append_msg("Sent", &msg.formatted())?;
|
imap_conn.append_msg("Sent", &msg.formatted(), &[Flag::Seen])?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -393,7 +441,7 @@ pub fn msg_matches(matches: &ArgMatches) -> Result<()> {
|
||||||
let msg = matches.value_of("message").unwrap();
|
let msg = matches.value_of("message").unwrap();
|
||||||
let msg = Msg::from(msg.to_string());
|
let msg = Msg::from(msg.to_string());
|
||||||
|
|
||||||
imap_conn.append_msg(mbox, &msg.to_vec()?)?;
|
imap_conn.append_msg(mbox, &msg.to_vec()?, &[Flag::Seen])?;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -567,7 +567,7 @@ impl<'m> DisplayTable<'m, Msg<'m>> for Msgs<'m> {
|
||||||
|
|
||||||
impl<'m> From<&'m imap::types::ZeroCopy<Vec<imap::types::Fetch>>> for Msgs<'m> {
|
impl<'m> From<&'m imap::types::ZeroCopy<Vec<imap::types::Fetch>>> for Msgs<'m> {
|
||||||
fn from(fetches: &'m imap::types::ZeroCopy<Vec<imap::types::Fetch>>) -> Self {
|
fn from(fetches: &'m imap::types::ZeroCopy<Vec<imap::types::Fetch>>) -> Self {
|
||||||
Self(fetches.iter().map(Msg::from).collect::<Vec<_>>())
|
Self(fetches.iter().rev().map(Msg::from).collect::<Vec<_>>())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue