Skip to content

Commit 6b998fb

Browse files
committed
usingcurl/reademail.md: flesh out IMAP section
1 parent 09c5287 commit 6b998fb

File tree

2 files changed

+65
-8
lines changed

2 files changed

+65
-8
lines changed

usingcurl/reademail.md

Lines changed: 64 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,21 +21,77 @@ To delete message 1:
2121

2222
## IMAP
2323

24-
Get the mail using the UID 57 from mailbox 'stuff':
24+
For clarity, server authentication with `--username` / `-u` is elided, and
25+
(while usually not required) IMAP commands and their arguments are upper-cased.
26+
For reasons noted below, you will probably want to include curl's `-v` or
27+
`--verbose` option when initially tinkering with its IMAP support.
2528

26-
curl imap://server.example.com/stuff;UID=57
29+
List (sub)mailboxes in the main inbox:
2730

28-
Instead, get the mail with index 57 from the mailbox 'fun':
31+
curl imap://server.example.com
2932

30-
curl imap://server.example.com/fun;MAILINDEX=57
33+
List (sub)mailboxes in the mailbox `boring`, with the IMAP server on a
34+
non-standard port number:
3135

32-
List the mails in the mailbox 'boring':
36+
curl imap://server.example.com:1143/boring
3337

34-
curl imap://server.example.com/boring
38+
List all emails in the inbox:
3539

36-
List the mails in the mailbox 'boring' and provide user and password:
40+
# use quotes appropriate to your shell here to preserve internal whitespace
41+
curl imap://server.example.com:1143/INBOX -X 'FETCH 1:* FAST'
3742

38-
curl imap://server.example.com/boring -u user:password
43+
This produces output similar to what's below; the numbers after the asterisks
44+
are the **mailbox indices** of the messages, counting from 1:
45+
46+
* 1 FETCH (FLAGS (\Flagged \Deleted \Seen) INTERNALDATE " 3-Dec-2025 12:02:39 -0500" RFC822.SIZE 15163)
47+
* 2 FETCH (FLAGS (\Deleted \Seen) INTERNALDATE " 6-Dec-2025 09:01:30 -0500" RFC822.SIZE 26862)
48+
* 3 FETCH (FLAGS (\Seen nonjunk $label1) INTERNALDATE "10-Sep-2025 12:09:16 -0400" RFC822.SIZE 11713)
49+
...
50+
51+
To retrieve message UIDs, needed for `FETCH` and
52+
[similar commands](#imap-fetch-message), try this:
53+
54+
curl imap://server.example.com:1143/INBOX -X 'FETCH 1:* UID'
55+
56+
See IETF [RFC 3501](https://datatracker.ietf.org/doc/html/rfc3501) or later
57+
RFCs for details and other available commands.
58+
59+
### Fetching individual messages from IMAP {#imap-fetch-message}
60+
61+
Get the message having UID 57 from mailbox `stuff`. Many shells will require
62+
you to quote or escape the semicolon, thus:
63+
64+
curl 'imap://server.example.com/stuff;UID=57'
65+
66+
Get the 57<sup>th</sup> message from the mailbox `fun`:
67+
68+
curl 'imap://server.example.com/fun;MAILINDEX=57'
69+
70+
Be aware that deleted but not "expunged" messages still have an index!
71+
72+
Note that `FETCH`es will probably not do what you initially expect; see
73+
[bug #536](https://github.com/curl/curl/issues/536). For example:
74+
75+
curl 'imap://server.example.com/stuff' -X 'FETCH 1 BODY.PEEK[]'
76+
77+
yields only
78+
79+
* 1 FETCH (BODY[] {11713}
80+
81+
…rather than the full message body you were expecting. As a workaround, add the
82+
`-v` / `--verbose` option to your `curl` invocation, which prints the `BODY` to
83+
standard error.
84+
85+
Here are a few handy other handy `FETCH` commands:
86+
87+
# get flags, date, and message size for all messages in 'stuff'
88+
curl -sv 'imap://server.example.com/stuff' -X 'FETCH 1 FAST'
89+
90+
# get UID, size, and 1024 bytes of message body (which includes headers)
91+
curl -sv 'imap://server.example.com/stuff' -X 'FETCH 1 (UID RFC822.SIZE BODY.PEEK[]<0.1024>)'
92+
93+
See [RFC 3501 § 6.4.5](https://datatracker.ietf.org/doc/html/rfc3501#section-6.4.5)
94+
for details of the `FETCH` command.
3995

4096
## TLS for emails
4197

wordlist.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,7 @@ typedefed
551551
UDP
552552
UI
553553
UID
554+
UIDs
554555
Unary
555556
uncompress
556557
unencrypted

0 commit comments

Comments
 (0)