10 IMAP: Reading Mail
10.1 Connecting and Selecting Mailboxes
procedure
(imap-connection? v) → boolean?
v : any/c
procedure
(imap-connect server username password mailbox [ #:tls? tls? #:try-tls? try-tls? #:xoauth2? xoauth2?]) →
imap-connection? exact-nonnegative-integer? exact-nonnegative-integer? server : string? username : (or/c string? bytes?) password : (or/c string? bytes?) mailbox : (or/c string? bytes?) tls? : any/c = #f try-tls? : any/c = #t xoauth2? : any/c = #f
The first result value represents the connection. The second and third return values indicate the total number of messages in the mailbox and the number of recent messages (i.e., messages received since the mailbox was last selected), respectively.
See also imap-port-number.
A user’s primary mailbox is always called "INBOX". (Capitalization doesn’t matter for that mailbox name.)
Updated message-count and recent-count values are available through imap-messages and imap-recent. See also imap-new? and imap-reset-new!.
Changed in version 1.2 of package net-lib: Added the xoauth2? argument.
parameter
(imap-port-number) → (integer-in 0 65535)
(imap-port-number k) → void? k : (integer-in 0 65535)
procedure
(imap-connect* in out username password mailbox [ #:tls? tls? #:try-tls? try-tls? #:xoauth2? xoauth2?])
→
imap-connection? exact-nonnegative-integer? exact-nonnegative-integer? in : input-port? out : output-port? username : (or/c string? bytes?) password : (or/c string? bytes?) mailbox : (or/c string? bytes?) tls? : any/c = #f try-tls? : any/c = #t xoauth2? : any/c = #f
Changed in version 1.2 of package net-lib: Added the xoauth2? argument.
procedure
(imap-disconnect imap) → void?
imap : imap-connection?
procedure
(imap-force-disconnect imap) → void?
imap : imap-connection?
procedure
(imap-reselect imap mailbox) →
exact-nonnegative-integer? exact-nonnegative-integer? imap : imap-connection? mailbox : (or/c string? bytes?)
Do not use this procedure to poll a mailbox to see whether there are any new messages. Use imap-noop, imap-new?, and imap-reset-new! instead.
procedure
(imap-examine imap mailbox) →
exact-nonnegative-integer? exact-nonnegative-integer? imap : imap-connection? mailbox : (or/c string? bytes?)
10.2 Selected Mailbox State
procedure
(imap-noop imap) →
exact-nonnegative-integer? exact-nonnegative-integer? imap : imap-connection?
The return information is the same as for imap-reselect.
procedure
imap : imap-connection?
procedure
(imap-messages imap) → exact-nonnegative-integer?
imap : imap-connection?
This operation does not communicate with the server. It merely reports the result of previous communication.
procedure
(imap-recent imap) → exact-nonnegative-integer?
imap : imap-connection?
This operation does not communicate with the server. It merely reports the result of previous communication.
procedure
(imap-unseen imap) → (or/c exact-nonnegative-integer? #f)
imap : imap-connection?
This operation does not communicate with the server. It merely reports the result of previous communication.
procedure
(imap-uidnext imap) → (or/c exact-nonnegative-integer? #f)
imap : imap-connection?
This operation does not communicate with the server. It merely reports the result of previous communication.
procedure
(imap-uidvalidity imap) → (or/c exact-nonnegative-integer? #f)
imap : imap-connection?
This operation does not communicate with the server. It merely reports the result of previous communication.
procedure
imap : imap-connection?
This operation does not communicate with the server. It merely reports the result of previous communication.
procedure
(imap-reset-new! imap) → void?
imap : imap-connection?
procedure
(imap-get-expunges imap) → (listof exact-nonnegative-integer?)
imap : imap-connection?
This operation does not communicate with the server. It merely reports the result of previous communication.
The server can notify the client of newly deleted messages during most other commands, but not asynchronously between commands. Furthermore, the server cannot report new deletions during imap-get-messages or imap-store operations.
Before calling any IMAP operation that works in terms of message numbers, pending expunge notifications must be handled by calling imap-get-expunges.
procedure
(imap-pending-expunges? imap) → boolean?
imap : imap-connection?
procedure
(imap-get-updates imap)
→
(listof (cons/c exact-nonnegative-integer? (listof pair?))) imap : imap-connection?
This operation does not communicate with the server. It merely reports the result of previous communication. It also clears the update information from the connection after reporting it.
When a server reports information that supersedes old reported information for a message, or if the server reports that a message has been deleted, then old information for the message is dropped. Similarly, if imap-get-messages is used to explicitly obtain information, any redundant (or out-of-date) information is dropped.
A client need not use imap-get-updates ever, but accumulated information for the connection consumes space.
procedure
(imap-pending-updates? imap) → boolean?
imap : imap-connection?
10.3 Manipulating Messages
procedure
(imap-get-messages imap msg-nums fields) → (listof list?)
imap : imap-connection? msg-nums : (listof exact-nonnegative-integer?)
fields :
(listof (or/c 'uid 'header 'body 'flags 'date))
'uid —
the value is an integer 'header —
the value is a header (a string, but see net/head) 'body —
the value is a byte string, with CRLF-separated lines 'flags —
the value is a list of symbols that correspond to IMAP flags; see imap-flag->symbol 'date —
the value is a byte string following IMAP’s format for internal message dates (which is distinct from any date field in the message’s header)
The return value is a list of entry items in parallel to msg-nums. Each entry is itself a list containing value items in parallel to fields.
Pending expunges must be handled before calling this function; see imap-get-expunges.
> (imap-get-messages imap '(1 3 5) '(uid header))
'((107 #"From: larry@stooges.com ...")
(110 #"From: moe@stooges.com ...")
(112 #"From: curly@stooges.com ..."))
Changed in version 1.2 of package net-lib: Added the 'date field option.
procedure
(imap-flag->symbol flag) → symbol?
flag : symbol?
procedure
(symbol->imap-flag sym) → symbol?
sym : symbol?
|
|
| symbol |
| IMAP flag |
| message flags: |
| 'seen |
| '|\Seen| |
|
|
| 'answered |
| '|\Answered| |
|
|
| 'flagged |
| '|\Flagged| |
|
|
| 'deleted |
| '|\Deleted| |
|
|
| 'draft |
| '|\Draft| |
|
|
| 'recent |
| '|\Recent| |
| mailbox flags: |
| 'noinferiors |
| '|\Noinferiors| |
|
|
| 'noselect |
| '|\Noselect| |
|
|
| 'marked |
| '|\Marked| |
|
|
| 'unmarked |
| '|\Unmarked| |
|
|
| 'hasnochildren |
| '|\HasNoChildren| |
|
|
| 'haschildren |
| '|\HasChildren| |
The imap-flag->symbol and symbol->imap-flag functions act like the identity function when any other symbol is provided.
procedure
(imap-store imap mode msg-nums imap-flags) → void?
imap : imap-connection? mode : (or/c '+ '- '!) msg-nums : (listof exact-nonnegative-integer?) imap-flags : (listof symbol?)
'+ —
add the given flags to each message '- —
remove the given flags from each message '! —
set each message’s flags to the given set
The msg-nums argument specifies a set of messages by their message positions (not their uids). The flags argument specifies the imap flags to add/remove/install.
Pending expunges must be handled before calling this function; see imap-get-expunges. The server will not report back message-state changes (so they will not show up through imap-get-updates).
> (imap-store imap '+ '(1 2 3) (list (symbol->imap-flag 'deleted))) ; marks the first three messages to be deleted > (imap-expunge imap) ; permanently removes the first three messages (and possibly ; others) from the currently-selected mailbox
procedure
(imap-expunge imap) → void?
imap : imap-connection?
10.4 Querying and Changing (Other) Mailboxes
procedure
imap : imap-connection? msg-nums : (listof exact-nonnegative-integer?) dest-mailbox : (or/c string? bytes?)
Pending expunges must be handled before calling this function; see imap-get-expunges.
procedure
(imap-append imap mailbox message [ flags #:date date]) → void? imap : imap-connection? mailbox : string? message : (or/c string? bytes?)
flags :
(listof (or/c 'seen 'answered 'flagged 'deleted 'draft 'recent)) = '(seen) date : (or/c string? bytes? #f) = #f
The date string, if provided, determines the internal date associated with the message, as opposed to the date in the message header. The date-string format is defined by IMAP, and the same format is used for a 'date result from imap-get-messages.
Changed in version 1.2 of package net-lib: Added the optional date argument.
procedure
(imap-status imap mailbox statuses) → list?
imap : imap-connection? mailbox : (or/c string? bytes?) statuses : (listof symbol?)
The statuses list specifies the request, and the return value includes one value for each symbol in statuses. The allowed status symbols are:
'messages —
number of messages 'recent —
number of recent messages 'unseen —
number of unseen messages 'uidnext —
uid for next received message 'uidvalidity —
id that changes when all uids are changed
Use imap-messages to get the message count for the currently selected mailbox, etc. Use imap-new? and imap-reset-new! to detect when new messages are available in the currently selected mailbox.
procedure
(imap-mailbox-exists? imap mailbox) → boolean?
imap : imap-connection? mailbox : (or/c string? bytes?)
procedure
(imap-create-mailbox imap mailbox) → void?
imap : imap-connection? mailbox : (or/c string? bytes?)
procedure
(imap-list-child-mailboxes imap mailbox [ delimiter]) → (listof (list/c (listof symbol?) bytes?)) imap : imap-connection? mailbox : (or/c string? bytes? #f)
delimiter : (or/c string? bytes?) = (imap-get-hierarchy-delimiter)
The return value is a list of mailbox-information lists. Each mailbox-information list contains two items:
a list of imap flags for the mailbox
the mailbox’s name
procedure
(imap-get-hierarchy-delimiter imap) → bytes?
imap : imap-connection?
procedure
(imap-mailbox-flags imap mailbox) → (listof symbol?)
imap : imap-connection? mailbox : (or/c string? bytes?)
10.5 IMAP Unit
imap@ and imap^ are deprecated. They exist for backward-compatibility and will likely be removed in the future. New code should use the net/imap module.
(require net/imap-unit) | package: compatibility-lib |
10.6 IMAP Signature
(require net/imap-sig) | package: compatibility-lib |
signature
imap^ : signature
Includes everything exported by the net/imap module.