Send/receive commands to/from an IMAP server. More...
#include "config.h"#include <errno.h>#include <limits.h>#include <stdbool.h>#include <stdint.h>#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include <unistd.h>#include "private.h"#include "mutt/lib.h"#include "config/lib.h"#include "email/lib.h"#include "core/lib.h"#include "conn/lib.h"#include "commands/lib.h"#include "adata.h"#include "edata.h"#include "mdata.h"#include "msn.h"Go to the source code of this file.
Macros | |
| #define | IMAP_CMD_BUFSIZE 512 |
| Default buffer size for IMAP commands. | |
| #define | IMAP_MAX_RETRIES 5 |
| Maximum number of reconnection attempts before giving up. | |
| #define | IMAP_MAX_BACKOFF 30 |
| Maximum backoff delay in seconds between reconnection attempts. | |
| #define | IMAP_CONN_STALE_THRESHOLD 300 |
| Threshold in seconds after which to consider a connection potentially stale. | |
Functions | |
| static bool | cmd_queue_full (struct ImapAccountData *adata) |
| Is the IMAP command queue full? | |
| static struct ImapCommand * | cmd_new (struct ImapAccountData *adata) |
| Create and queue a new command control block. | |
| static int | cmd_queue (struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags) |
| Add a IMAP command to the queue. | |
| static void | cmd_handle_fatal (struct ImapAccountData *adata) |
| When ImapAccountData is in fatal state, do what we can. | |
| static int | cmd_start (struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags) |
| Start a new IMAP command. | |
| static int | cmd_status (const char *s) |
| Parse response line for tagged OK/NO/BAD. | |
| static void | cmd_parse_expunge (struct ImapAccountData *adata, const char *s) |
| Parse expunge command. | |
| static void | cmd_parse_vanished (struct ImapAccountData *adata, char *s) |
| Parse vanished command. | |
| static void | cmd_parse_fetch (struct ImapAccountData *adata, char *s) |
| Load fetch response into ImapAccountData. | |
| static void | cmd_parse_capability (struct ImapAccountData *adata, char *s) |
| Set capability bits according to CAPABILITY response. | |
| static void | cmd_parse_list (struct ImapAccountData *adata, char *s) |
| Parse a server LIST command (list mailboxes). | |
| static void | cmd_parse_lsub (struct ImapAccountData *adata, char *s) |
| Parse a server LSUB (list subscribed mailboxes). | |
| static void | cmd_parse_myrights (struct ImapAccountData *adata, const char *s) |
| Set rights bits according to MYRIGHTS response. | |
| static struct Mailbox * | find_mailbox (struct ImapAccountData *adata, const char *name) |
| Find a Mailbox by its name. | |
| static void | cmd_parse_status (struct ImapAccountData *adata, char *s) |
| Parse status from server. | |
| static void | cmd_parse_enabled (struct ImapAccountData *adata, const char *s) |
| Record what the server has enabled. | |
| static void | cmd_parse_exists (struct ImapAccountData *adata, const char *pn) |
| Parse EXISTS message from serer. | |
| static int | cmd_handle_untagged (struct ImapAccountData *adata) |
| Fallback parser for otherwise unhandled messages. | |
| int | imap_cmd_start (struct ImapAccountData *adata, const char *cmdstr) |
| Given an IMAP command, send it to the server. | |
| int | imap_cmd_step (struct ImapAccountData *adata) |
| Reads server responses from an IMAP command. | |
| bool | imap_code (const char *s) |
| Was the command successful. | |
| const char * | imap_cmd_trailer (struct ImapAccountData *adata) |
| Extra information after tagged command response if any. | |
| int | imap_exec (struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags) |
| Execute a command and wait for the response from the server. | |
| void | imap_cmd_finish (struct ImapAccountData *adata) |
| Attempt to perform cleanup. | |
| int | imap_cmd_idle (struct ImapAccountData *adata) |
| Enter the IDLE state. | |
Variables | |
| static const char *const | Capabilities [] |
| Server capabilities strings that we understand. | |
Send/receive commands to/from an IMAP server.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file command.c.
| #define IMAP_CMD_BUFSIZE 512 |
| #define IMAP_MAX_RETRIES 5 |
| #define IMAP_MAX_BACKOFF 30 |
| #define IMAP_CONN_STALE_THRESHOLD 300 |
|
static |
|
static |
Create and queue a new command control block.
| adata | Imap Account data |
| NULL | The pipeline is full |
| ptr | New command |
Definition at line 122 of file command.c.
|
static |
Add a IMAP command to the queue.
| adata | Imap Account data |
| cmdstr | Command string |
| flags | Server flags, see ImapCmdFlags |
| 0 | Success |
| <0 | Failure, e.g. IMAP_RES_BAD |
If the queue is full, attempts to drain it.
Definition at line 154 of file command.c.
|
static |
When ImapAccountData is in fatal state, do what we can.
| adata | Imap Account data |
Attempts to reconnect using exponential backoff (1s, 2s, 4s, 8s... max 30s). Gives up after IMAP_MAX_RETRIES consecutive failures.
Definition at line 183 of file command.c.
|
static |
Start a new IMAP command.
| adata | Imap Account data |
| cmdstr | Command string |
| flags | Command flags, see ImapCmdFlags |
| 0 | Success |
| <0 | Failure, e.g. IMAP_RES_BAD |
Definition at line 270 of file command.c.
|
static |
Parse response line for tagged OK/NO/BAD.
| s | Status string from server |
| 0 | Success |
| <0 | Failure, e.g. IMAP_RES_BAD |
Definition at line 306 of file command.c.
|
static |
Parse expunge command.
| adata | Imap Account data |
| s | String containing MSN of message to expunge |
cmd_parse_expunge: mark headers with new sequence ID and mark adata to be reopened at our earliest convenience
Definition at line 326 of file command.c.
|
static |
Parse vanished command.
| adata | Imap Account data |
| s | String containing MSN of message to expunge |
Handle VANISHED (RFC7162), which is like expunge, but passes a seqset of UIDs. An optional (EARLIER) argument specifies not to decrement subsequent MSNs.
Definition at line 385 of file command.c.
|
static |
Load fetch response into ImapAccountData.
| adata | Imap Account data |
| s | String containing MSN of message to fetch |
Currently only handles unanticipated FETCH responses, and only FLAGS data. We get these if another client has changed flags for a mailbox we've selected. Of course, a lot of code here duplicates code in message.c.
Definition at line 484 of file command.c.
|
static |
Set capability bits according to CAPABILITY response.
Definition at line 636 of file command.c.
|
static |
Parse a server LIST command (list mailboxes).
Definition at line 669 of file command.c.
|
static |
Parse a server LSUB (list subscribed mailboxes).
Definition at line 763 of file command.c.
|
static |
Set rights bits according to MYRIGHTS response.
Definition at line 811 of file command.c.
|
static |
Find a Mailbox by its name.
| ptr | Mailbox |
Definition at line 882 of file command.c.
|
static |
Parse status from server.
first cut: just do mailbox update. Later we may wish to cache all mailbox information, even that not desired by mailbox
Definition at line 908 of file command.c.
|
static |
|
static |
Parse EXISTS message from serer.
| adata | Imap Account data |
| pn | String containing the total number of messages for the selected mailbox |
Definition at line 1075 of file command.c.
|
static |
Fallback parser for otherwise unhandled messages.
| adata | Imap Account data |
| 0 | Success |
| -1 | Failure |
Definition at line 1120 of file command.c.
| int imap_cmd_start | ( | struct ImapAccountData * | adata, |
| const char * | cmdstr ) |
Given an IMAP command, send it to the server.
| 0 | Success |
| <0 | Failure, e.g. IMAP_RES_BAD |
If cmdstr is NULL, sends queued commands.
Definition at line 1216 of file command.c.
| int imap_cmd_step | ( | struct ImapAccountData * | adata | ) |
Reads server responses from an IMAP command.
| adata | Imap Account data |
| 0 | Success |
| <0 | Failure, e.g. IMAP_RES_BAD |
detects tagged completion response, handles untagged messages, can read arbitrarily large strings (using malloc, so don't make it too large!).
Definition at line 1230 of file command.c.
| bool imap_code | ( | const char * | s | ) |
| const char * imap_cmd_trailer | ( | struct ImapAccountData * | adata | ) |
Extra information after tagged command response if any.
| adata | Imap Account data |
| ptr | Extra command information (pointer into adata->buf) |
| "" | Error (static string) |
Definition at line 1383 of file command.c.
| int imap_exec | ( | struct ImapAccountData * | adata, |
| const char * | cmdstr, | ||
| ImapCmdFlags | flags ) |
Execute a command and wait for the response from the server.
| adata | Imap Account data |
| cmdstr | Command to execute |
| flags | Flags, see ImapCmdFlags |
| IMAP_EXEC_SUCCESS | Command successful or queued |
| IMAP_EXEC_ERROR | Command returned an error |
| IMAP_EXEC_FATAL | Imap connection failure |
Also, handle untagged responses.
Definition at line 1420 of file command.c.
| void imap_cmd_finish | ( | struct ImapAccountData * | adata | ) |
Attempt to perform cleanup.
| adata | Imap Account data |
If a reopen is allowed, it attempts to perform cleanup (eg fetch new mail if detected, do expunge). Called automatically by imap_cmd_step(), but may be called at any time.
mdata->check_status is set and will be used later by imap_check_mailbox().
Definition at line 1511 of file command.c.
| int imap_cmd_idle | ( | struct ImapAccountData * | adata | ) |
Enter the IDLE state.
| adata | Imap Account data |
| 0 | Success |
| <0 | Failure, e.g. IMAP_RES_BAD |
Definition at line 1586 of file command.c.
|
static |
Server capabilities strings that we understand.
Definition at line 78 of file command.c.