IMAP network mailbox. More...
#include "config.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 "mutt.h"
#include "lib.h"
#include "enter/lib.h"
#include "parse/lib.h"
#include "progress/lib.h"
#include "question/lib.h"
#include "adata.h"
#include "auth.h"
#include "commands.h"
#include "edata.h"
#include "external.h"
#include "hook.h"
#include "mdata.h"
#include "msn.h"
#include "mutt_logging.h"
#include "mutt_socket.h"
#include "muttlib.h"
#include "mx.h"
#include "sort.h"
#include <libintl.h>
Go to the source code of this file.
Functions | |
void | imap_init (void) |
Setup feature commands. More... | |
static int | check_capabilities (struct ImapAccountData *adata) |
Make sure we can log in to this server. More... | |
static char * | get_flags (struct ListHead *hflags, char *s) |
Make a simple list out of a FLAGS response. More... | |
static void | set_flag (struct Mailbox *m, AclFlags aclflag, bool flag, const char *str, char *flags, size_t flsize) |
Append str to flags if we currently have permission according to aclflag. More... | |
static int | make_msg_set (struct Mailbox *m, struct Buffer *buf, enum MessageType flag, bool changed, bool invert, int *pos) |
Make a message set. More... | |
static bool | compare_flags_for_copy (struct Email *e) |
Compare local flags against the server. More... | |
static int | sync_helper (struct Mailbox *m, AclFlags right, enum MessageType flag, const char *name) |
Sync flag changes to the server. More... | |
static size_t | longest_common_prefix (char *dest, const char *src, size_t start, size_t dlen) |
Find longest prefix common to two strings. More... | |
static int | complete_hosts (char *buf, size_t buflen) |
Look for completion matches for mailboxes. More... | |
int | imap_create_mailbox (struct ImapAccountData *adata, const char *mailbox) |
Create a new mailbox. More... | |
int | imap_access (const char *path) |
Check permissions on an IMAP mailbox with a new connection. More... | |
int | imap_rename_mailbox (struct ImapAccountData *adata, char *oldname, const char *newname) |
Rename a mailbox. More... | |
int | imap_delete_mailbox (struct Mailbox *m, char *path) |
Delete a mailbox. More... | |
static void | imap_logout (struct ImapAccountData *adata) |
Gracefully log out of server. More... | |
void | imap_logout_all (void) |
Close all open connections. More... | |
int | imap_read_literal (FILE *fp, struct ImapAccountData *adata, unsigned long bytes, struct Progress *progress) |
Read bytes bytes from server into file. More... | |
void | imap_notify_delete_email (struct Mailbox *m, struct Email *e) |
Inform IMAP that an Email has been deleted. More... | |
void | imap_expunge_mailbox (struct Mailbox *m, bool resort) |
Purge messages from the server. More... | |
int | imap_open_connection (struct ImapAccountData *adata) |
Open an IMAP connection. More... | |
void | imap_close_connection (struct ImapAccountData *adata) |
Close an IMAP connection. More... | |
bool | imap_has_flag (struct ListHead *flag_list, const char *flag) |
Does the flag exist in the list. More... | |
static int | compare_uid (const void *a, const void *b) |
Compare two Emails by UID - Implements sort_t -. More... | |
int | imap_exec_msgset (struct Mailbox *m, const char *pre, const char *post, enum MessageType flag, bool changed, bool invert) |
Prepare commands for all messages matching conditions. More... | |
int | imap_sync_message_for_copy (struct Mailbox *m, struct Email *e, struct Buffer *cmd, enum QuadOption *err_continue) |
Update server to reflect the flags of a single message. More... | |
enum MxStatus | imap_check_mailbox (struct Mailbox *m, bool force) |
Use the NOOP or IDLE command to poll for new mail. More... | |
static int | imap_status (struct ImapAccountData *adata, struct ImapMboxData *mdata, bool queue) |
Refresh the number of total and new messages. More... | |
static enum MxStatus | imap_mbox_check_stats (struct Mailbox *m, uint8_t flags) |
Check the Mailbox statistics - Implements MxOps::mbox_check_stats() -. More... | |
int | imap_path_status (const char *path, bool queue) |
Refresh the number of total and new messages. More... | |
int | imap_mailbox_status (struct Mailbox *m, bool queue) |
Refresh the number of total and new messages. More... | |
int | imap_subscribe (char *path, bool subscribe) |
Subscribe to a mailbox. More... | |
int | imap_complete (char *buf, size_t buflen, const char *path) |
Try to complete an IMAP folder path. More... | |
int | imap_fast_trash (struct Mailbox *m, const char *dest) |
Use server COPY command to copy deleted messages to trash. More... | |
enum MxStatus | imap_sync_mailbox (struct Mailbox *m, bool expunge, bool close) |
Sync all the changes to the server. More... | |
static bool | imap_ac_owns_path (struct Account *a, const char *path) |
Check whether an Account owns a Mailbox path - Implements MxOps::ac_owns_path() -. More... | |
static bool | imap_ac_add (struct Account *a, struct Mailbox *m) |
Add a Mailbox to an Account - Implements MxOps::ac_add() -. More... | |
static void | imap_mbox_select (struct Mailbox *m) |
Select a Mailbox. More... | |
int | imap_login (struct ImapAccountData *adata) |
Open an IMAP connection. More... | |
static enum MxOpenReturns | imap_mbox_open (struct Mailbox *m) |
Open a mailbox - Implements MxOps::mbox_open() -. More... | |
static bool | imap_mbox_open_append (struct Mailbox *m, OpenMailboxFlags flags) |
Open a Mailbox for appending - Implements MxOps::mbox_open_append() -. More... | |
static enum MxStatus | imap_mbox_check (struct Mailbox *m) |
Check for new mail - Implements MxOps::mbox_check() -. More... | |
static enum MxStatus | imap_mbox_close (struct Mailbox *m) |
Close a Mailbox - Implements MxOps::mbox_close() -. More... | |
static bool | imap_msg_open_new (struct Mailbox *m, struct Message *msg, const struct Email *e) |
Open a new message in a Mailbox - Implements MxOps::msg_open_new() -. More... | |
static int | imap_tags_edit (struct Mailbox *m, const char *tags, struct Buffer *buf) |
Prompt and validate new messages tags - Implements MxOps::tags_edit() -. More... | |
static int | imap_tags_commit (struct Mailbox *m, struct Email *e, const char *buf) |
Save the tags to a message - Implements MxOps::tags_commit() -. More... | |
enum MailboxType | imap_path_probe (const char *path, const struct stat *st) |
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -. More... | |
int | imap_path_canon (char *buf, size_t buflen) |
Canonicalise a Mailbox path - Implements MxOps::path_canon() -. More... | |
int | imap_expand_path (struct Buffer *buf) |
Buffer wrapper around imap_path_canon() More... | |
static int | imap_path_pretty (char *buf, size_t buflen, const char *folder) |
Abbreviate a Mailbox path - Implements MxOps::path_pretty() -. More... | |
static int | imap_path_parent (char *buf, size_t buflen) |
Find the parent of a Mailbox path - Implements MxOps::path_parent() -. More... | |
static int | imap_path_is_empty (const char *path) |
Is the mailbox empty - Implements MxOps::path_is_empty() -. More... | |
Variables | |
static const struct Command | ImapCommands [] |
Imap Commands. More... | |
struct MxOps | MxImapOps |
IMAP Mailbox - Implements MxOps -. More... | |
IMAP network mailbox.
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 imap.c.
void imap_init | ( | void | ) |
Setup feature commands.
Definition at line 86 of file imap.c.
|
static |
Make sure we can log in to this server.
adata | Imap Account data |
0 | Success |
-1 | Failure |
Definition at line 97 of file imap.c.
|
static |
Make a simple list out of a FLAGS response.
hflags | List to store flags |
s | String containing flags |
ptr | End of the flags |
NULL | Failure |
return stream following FLAGS response
Definition at line 123 of file imap.c.
|
static |
Append str to flags if we currently have permission according to aclflag.
[in] | m | Selected Imap Mailbox |
[in] | aclflag | Permissions, see AclFlags |
[in] | flag | Does the email have the flag set? |
[in] | str | Server flag name |
[out] | flags | Buffer for server command |
[in] | flsize | Length of buffer |
Definition at line 178 of file imap.c.
|
static |
Make a message set.
[in] | m | Selected Imap Mailbox |
[in] | buf | Buffer to store message set |
[in] | flag | Flags to match, e.g. MUTT_DELETED |
[in] | changed | Matched messages that have been altered |
[in] | invert | Flag matches should be inverted |
[out] | pos | Cursor used for multiple calls to this function |
num | Messages in the set |
Definition at line 199 of file imap.c.
|
static |
Compare local flags against the server.
e |
true | Flags have changed |
false | Flags match cached server flags |
The comparison of flags EXCLUDES the deleted flag.
Definition at line 300 of file imap.c.
|
static |
Sync flag changes to the server.
m | Selected Imap Mailbox |
right | ACL, see AclFlags |
flag | NeoMutt flag, e.g. MUTT_DELETED |
name | Name of server flag |
>=0 | Success, number of messages |
-1 | Failure |
Definition at line 325 of file imap.c.
|
static |
Find longest prefix common to two strings.
dest | Destination buffer |
src | Source buffer |
start | Starting offset into string |
dlen | Destination buffer length |
num | Length of the common string |
Trim dest to the length of the longest prefix it shares with src.
Definition at line 366 of file imap.c.
|
static |
Look for completion matches for mailboxes.
buf | Partial mailbox name to complete |
buflen | Length of buffer |
0 | Success |
-1 | Failure |
look for IMAP URLs to complete from defined mailboxes. Could be extended to complete over open connections and account/folder hooks too.
Definition at line 387 of file imap.c.
int imap_create_mailbox | ( | struct ImapAccountData * | adata, |
const char * | mailbox | ||
) |
Create a new mailbox.
0 | Success |
-1 | Failure |
Definition at line 453 of file imap.c.
int imap_access | ( | const char * | path | ) |
Check permissions on an IMAP mailbox with a new connection.
path | Mailbox path |
0 | Success |
<0 | Failure |
TODO: ACL checks. Right now we assume if it exists we can mess with it. TODO: This method should take a Mailbox as parameter to be able to reuse the existing connection.
Definition at line 479 of file imap.c.
int imap_rename_mailbox | ( | struct ImapAccountData * | adata, |
char * | oldname, | ||
const char * | newname | ||
) |
Rename a mailbox.
adata | Imap Account data |
oldname | Existing mailbox |
newname | New name for mailbox |
0 | Success |
-1 | Failure |
Definition at line 494 of file imap.c.
int imap_delete_mailbox | ( | struct Mailbox * | m, |
char * | path | ||
) |
|
static |
Gracefully log out of server.
adata | Imap Account data |
Definition at line 541 of file imap.c.
void imap_logout_all | ( | void | ) |
Close all open connections.
Quick and dirty until we can make sure we've got all the context we need.
Definition at line 568 of file imap.c.
int imap_read_literal | ( | FILE * | fp, |
struct ImapAccountData * | adata, | ||
unsigned long | bytes, | ||
struct Progress * | progress | ||
) |
Read bytes bytes from server into file.
fp | File handle for email file |
adata | Imap Account data |
bytes | Number of bytes to read |
progress | Progress bar |
0 | Success |
-1 | Failure |
Not explicitly buffered, relies on FILE buffering.
\r
from \r\n
. Apparently even literals use \r\n
-terminated strings ?! Definition at line 604 of file imap.c.
Inform IMAP that an Email has been deleted.
Definition at line 662 of file imap.c.
void imap_expunge_mailbox | ( | struct Mailbox * | m, |
bool | resort | ||
) |
Purge messages from the server.
m | Mailbox |
resort | Trigger a resort? |
Purge IMAP portion of expunged messages from the context. Must not be done while something has a handle on any headers (eg inside pager or editor). That is, check IMAP_REOPEN_ALLOW.
Definition at line 683 of file imap.c.
int imap_open_connection | ( | struct ImapAccountData * | adata | ) |
Open an IMAP connection.
adata | Imap Account data |
0 | Success |
-1 | Failure |
Definition at line 755 of file imap.c.
void imap_close_connection | ( | struct ImapAccountData * | adata | ) |
Close an IMAP connection.
adata | Imap Account data |
Definition at line 863 of file imap.c.
bool imap_has_flag | ( | struct ListHead * | flag_list, |
const char * | flag | ||
) |
Does the flag exist in the list.
flag_list | List of server flags |
flag | Flag to find |
true | Flag exists |
Do a caseless comparison of the flag against a flag list, return true if found or flag list has '*'. Note that "flag" might contain additional whitespace at the end, so we really need to compare up to the length of each element in "flag_list".
Definition at line 888 of file imap.c.
int imap_exec_msgset | ( | struct Mailbox * | m, |
const char * | pre, | ||
const char * | post, | ||
enum MessageType | flag, | ||
bool | changed, | ||
bool | invert | ||
) |
Prepare commands for all messages matching conditions.
m | Selected Imap Mailbox |
pre | prefix commands |
post | postfix commands |
flag | flag type on which to filter, e.g. MUTT_REPLIED |
changed | include only changed messages in message set |
invert | invert sense of flag, eg MUTT_READ matches unread messages |
num | Matched messages |
-1 | Failure |
pre/post: commands are of the form "%s %s %s %s", tag, pre, message set, post Prepares commands for all messages matching conditions (must be flushed with imap_exec)
Definition at line 940 of file imap.c.
int imap_sync_message_for_copy | ( | struct Mailbox * | m, |
struct Email * | e, | ||
struct Buffer * | cmd, | ||
enum QuadOption * | err_continue | ||
) |
Update server to reflect the flags of a single message.
[in] | m | Mailbox |
[in] | e | |
[in] | cmd | Buffer for the command string |
[out] | err_continue | Did the user force a continue? |
0 | Success |
-1 | Failure |
Update the IMAP server to reflect the flags for a single message before performing a "UID COPY".
Definition at line 1017 of file imap.c.
Use the NOOP or IDLE command to poll for new mail.
m | Mailbox |
force | Don't wait |
num | MxStatus |
Definition at line 1118 of file imap.c.
|
static |
Refresh the number of total and new messages.
num | Total number of messages |
Definition at line 1189 of file imap.c.
int imap_path_status | ( | const char * | path, |
bool | queue | ||
) |
Refresh the number of total and new messages.
path | Mailbox path |
queue | Queue the STATUS command |
num | Total number of messages |
Definition at line 1249 of file imap.c.
int imap_mailbox_status | ( | struct Mailbox * | m, |
bool | queue | ||
) |
Refresh the number of total and new messages.
m | Mailbox |
queue | Queue the STATUS command |
num | Total number of messages |
-1 | Error |
Definition at line 1284 of file imap.c.
int imap_subscribe | ( | char * | path, |
bool | subscribe | ||
) |
Subscribe to a mailbox.
path | Mailbox path |
subscribe | True: subscribe, false: unsubscribe |
0 | Success |
-1 | Failure |
Definition at line 1300 of file imap.c.
int imap_complete | ( | char * | buf, |
size_t | buflen, | ||
const char * | path | ||
) |
Try to complete an IMAP folder path.
buf | Buffer for result |
buflen | Length of buffer |
path | Partial mailbox name to complete |
0 | Success |
-1 | Failure |
Given a partial IMAP folder path, return a string which adds as much to the path as is unique
Definition at line 1356 of file imap.c.
int imap_fast_trash | ( | struct Mailbox * | m, |
const char * | dest | ||
) |
Use server COPY command to copy deleted messages to trash.
-1 | Error |
0 | Success |
1 | Non-fatal error - try fetch/append |
Definition at line 1435 of file imap.c.
Sync all the changes to the server.
m | Mailbox |
expunge | if true do expunge |
close | if true we move imap state to CLOSE |
enum | MxStatus |
Definition at line 1545 of file imap.c.
|
static |
Select a Mailbox.
m | Mailbox |
Definition at line 1828 of file imap.c.
int imap_login | ( | struct ImapAccountData * | adata | ) |
Open an IMAP connection.
adata | Imap Account data |
0 | Success |
-1 | Failure |
Ensure ImapAccountData is connected and logged into the imap server.
Definition at line 1861 of file imap.c.
int imap_expand_path | ( | struct Buffer * | buf | ) |
Buffer wrapper around imap_path_canon()
buf | Path to expand |
0 | Success |
-1 | Failure |
Definition at line 2465 of file imap.c.
|
static |
Imap Commands.