Send/receive commands to/from an IMAP server. More...
#include "config.h"
#include <ctype.h>
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.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 "adata.h"
#include "commands.h"
#include "edata.h"
#include "mdata.h"
#include "msn.h"
#include "mutt_account.h"
#include "mutt_logging.h"
#include "mx.h"
Go to the source code of this file.
Macros | |
#define | IMAP_CMD_BUFSIZE 512 |
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.
|
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 112 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 144 of file command.c.
|
static |
When ImapAccountData is in fatal state, do what we can.
adata | Imap Account data |
Definition at line 170 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 204 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 240 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 260 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 307 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 401 of file command.c.
|
static |
Set capability bits according to CAPABILITY response.
Definition at line 545 of file command.c.
|
static |
Parse a server LIST command (list mailboxes)
Definition at line 578 of file command.c.
|
static |
Parse a server LSUB (list subscribed mailboxes)
Definition at line 672 of file command.c.
|
static |
Set rights bits according to MYRIGHTS response.
Definition at line 720 of file command.c.
|
static |
|
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 812 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 979 of file command.c.
|
static |
Fallback parser for otherwise unhandled messages.
adata | Imap Account data |
0 | Success |
-1 | Failure |
Definition at line 1019 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 1115 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 1129 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 1267 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 1304 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 1369 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 1436 of file command.c.
|
static |
Server capabilities strings that we understand.