fixed overflow when empty page

This commit is contained in:
Clément DOUIN 2021-03-16 22:33:06 +01:00
parent c9b26031e2
commit 0dd73e693e
No known key found for this signature in database
GPG key ID: 69C9B9CFFDEE2DEF
2 changed files with 11 additions and 3 deletions

View file

@ -18,6 +18,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Fixed
- Missing `FLAGS` column in messages table [#40]
- Subtract with overflow if next page empty [#38]
## [0.2.0] - 2021-03-10
@ -80,5 +81,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
[#25]: https://github.com/soywod/himalaya/issues/25
[#29]: https://github.com/soywod/himalaya/issues/29
[#32]: https://github.com/soywod/himalaya/issues/32
[#38]: https://github.com/soywod/himalaya/issues/38
[#39]: https://github.com/soywod/himalaya/issues/39
[#40]: https://github.com/soywod/himalaya/issues/40

View file

@ -101,10 +101,16 @@ impl<'a> ImapConnector<'a> {
.sess
.select(mbox)
.chain_err(|| format!("Cannot select mailbox `{}`", mbox))?
.exists;
.exists as i64;
let begin = last_seq - page * page_size;
let end = begin - (begin - 1).min(page_size - 1);
if last_seq == 0 {
return Err(format!("Cannot select empty mailbox `{}`", mbox).into());
}
// 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 msgs = self