MailCore / mailcore2

MailCore 2 provide a simple and asynchronous API to work with e-mail protocols IMAP, POP and SMTP. The API has been redesigned from ground up.
Other
2.61k stars 627 forks source link

Method to clip ranges at UINT64_MAX #1689

Open matzipan opened 6 years ago

matzipan commented 6 years ago

Hello everyone,

So I'm playing with mailcore2 on linux and I've encountered a problem with RangeMake. Put shortly, something like mailcore::RangeMake (start_uid_value, end_uid_value), where start is anything higher than 1 when end is UINT64_MAX results in an overflow.

Take the following snippet:

auto range = mailcore::RangeMake (90000, UINT64_MAX);

auto fetch_messages_operation = session->fetchMessagesByUIDOperation(new mailcore::String (folder_path), (mailcore::IMAPMessagesRequestKind) kind, uidRange);

The actual command will try to fetch 90000:89999 because of an overflow. Honestly, I think this behavior of Range is confusing since the library is expecting start index and length when the developer might be giving start index and end index, but I realise that this might be hard to change in all the applications that depend on mailcore2.

Instead, I propose a clipping mechanism that will clip the end index to UINT64_MAX if the range overflows it. This would've saved me many hours of debugging.

What do you think?

matzipan commented 6 years ago

Looking more closely, I see this behavior also confused the author of this line in your library.