add default page size config (#96)

This commit is contained in:
Clément DOUIN
2021-04-17 22:37:59 +02:00
parent 2f4caaca07
commit 3e0d1f704d
10 changed files with 248 additions and 168 deletions
+12 -7
View File
@@ -2,7 +2,10 @@ use clap::{self, App, ArgMatches, SubCommand};
use error_chain::error_chain;
use log::debug;
use crate::{config::model::Config, imap::model::ImapConnector};
use crate::{
config::model::{Account, Config},
imap::model::ImapConnector,
};
error_chain! {
links {
@@ -15,18 +18,20 @@ 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 mbox = matches.value_of("mailbox").unwrap();
pub fn imap_matches(
config: &Config,
account: &Account,
mbox: &str,
matches: &ArgMatches,
) -> Result<bool> {
if let Some(_) = matches.subcommand_matches("idle") {
debug!("[imap::cli] idle command matched");
debug!("[imap::cli::matches] idle command matched");
let mut imap_conn = ImapConnector::new(&account)?;
imap_conn.idle(&config, &mbox)?;
imap_conn.logout();
return Ok(true);
}
debug!("[imap::cli::matches] nothing matched");
Ok(false)
}
+8 -4
View File
@@ -197,10 +197,14 @@ impl<'ic> ImapConnector<'ic> {
}
// TODO: add tests, improve error management when empty page
let cursor = (page * page_size) as i64;
let begin = 1.max(last_seq - cursor);
let end = begin - begin.min(*page_size as i64) + 1;
let range = format!("{}:{}", begin, end);
let range = if page_size > &0 {
let cursor = (page * page_size) as i64;
let begin = 1.max(last_seq - cursor);
let end = begin - begin.min(*page_size as i64) + 1;
format!("{}:{}", begin, end)
} else {
String::from("1:*")
};
let fetches = self
.sess