Based on https://busylog.net/telnet-imap-commands-note/
- -k -- don't verify certificate (optional)
- -n -- use .netrc for username and password (optional)
- -X -- request to send to server
curl -n imaps://mail.server.tld -X 'imap command'
machine mail.server.tld login username password supersecretpw
machine mail.server.tld
login username
password supersecretpw
- tls -- imaps://
- plain -- imap://
Note: enclose url in quotes if your user id or password have shell characters
curl -n imaps://mail.server.tld -X 'STATUS INBOX (MESSAGES)'
* STATUS INBOX (MESSAGES 36)
curl -n imaps://mail.server.tld -X 'STATUS INBOX (UNSEEN)'
* STATUS INBOX (UNSEEN 20)
curl -n imaps://mail.server.tld -X 'STATUS Archive.2016 (MESSAGES)'
* STATUS Archive.2016 (MESSAGES 3069)
curl -n imaps://mail.server.tld -X 'STATUS INBOX (RECENT)'
* STATUS INBOX (RECENT 0)
curl -n imaps://mail.server.tld -X 'LIST "" "*"'
* LIST (\HasNoChildren \Drafts) "." Drafts
* LIST (\HasChildren) "." Archive
* LIST (\HasNoChildren) "." Archive.2013
* LIST (\HasNoChildren) "." Archive.2014
* LIST (\HasNoChildren) "." Archive.2015
* LIST (\HasNoChildren) "." Archive.2016
* LIST (\HasChildren) "." Archive.old_account
* LIST (\HasNoChildren) "." Archive.old_account.sent
* LIST (\HasNoChildren \Junk) "." Junk
* LIST (\HasNoChildren \Sent) "." "Sent Messages"
* LIST (\HasNoChildren \Trash) "." Trash
* LIST (\HasNoChildren) "." INBOX
This one wasn't easy. I wanted to remove all mails which are older than 90 days from the trash bin. After several tries I found out that the folder name returned bei
LIST
is "Gel&APY-schte Elemente" and to use it in--url
it must be urlencoded as follows:This is the final code:
Attention:
%b
of thedate
command could return a localized string. To force english output you should addexport LC_ALL=C
to the top of your script.