mirror of
https://github.com/soywod/himalaya.git
synced 2024-07-08 18:45:13 +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 error_chain::error_chain;
|
||||||
use std::env;
|
use std::env;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
flag::cli::{flag_matches, flag_subcmds},
|
flag::cli::{flag_matches, flag_subcmds},
|
||||||
|
imap::cli::{imap_matches, imap_subcmds},
|
||||||
mbox::cli::{mbox_arg, mbox_matches, mbox_subcmds},
|
mbox::cli::{mbox_arg, mbox_matches, mbox_subcmds},
|
||||||
msg::cli::{msg_matches, msg_subcmds},
|
msg::cli::{msg_matches, msg_subcmds},
|
||||||
};
|
};
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
links {
|
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);
|
MboxCli(crate::mbox::cli::Error, crate::mbox::cli::ErrorKind);
|
||||||
MsgCli(crate::msg::cli::Error, crate::msg::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"),
|
.value_name("STRING"),
|
||||||
)
|
)
|
||||||
.arg(mbox_arg())
|
.arg(mbox_arg())
|
||||||
.subcommand(SubCommand::with_name("idle").about("Spawns a blocking idle daemon"));
|
.subcommands(flag_subcmds())
|
||||||
|
.subcommands(imap_subcmds())
|
||||||
let app = app.subcommands(mbox_subcmds());
|
.subcommands(mbox_subcmds())
|
||||||
let app = app.subcommands(flag_subcmds());
|
.subcommands(msg_subcmds());
|
||||||
let app = app.subcommands(msg_subcmds());
|
|
||||||
|
|
||||||
Self(app)
|
Self(app)
|
||||||
}
|
}
|
||||||
|
@ -62,18 +63,14 @@ impl<'a> App<'a> {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if imap_matches(&matches)? {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
msg_matches(&matches)?;
|
msg_matches(&matches)?;
|
||||||
break;
|
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(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,12 @@
|
||||||
use clap::{App, Arg, ArgMatches, SubCommand};
|
use clap::{App, Arg, ArgMatches, SubCommand};
|
||||||
use error_chain::error_chain;
|
use error_chain::error_chain;
|
||||||
|
|
||||||
use crate::{
|
use crate::{config::Config, imap::model::ImapConnector};
|
||||||
config::{self, Config},
|
|
||||||
imap::{self, ImapConnector},
|
|
||||||
};
|
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
links {
|
links {
|
||||||
Config(config::Error, config::ErrorKind);
|
Config(crate::config::Error, crate::config::ErrorKind);
|
||||||
Imap(imap::Error, imap::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> {
|
pub fn flag_matches(matches: &ArgMatches) -> Result<bool> {
|
||||||
let config = Config::new_from_file()?;
|
let config = Config::new_from_file()?;
|
||||||
let account = config.find_account_by_name(matches.value_of("account"))?;
|
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 mbox = matches.value_of("mailbox").unwrap();
|
||||||
let mut imap_conn = ImapConnector::new(&account)?;
|
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 app;
|
||||||
mod config;
|
mod config;
|
||||||
mod imap;
|
|
||||||
mod input;
|
mod input;
|
||||||
mod output;
|
mod output;
|
||||||
mod smtp;
|
mod smtp;
|
||||||
mod table;
|
mod table;
|
||||||
|
mod imap {
|
||||||
|
pub(crate) mod cli;
|
||||||
|
pub(crate) mod model;
|
||||||
|
}
|
||||||
mod flag {
|
mod flag {
|
||||||
pub(crate) mod cli;
|
pub(crate) mod cli;
|
||||||
pub(crate) mod model;
|
pub(crate) mod model;
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
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 crate::{config::Config, imap::ImapConnector, output::print};
|
use crate::{config::Config, imap::model::ImapConnector, output::print};
|
||||||
|
|
||||||
error_chain! {
|
error_chain! {
|
||||||
links {
|
links {
|
||||||
Config(crate::config::Error, crate::config::ErrorKind);
|
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);
|
MsgCli(crate::msg::cli::Error, crate::msg::cli::ErrorKind);
|
||||||
Output(crate::output::Error, crate::output::ErrorKind);
|
Output(crate::output::Error, crate::output::ErrorKind);
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,7 +4,7 @@ use std::fs;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
config::Config,
|
config::Config,
|
||||||
imap::ImapConnector,
|
imap::model::ImapConnector,
|
||||||
input,
|
input,
|
||||||
msg::model::{Attachments, Msg, Msgs, ReadableMsg},
|
msg::model::{Attachments, Msg, Msgs, ReadableMsg},
|
||||||
output::print,
|
output::print,
|
||||||
|
@ -14,7 +14,7 @@ use crate::{
|
||||||
error_chain! {
|
error_chain! {
|
||||||
links {
|
links {
|
||||||
Config(crate::config::Error, crate::config::ErrorKind);
|
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);
|
Input(crate::input::Error, crate::input::ErrorKind);
|
||||||
MsgModel(crate::msg::model::Error, crate::msg::model::ErrorKind);
|
MsgModel(crate::msg::model::Error, crate::msg::model::ErrorKind);
|
||||||
Output(crate::output::Error, crate::output::ErrorKind);
|
Output(crate::output::Error, crate::output::ErrorKind);
|
||||||
|
|
Loading…
Reference in a new issue