From f7ed99d55fdfff05b052094ee07303919382405f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20DOUIN?= Date: Tue, 9 Mar 2021 15:26:41 +0100 Subject: [PATCH] add send and sav subcommands --- src/main.rs | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/src/main.rs b/src/main.rs index ccc9fa1..88c1e16 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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(()) }