Search code examples
.netimap

imap fetch return {6} {15}


im working on a .net imap client

when i fetch envelopes i get back lines like this

  • 2 FETCH (FLAGS (\SEEN) INTERNALDATE "13-Nov-2011 02:38:07 -0700" RFC822.SIZE 10993 UID 62 ENVELOPE ("13 Nov 2011 12:37:32 +0200" "Your Order" (({15}

  • 1 FETCH (FLAGS (\SEEN) INTERNALDATE "11-Nov-2009 13:54:35 -0700" RFC822.SIZE 38501 UID 1 ENVELOPE ("Wed, 11 Nov 2009 17:50:29 -0400" "Newegg.com - Order Confirmation" (({6}

    Newegg NIL "info" "newegg.com")) (({6}

    Newegg NIL "info" "newegg.com")) NIL ((NIL NIL "office" "mysite.com")) NIL NIL NIL ""))

the rest of the envelope is on the next line

sometimes it breaks on {15} like the first

sometimes on {6}

maybe there are others as well, so far i had these

i tried many different encodings in the streamwriter and/or streamreader (ascii,utf7,utf8)

so what do these numbers mean? or how can i just correctly read the line till the end

thanks a lot!


Solution

  • You need to read up on the IMAP protocol if you're implementing your own client rather than using an existing library. The meaning of the numbers in curly brackets is well explained in the RFC.

    It's a literal. The bracketed number is always followed by an end of line (CRLF) and then a number of raw bytes that form the value of the string. The number between the brackets is a count of the number of raw bytes that follow. You need to read exactly that many raw bytes after the CRLF (and be careful about encoding and line ending conversions: if you decode text or translate line endings then you might read the wrong number of raw bytes).