diff --git a/CHANGELOG.md b/CHANGELOG.md index 44d69e5..f20ba47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Config option `signature-delimiter` to customize the signature delimiter (default to `-- \n`) [[#114](https://github.com/soywod/himalaya/pull/114)] - Expand tilde and env vars for `downloads-dir` and `signature` [#102] +### Changed + +- Pagination for list and search cmd starts from 1 instead of 0 [#186] + ### Fixed - New/reply/forward from Vim plugin since Tpl refactor [#176] @@ -307,3 +311,4 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 [#146]: https://github.com/soywod/himalaya/issues/146 [#160]: https://github.com/soywod/himalaya/issues/160 [#176]: https://github.com/soywod/himalaya/issues/176 +[#186]: https://github.com/soywod/himalaya/issues/186 diff --git a/src/msg/cli.rs b/src/msg/cli.rs index 3b4ebbf..af4e7b3 100644 --- a/src/msg/cli.rs +++ b/src/msg/cli.rs @@ -66,7 +66,7 @@ fn page_arg<'a>() -> clap::Arg<'a, 'a> { .short("p") .long("page") .value_name("INT") - .default_value("0") + .default_value("1") } fn attachment_arg<'a>() -> clap::Arg<'a, 'a> { @@ -185,6 +185,7 @@ fn msg_matches_list(ctx: &Ctx, opt_matches: Option<&clap::ArgMatches>) -> Result debug!("page size: {:?}", page_size); let page: usize = opt_matches .and_then(|matches| matches.value_of("page").unwrap().parse().ok()) + .map(|page| 1.max(page) - 1) .unwrap_or_default(); debug!("page: {}", &page); @@ -215,7 +216,8 @@ fn msg_matches_search(ctx: &Ctx, matches: &clap::ArgMatches) -> Result { .value_of("page") .unwrap() .parse() - .unwrap_or_default(); + .map(|page| 1.max(page) - 1) + .unwrap_or(1); debug!("page: {}", &page); let query = matches diff --git a/tests/imap_test.rs b/tests/imap_test.rs index fbbb6b8..b1687e8 100644 --- a/tests/imap_test.rs +++ b/tests/imap_test.rs @@ -74,7 +74,7 @@ fn msg() { // List messages // TODO: check non-existance of \Seen flag - let msgs = imap_conn.list_msgs("INBOX", &10, &0).unwrap(); + let msgs = imap_conn.list_msgs("INBOX", &10, &1).unwrap(); let msgs = if let Some(ref fetches) = msgs { Msgs::from(fetches) } else { @@ -111,7 +111,7 @@ fn msg() { .add_flags("INBOX", &msg_b.uid.to_string(), "\\Deleted") .unwrap(); imap_conn.expunge("INBOX").unwrap(); - assert!(imap_conn.list_msgs("INBOX", &10, &0).unwrap().is_none()); + assert!(imap_conn.list_msgs("INBOX", &10, &1).unwrap().is_none()); // Logout imap_conn.logout();