mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-05 17:15:12 +00:00
extract imap cli+model
This commit is contained in:
parent
96c527dd1a
commit
e2ba18cda8
27
src/app.rs
27
src/app.rs
|
@ -1,18 +1,20 @@
|
|||
use clap::{self, Arg, SubCommand};
|
||||
use clap::{self, Arg};
|
||||
use error_chain::error_chain;
|
||||
use std::env;
|
||||
|
||||
use crate::{
|
||||
flag::cli::{flag_matches, flag_subcmds},
|
||||
imap::cli::{imap_matches, imap_subcmds},
|
||||
mbox::cli::{mbox_arg, mbox_matches, mbox_subcmds},
|
||||
msg::cli::{msg_matches, msg_subcmds},
|
||||
};
|
||||
|
||||
error_chain! {
|
||||
links {
|
||||
FlagCli(crate::flag::cli::Error, crate::flag::cli::ErrorKind);
|
||||
ImapCli(crate::imap::cli::Error, crate::imap::cli::ErrorKind);
|
||||
MboxCli(crate::mbox::cli::Error, crate::mbox::cli::ErrorKind);
|
||||
MsgCli(crate::msg::cli::Error, crate::msg::cli::ErrorKind);
|
||||
FlagCli(crate::flag::cli::Error, crate::flag::cli::ErrorKind);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -41,11 +43,10 @@ impl<'a> App<'a> {
|
|||
.value_name("STRING"),
|
||||
)
|
||||
.arg(mbox_arg())
|
||||
.subcommand(SubCommand::with_name("idle").about("Spawns a blocking idle daemon"));
|
||||
|
||||
let app = app.subcommands(mbox_subcmds());
|
||||
let app = app.subcommands(flag_subcmds());
|
||||
let app = app.subcommands(msg_subcmds());
|
||||
.subcommands(flag_subcmds())
|
||||
.subcommands(imap_subcmds())
|
||||
.subcommands(mbox_subcmds())
|
||||
.subcommands(msg_subcmds());
|
||||
|
||||
Self(app)
|
||||
}
|
||||
|
@ -62,18 +63,14 @@ impl<'a> App<'a> {
|
|||
break;
|
||||
}
|
||||
|
||||
if imap_matches(&matches)? {
|
||||
break;
|
||||
}
|
||||
|
||||
msg_matches(&matches)?;
|
||||
break;
|
||||
}
|
||||
|
||||
// if let Some(matches) = matches.subcommand_matches("idle") {
|
||||
// let config = Config::new_from_file()?;
|
||||
// let account = config.find_account_by_name(account)?;
|
||||
// let mut imap_conn = ImapConnector::new(&account)?;
|
||||
// let mbox = matches.value_of("mailbox").unwrap();
|
||||
// imap_conn.idle(&config, &mbox)?;
|
||||
// }
|
||||
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,12 @@
|
|||
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||
use error_chain::error_chain;
|
||||
|
||||
use crate::{
|
||||
config::{self, Config},
|
||||
imap::{self, ImapConnector},
|
||||
};
|
||||
use crate::{config::Config, imap::model::ImapConnector};
|
||||
|
||||
error_chain! {
|
||||
links {
|
||||
Config(config::Error, config::ErrorKind);
|
||||
Imap(imap::Error, imap::ErrorKind);
|
||||
Config(crate::config::Error, crate::config::ErrorKind);
|
||||
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -58,7 +55,6 @@ pub fn flag_subcmds<'a>() -> Vec<App<'a, 'a>> {
|
|||
pub fn flag_matches(matches: &ArgMatches) -> Result<bool> {
|
||||
let config = Config::new_from_file()?;
|
||||
let account = config.find_account_by_name(matches.value_of("account"))?;
|
||||
let output_fmt = matches.value_of("output").unwrap();
|
||||
let mbox = matches.value_of("mailbox").unwrap();
|
||||
let mut imap_conn = ImapConnector::new(&account)?;
|
||||
|
||||
|
|
30
src/imap/cli.rs
Normal file
30
src/imap/cli.rs
Normal file
|
@ -0,0 +1,30 @@
|
|||
use clap::{self, App, ArgMatches, SubCommand};
|
||||
use error_chain::error_chain;
|
||||
|
||||
use crate::{config::Config, imap::model::ImapConnector};
|
||||
|
||||
error_chain! {
|
||||
links {
|
||||
Config(crate::config::Error, crate::config::ErrorKind);
|
||||
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn imap_subcmds<'a>() -> Vec<App<'a, 'a>> {
|
||||
vec![SubCommand::with_name("idle").about("Spawns a blocking idle daemon")]
|
||||
}
|
||||
|
||||
pub fn imap_matches(matches: &ArgMatches) -> Result<bool> {
|
||||
let config = Config::new_from_file()?;
|
||||
let account = config.find_account_by_name(matches.value_of("account"))?;
|
||||
let mut imap_conn = ImapConnector::new(&account)?;
|
||||
let mbox = matches.value_of("mailbox").unwrap();
|
||||
|
||||
if let Some(matches) = matches.subcommand_matches("idle") {
|
||||
imap_conn.idle(&config, &mbox)?;
|
||||
imap_conn.logout();
|
||||
return Ok(true);
|
||||
}
|
||||
|
||||
Ok(false)
|
||||
}
|
|
@ -1,10 +1,13 @@
|
|||
mod app;
|
||||
mod config;
|
||||
mod imap;
|
||||
mod input;
|
||||
mod output;
|
||||
mod smtp;
|
||||
mod table;
|
||||
mod imap {
|
||||
pub(crate) mod cli;
|
||||
pub(crate) mod model;
|
||||
}
|
||||
mod flag {
|
||||
pub(crate) mod cli;
|
||||
pub(crate) mod model;
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
use clap::{self, App, Arg, ArgMatches, SubCommand};
|
||||
use error_chain::error_chain;
|
||||
|
||||
use crate::{config::Config, imap::ImapConnector, output::print};
|
||||
use crate::{config::Config, imap::model::ImapConnector, output::print};
|
||||
|
||||
error_chain! {
|
||||
links {
|
||||
Config(crate::config::Error, crate::config::ErrorKind);
|
||||
Imap(crate::imap::Error, crate::imap::ErrorKind);
|
||||
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
||||
MsgCli(crate::msg::cli::Error, crate::msg::cli::ErrorKind);
|
||||
Output(crate::output::Error, crate::output::ErrorKind);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ use std::fs;
|
|||
|
||||
use crate::{
|
||||
config::Config,
|
||||
imap::ImapConnector,
|
||||
imap::model::ImapConnector,
|
||||
input,
|
||||
msg::model::{Attachments, Msg, Msgs, ReadableMsg},
|
||||
output::print,
|
||||
|
@ -14,7 +14,7 @@ use crate::{
|
|||
error_chain! {
|
||||
links {
|
||||
Config(crate::config::Error, crate::config::ErrorKind);
|
||||
Imap(crate::imap::Error, crate::imap::ErrorKind);
|
||||
Imap(crate::imap::model::Error, crate::imap::model::ErrorKind);
|
||||
Input(crate::input::Error, crate::input::ErrorKind);
|
||||
MsgModel(crate::msg::model::Error, crate::msg::model::ErrorKind);
|
||||
Output(crate::output::Error, crate::output::ErrorKind);
|
||||
|
|
Loading…
Reference in a new issue