curl:perform_imap_queries_using_curl
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
curl:perform_imap_queries_using_curl [2016/11/16 16:40] – peter | curl:perform_imap_queries_using_curl [2020/09/25 13:02] (current) – 192.168.1.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Curl - Perform imap queries using Curl ====== | ====== Curl - Perform imap queries using Curl ====== | ||
- | If you have an IMAP or IMAPS server you can "read your email" using Curl. To get started you'll first of all need to know: | + | If you have an IMAP or IMAPS server you can "read your email" using Curl. To get started you'll first of all need to know: |
* Your mail-server address. | * Your mail-server address. | ||
* Your mail login. | * Your mail login. | ||
* Your mail password. | * Your mail password. | ||
+ | |||
+ | ---- | ||
===== Listing Folders ===== | ===== Listing Folders ===== | ||
Line 16: | Line 18: | ||
<WRAP info> | <WRAP info> | ||
- | If you leave out the password from the --user argument, curl will prompt you for the password before it preforms the request. This way you're not leaking your password to your shell history or the process list. | + | If you leave out the password from the **< |
- | Curl also supports .netrc lookup of user: | + | Curl also supports .netrc lookup of user: |
</ | </ | ||
+ | returns | ||
- | Returns | + | < |
- | + | ||
- | < | + | |
.. | .. | ||
.. | .. | ||
Line 35: | Line 36: | ||
Here we see that we've connected, and received a list of folders, including " | Here we see that we've connected, and received a list of folders, including " | ||
- | If your mail-server is running over SSL then instead of using **imap://** you should set the schema to **imaps:// | + | If your mail-server is running over SSL then instead of using **< |
This would look like so: | This would look like so: | ||
Line 43: | Line 44: | ||
</ | </ | ||
+ | ---- | ||
===== Discovering Messages ===== | ===== Discovering Messages ===== | ||
- | With the previous example we looked at listing mailboxes. | + | With the previous example we looked at listing mailboxes. |
+ | |||
+ | To fetch a message we need the identifier of the message to fetch - so we need to find out how many messages exist, as message-IDs are sequential. | ||
To see how many messages exist in the folder " | To see how many messages exist in the folder " | ||
Line 57: | Line 61: | ||
</ | </ | ||
- | Returns | + | returns: |
- | < | + | < |
* OK [PERMANENTFLAGS ()] Read-only mailbox. | * OK [PERMANENTFLAGS ()] Read-only mailbox. | ||
* 9465 EXISTS | * 9465 EXISTS | ||
Line 69: | Line 73: | ||
This tells us that there are 9465 messages. | This tells us that there are 9465 messages. | ||
+ | ---- | ||
===== Fetching A Single Message ===== | ===== Fetching A Single Message ===== | ||
Line 82: | Line 87: | ||
</ | </ | ||
- | Returns | + | returns: |
- | < | + | < |
.. | .. | ||
X-HELO: mail.cs.helsinki.fi | X-HELO: mail.cs.helsinki.fi | ||
Line 103: | Line 108: | ||
</ | </ | ||
- | Returns | + | returns: |
- | < | + | < |
Date: Sat, 14 Apr 2012 14:13:41 +0300 (EEST) | Date: Sat, 14 Apr 2012 14:13:41 +0300 (EEST) | ||
From: Steve Kemp < | From: Steve Kemp < | ||
Line 114: | Line 119: | ||
We could have avoided the use of URL-encoding and instead sent a custom-request, | We could have avoided the use of URL-encoding and instead sent a custom-request, | ||
- | < | + | < |
curl --insecure --verbose \ | curl --insecure --verbose \ | ||
--url " | --url " | ||
Line 121: | Line 126: | ||
</ | </ | ||
- | Returns | + | returns: |
- | < | + | < |
.. | .. | ||
Subject: Re: Fancy a cake? | Subject: Re: Fancy a cake? | ||
Line 131: | Line 136: | ||
The reason for avoiding custom-requests where possible is that when you're using the curl API programatically you'll discover that responses are not decoded - which is a known issue. | The reason for avoiding custom-requests where possible is that when you're using the curl API programatically you'll discover that responses are not decoded - which is a known issue. | ||
- | In the example above we'd have received zero output unless/ | + | In the example above we'd have received zero output unless/ |
+ | ---- | ||
===== Simple Shell Scripts ===== | ===== Simple Shell Scripts ===== | ||
Line 152: | Line 158: | ||
This takes no account of the maximum message-ID. | This takes no account of the maximum message-ID. | ||
- | < | + | < |
#!/bin/sh | #!/bin/sh | ||
# Dump the subject of all messages in the folder. | # Dump the subject of all messages in the folder. | ||
Line 167: | Line 173: | ||
</ | </ | ||
+ | ---- | ||
===== CurlMail Script ===== | ===== CurlMail Script ===== | ||
Line 186: | Line 193: | ||
function cleanup { | function cleanup { | ||
- | if [ -e /tmp/$$ ]; then | + | |
- | rm / | + | rm / |
- | fi | + | fi |
} | } | ||
Line 196: | Line 203: | ||
0) | 0) | ||
- | exec $0 `hostname` # | + | |
- | exit -1 # | + | exit -1 # exec doesn' |
- | ;; | + | ;; |
1) | 1) | ||
- | case " | + | |
- | -v) | + | -v) |
- | tail -n +4 $0 | head -n 1 | + | tail -n +4 $0 | head -n 1 |
- | ;; | + | |
- | --version) | + | |
- | tail -n +4 $0 | head -n 1 | + | |
- | ;; | + | |
- | -h) | + | |
- | head -n $help $0 | tail -n +6 | + | |
- | ;; | + | |
- | --help) | + | |
- | head -n $help $0 | tail -n +6 | + | |
- | ;; | + | |
- | *) | + | |
- | let uid=0 | + | |
- | while let uid=$uid+1 | + | |
- | do # iterate available messages | + | |
- | echo -n " | + | |
- | chmod 600 | + | |
- | curl -# --insecure -n --url \ | + | |
- | " | + | |
- | done | + | |
- | sed ' | + | |
- | rm | + | |
- | ;; | + | |
- | esac | + | |
- | exit | + | |
;; | ;; | ||
- | *) | + | |
- | server=" | + | tail -n +4 $0 | head -n 1 |
- | shift | + | |
- | while [ $# != 0 ] | + | |
- | do # iterate requested messages | + | |
- | message=`echo " | + | |
- | shift | + | |
- | rm | + | |
- | echo | + | |
- | chmod 600 | + | |
- | curl -# --insecure | + | |
- | sed ' | + | |
- | rm | + | |
- | done | + | |
- | exit | + | |
;; | ;; | ||
+ | -h) | ||
+ | head -n $help $0 | tail -n +6 | ||
+ | ;; | ||
+ | --help) | ||
+ | head -n $help $0 | tail -n +6 | ||
+ | ;; | ||
+ | *) | ||
+ | let uid=0 | ||
+ | while let uid=$uid+1 | ||
+ | do # iterate available messages | ||
+ | echo -n " | ||
+ | chmod 600 | ||
+ | curl -# --insecure -n --url \ | ||
+ | " | ||
+ | done | ||
+ | sed ' | ||
+ | rm | ||
+ | ;; | ||
+ | esac | ||
+ | exit | ||
+ | ;; | ||
+ | *) | ||
+ | server=" | ||
+ | shift | ||
+ | while [ $# != 0 ] | ||
+ | do # iterate requested messages | ||
+ | message=`echo " | ||
+ | shift | ||
+ | rm | ||
+ | echo -n " | ||
+ | chmod 600 | ||
+ | curl -# --insecure -n --url " | ||
+ | sed ' | ||
+ | rm | ||
+ | done | ||
+ | exit | ||
+ | ;; | ||
esac | esac | ||
</ | </ | ||
+ | |||
+ | ---- | ||
+ | |||
+ | ===== References ===== | ||
+ | |||
+ | http:// | ||
+ |
curl/perform_imap_queries_using_curl.1479314403.txt.gz · Last modified: 2020/07/15 09:30 (external edit)