question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

FetchAsync is not loading list of UniqueIds

See original GitHub issue

Describe the bug

I’m attempting to load recent messages from a given folder, in this case a user’s inbox. I get a list of unique ids using folder.SortAsync() then take that list and call folder.FetchAsync(). SortAsync is returning 199 UniqueId values. When I call fetch, no records are returned.

However, if I request a single UniqueId at a time, it works. I assume the IMAP server does not support ranges.

Is there a capability I can look at the determine this behavior? Also, is there a way to request that Fetch not use ranges?

Using MailKit 2.3.0

Expected behavior I’d expect FetchAsync to return the 199 messages.

Additional context

Output from Imap Protocol Logger
S: A00000000 OK [CAPABILITY IMAP4REV1 LITERAL+ UTF8=ALL STARTTLS IDLE NAMESPACE UNSELECT SORT QUOTA ID] User [redacted] authenticated
C: A00000001 NAMESPACE
S: * NAMESPACE (("" "/")) NIL NIL
S: A00000001 OK NAMESPACE completed
C: A00000002 LIST "" "INBOX"
S: * LIST (\NoInferiors) NIL INBOX
S: A00000002 OK LIST completed
C: A00000003 LIST "" "%"
S: * LIST (\NoInferiors) NIL INBOX
S: * LIST (\Marked) "/" mail/SPAM.incoming
S: * LIST (\UnMarked) "/" mail/drafts
S: * LIST (\UnMarked) "/" mail/sent-mail
S: * LIST (\UnMarked) "/" mail/trash
S: * LIST (\UnMarked) "/" "Junk E-mail"
S: * LIST (\UnMarked) "/" "Sent Items"
S: * LIST (\UnMarked) "/" "Deleted Items"
S: * LIST (\UnMarked) "/" Drafts
S: A00000003 OK LIST completed
C: A00000004 LIST "" mail
S: A00000004 OK LIST completed
C: A00000005 EXAMINE INBOX
S: * 199 EXISTS
S: * 2 RECENT
S: * OK [UIDVALIDITY 1279810762] UID validity status
S: * OK [UIDNEXT 38448] Predicted next UID
S: * FLAGS (\Answered \Flagged \Deleted \Draft \Seen)
S: * OK [PERMANENTFLAGS ()] Permanent flags
S: * OK [UNSEEN 198] first unseen message in mailbox
S: A00000005 OK [READ-ONLY] EXAMINE completed
C: A00000006 UID SORT (REVERSE ARRIVAL) US-ASCII ALL
S: * SORT 38447 38446 38445 38444 38443 38442 38441 38440 38439 38438 38437 38436 38435 38434 38433 38432 38431 38430 38429 38428 38427 38426 38425 38424 38423 38422 38421 38420 38419 38418 38417 38416 38415 38414 38413 38412 38411 38410 38409 38408 38407 38406 38405 38404 38403 38402 38401 38400 38399 38398 38397 38396 38395 38394 38393 38392 38391 38390 38389 38388 38387 38386 38385 38384 38383 38382 38381 38380 38379 38378 38377 38376 38375 38374 38373 38372 38371 38370 38369 38368 38367 38366 38365 38364 38363 38362 38361 38360 38359 38358 38357 38356 38355 38354 38353 38352 38351 38350 38349 38348 38347 38346 38345 38344 38343 38342 38341 38340 38339 38338 38337 38336 38335 38334 38333 38332 38331 38330 38329 38328 38327 38326 38325 38324 38323 38322 38321 38320 38319 38318 38317 38316 38315 38314 38313 38312 38311 38310 38309 38308 38307 38306 38305 38304 38303 38302 38301 38300 38299 38298 38297 38296 38295 38294 38293 38292 38291 38290 38289 38288 38287 38286 38285 38284 38283 38282 38281 38280 38279 38278 38277 38276 38275 38274 38273 38272 38271 38270 38269 38268 38267 38266 38265 38264 38263 38262 38261 38260 38259 38258 38257 38256 38255 38254 38253 38252 38251 38250 38249
S: A00000006 OK UID SORT completed
C: A00000007 UID FETCH 38447:38348 BODY.PEEK[HEADER.FIELDS (TO FROM MESSAGE-ID DATE DELIVERY-DATE SUBJECT REFERENCES IN-REPLY-TO)]
S: A00000007 OK UID FETCH completed

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jstedfastcommented, Sep 10, 2019

Thanks! That might be good enough. Perhaps the IMAP server is called Bigfoot. I’ll have to do some web searching later to see.

I generally prefer to try and use the info in the line you gave me than hostnames to do this sort of work-around.

1reaction
jstedfastcommented, Sep 10, 2019

The problem seems to be a bug in your IMAP server which cannot handle UIDs in descending order.

Solution:

var uids = folder.Search (SearchQuery.All);
var results = folder.Fetch (uids, ...);
results.Sort (new OrderBy[] { OrderBy.ReverseArrival });
Read more comments on GitHub >

github_iconTop Results From Across the Web

JS lodash uniq not woking with ObjectID list
I have a collection of mongoose models, I tried to use uniq lodash function to get unique id`s from the list, but still...
Read more >
jstedfast/MailKit: A cross-platform .NET library for IMAP, ...
For SMTP, most developers use System.Net.Mail.SmtpClient which suits their needs more-or-less satisfactorily and so is probably not high on their list of needs....
Read more >
Receiving Emails In C#/.NET
Learn how to receive emails with only one line of code.
Read more >
MailFolder Class
Asynchronously expunge the specified uids, permanently removing them from the folder. Public method Code example, Fetch(IList<UniqueId>, IFetchRequest, ...
Read more >
Find unique IDs which entries do not have a certain value ...
I want to find which unique studies do not have any "accept" value, count them, and exclude them.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found