add send and sav subcommands

This commit is contained in:
Clément DOUIN 2021-03-09 15:26:41 +01:00
parent 2b5be91af9
commit f7ed99d55f
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF

View file

@ -217,6 +217,17 @@ fn run() -> Result<()> {
.arg(uid_arg())
.arg(mailbox_arg()),
)
.subcommand(
SubCommand::with_name("send")
.about("Sends a raw message")
.arg(Arg::with_name("message").raw(true)),
)
.subcommand(
SubCommand::with_name("save")
.about("Saves a raw message in the given mailbox")
.arg(mailbox_arg())
.arg(Arg::with_name("message").raw(true)),
)
.subcommand(
SubCommand::with_name("template")
.aliases(&["tpl", "t"])
@ -471,6 +482,32 @@ fn run() -> Result<()> {
imap_conn.logout();
}
if let Some(matches) = matches.subcommand_matches("send") {
let config = Config::new_from_file()?;
let account = config.find_account_by_name(account_name)?;
let mut imap_conn = ImapConnector::new(&account)?;
let msg = matches.value_of("message").unwrap();
let msg = Msg::from(msg.to_string());
smtp::send(&account, &msg.to_sendable_msg()?)?;
imap_conn.append_msg("Sent", &msg.to_vec()?)?;
imap_conn.logout();
}
if let Some(matches) = matches.subcommand_matches("save") {
let config = Config::new_from_file()?;
let account = config.find_account_by_name(account_name)?;
let mut imap_conn = ImapConnector::new(&account)?;
let mbox = matches.value_of("mailbox").unwrap();
let msg = matches.value_of("message").unwrap();
let msg = Msg::from(msg.to_string());
imap_conn.append_msg(mbox, &msg.to_vec()?)?;
imap_conn.logout();
}
Ok(())
}