Skip to content

Instantly share code, notes, and snippets.

@jay
jay / ShowGmailFolders.c
Last active October 18, 2021 20:44
Use libcurl to retrieve Gmail folders and labels via IMAP over SSL (IMAPS).
/* Use libcurl to retrieve Gmail folders and labels via IMAP over SSL (IMAPS).
Usage: ShowGmailFolders <username> <password>
curl-library mailing list thread:
'Re: DL curl 7.35 mingw32'
http://curl.haxx.se/mail/lib-2015-05/0037.html
Note: When you attempt to login to Gmail via IMAP they sometimes require a
web login first for security reasons. In that case an error will be shown. Such
@karanth
karanth / parse-imap.md
Last active August 7, 2022 06:27
Notes on parsing IMAP responses

The IMAP protocol workflow consists of the following steps,

  • A network connection established between the client and the server.
  • A greeting message sent by the server indicating that the client has successfully connected.
  • A series of interactions between the client and server.

The interactions consists of strings of lines, i.e. string terminated by a carriage return and a line feed (CRLF or \r\n). Interactions can be both commands (sent by clients) and data (sent by clients and servers). Both the client and the server strictly interact using lines or known length octet streams (8-bit characters) followed by a line.

####Client

An IMAP client issues commands to the server in a CRLF terminated string. The syntax of a command includes a tag, followed by the command and parameters. A tag is an alphanumeric identifier and each client command has a different tag for that session. A tag could be something like but not limited to A1, A2 etc.