IMAP network mailbox. More...
#include "config.h"#include <limits.h>#include <stdbool.h>#include <stdint.h>#include <stdio.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 "editor/lib.h"#include "history/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 "msg_set.h"#include "msn.h"#include "mutt_logging.h"#include "mutt_socket.h"#include "muttlib.h"#include "mx.h"#include <libintl.h>
Include dependency graph for imap.c:Go to the source code of this file.
Functions | |
| void | imap_init (void) |
| Setup feature commands. | |
| static int | check_capabilities (struct ImapAccountData *adata) |
| Make sure we can log in to this server. | |
| static char * | get_flags (struct ListHead *hflags, char *s) |
| Make a simple list out of a FLAGS response. | |
| static void | set_flag (struct Mailbox *m, AclFlags aclflag, bool flag, const char *str, struct Buffer *flags) |
| Append str to flags if we currently have permission according to aclflag. | |
| static bool | compare_flags_for_copy (struct Email *e) |
| Compare local flags against the server. | |
| static int | select_email_uids (struct Email **emails, int num_emails, enum MessageType flag, bool changed, bool invert, struct UidArray *uida) |
| Create a list of Email UIDs by type. | |
| static int | sync_helper (struct Mailbox *m, struct Email **emails, int num_emails, AclFlags right, enum MessageType flag, const char *name) |
| Sync flag changes to the server. | |
| static size_t | longest_common_prefix (struct Buffer *buf, const char *src, size_t start) |
| Find longest prefix common to two strings. | |
| static int | complete_hosts (struct Buffer *buf) |
| Look for completion matches for mailboxes. | |
| int | imap_create_mailbox (struct ImapAccountData *adata, const char *mailbox) |
| Create a new mailbox. | |
| int | imap_access (const char *path) |
| Check permissions on an IMAP mailbox with a new connection. | |
| int | imap_rename_mailbox (struct ImapAccountData *adata, char *oldname, const char *newname) |
| Rename a mailbox. | |
| int | imap_delete_mailbox (struct Mailbox *m, char *path) |
| Delete a mailbox. | |
| static void | imap_logout (struct ImapAccountData *adata) |
| Gracefully log out of server. | |
| void | imap_logout_all (void) |
| Close all open connections. | |
| int | imap_read_literal (FILE *fp, struct ImapAccountData *adata, unsigned long bytes, struct Progress *progress) |
| Read bytes bytes from server into file. | |
| void | imap_notify_delete_email (struct Mailbox *m, struct Email *e) |
| Inform IMAP that an Email has been deleted. | |
| void | imap_expunge_mailbox (struct Mailbox *m, bool resort) |
| Purge messages from the server. | |
| int | imap_open_connection (struct ImapAccountData *adata) |
| Open an IMAP connection. | |
| void | imap_close_connection (struct ImapAccountData *adata) |
| Close an IMAP connection. | |
| bool | imap_has_flag (struct ListHead *flag_list, const char *flag) |
| Does the flag exist in the list. | |
| static int | imap_sort_email_uid (const void *a, const void *b, void *sdata) |
| Compare two Emails by UID - Implements sort_t -. | |
| 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. | |
| enum MxStatus | imap_check_mailbox (struct Mailbox *m, bool force) |
| Use the NOOP or IDLE command to poll for new mail. | |
| static int | imap_status (struct ImapAccountData *adata, struct ImapMboxData *mdata, bool queue) |
| Refresh the number of total and new messages. | |
| static enum MxStatus | imap_mbox_check_stats (struct Mailbox *m, uint8_t flags) |
| Check the Mailbox statistics - Implements MxOps::mbox_check_stats() -. | |
| int | imap_path_status (const char *path, bool queue) |
| Refresh the number of total and new messages. | |
| int | imap_mailbox_status (struct Mailbox *m, bool queue) |
| Refresh the number of total and new messages. | |
| int | imap_subscribe (const char *path, bool subscribe) |
| Subscribe to a mailbox. | |
| int | imap_complete (struct Buffer *buf, const char *path) |
| Try to complete an IMAP folder path. | |
| int | imap_fast_trash (struct Mailbox *m, const char *dest) |
| Use server COPY command to copy deleted messages to trash. | |
| enum MxStatus | imap_sync_mailbox (struct Mailbox *m, bool expunge, bool close) |
| Sync all the changes to the server. | |
| 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() -. | |
| static bool | imap_ac_add (struct Account *a, struct Mailbox *m) |
| Add a Mailbox to an Account - Implements MxOps::ac_add() -. | |
| static void | imap_mbox_select (struct Mailbox *m) |
| Select a Mailbox. | |
| int | imap_login (struct ImapAccountData *adata) |
| Open an IMAP connection. | |
| static enum MxOpenReturns | imap_mbox_open (struct Mailbox *m) |
| Open a mailbox - Implements MxOps::mbox_open() -. | |
| static bool | imap_mbox_open_append (struct Mailbox *m, OpenMailboxFlags flags) |
| Open a Mailbox for appending - Implements MxOps::mbox_open_append() -. | |
| static enum MxStatus | imap_mbox_check (struct Mailbox *m) |
| Check for new mail - Implements MxOps::mbox_check() -. | |
| static enum MxStatus | imap_mbox_close (struct Mailbox *m) |
| Close a Mailbox - Implements MxOps::mbox_close() -. | |
| 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() -. | |
| static int | imap_tags_edit (struct Mailbox *m, const char *tags, struct Buffer *buf) |
| Prompt and validate new messages tags - Implements MxOps::tags_edit() -. | |
| static int | imap_tags_commit (struct Mailbox *m, struct Email *e, const char *buf) |
| Save the tags to a message - Implements MxOps::tags_commit() -. | |
| enum MailboxType | imap_path_probe (const char *path, const struct stat *st) |
| Is this an IMAP Mailbox? | |
| int | imap_path_canon (struct Buffer *path) |
| Canonicalise a Mailbox path - Implements MxOps::path_canon() -. | |
| static int | imap_path_is_empty (struct Buffer *path) |
| Is the mailbox empty - Implements MxOps::path_is_empty() -. | |
Variables | |
| static const struct Command | ImapCommands [] |
| Imap Commands. | |
| const struct MxOps | MxImapOps |
| IMAP Mailbox - Implements MxOps -. | |
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 95 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Make sure we can log in to this server.
| adata | Imap Account data |
| 0 | Success |
| -1 | Failure |
Definition at line 106 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
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 132 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
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 |
Definition at line 186 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
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 202 of file imap.c.
Here is the caller graph for this function:
|
static |
Create a list of Email UIDs by type.
| emails | Array of Emails |
| num_emails | Number of Emails in the array |
| 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 |
| uida | Array to fill with UIDs |
| num | Number of UIDs added |
| -1 | Error |
Definition at line 229 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Sync flag changes to the server.
| m | Selected Imap Mailbox |
| emails | Array of Emails |
| num_emails | Number of Emails in the array |
| 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 299 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Find longest prefix common to two strings.
| buf | Destination buffer |
| src | Source buffer |
| start | Starting offset into string |
| num | Length of the common string |
Trim dest to the length of the longest prefix it shares with src.
Definition at line 347 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Look for completion matches for mailboxes.
| buf | Partial mailbox name to complete |
| 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 370 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int imap_create_mailbox | ( | struct ImapAccountData * | adata, |
| const char * | mailbox ) |
Create a new mailbox.
| 0 | Success |
| -1 | Failure |
Definition at line 435 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 462 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 477 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int imap_delete_mailbox | ( | struct Mailbox * | m, |
| char * | path ) |
Delete a mailbox.
| m | Mailbox |
| path | name of the mailbox to delete |
| 0 | Success |
| -1 | Failure |
Definition at line 504 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Gracefully log out of server.
| adata | Imap Account data |
Definition at line 526 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 556 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 592 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:Inform IMAP that an Email has been deleted.
Definition at line 650 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 671 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int imap_open_connection | ( | struct ImapAccountData * | adata | ) |
Open an IMAP connection.
| adata | Imap Account data |
| 0 | Success |
| -1 | Failure |
Definition at line 743 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| void imap_close_connection | ( | struct ImapAccountData * | adata | ) |
Close an IMAP connection.
| adata | Imap Account data |
Definition at line 851 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 876 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 928 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:Use the NOOP or IDLE command to poll for new mail.
| m | Mailbox |
| force | Don't wait |
| num | MxStatus |
Definition at line 1034 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Refresh the number of total and new messages.
| num | Total number of messages |
Definition at line 1107 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 1174 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 1209 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int imap_subscribe | ( | const char * | path, |
| bool | subscribe ) |
Subscribe to a mailbox.
| path | Mailbox path |
| subscribe | True: subscribe, false: unsubscribe |
| 0 | Success |
| -1 | Failure |
Definition at line 1225 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| int imap_complete | ( | struct Buffer * | buf, |
| const char * | path ) |
Try to complete an IMAP folder path.
| buf | Buffer for result |
| 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 1277 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 1358 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function: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 1473 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Select a Mailbox.
| m | Mailbox |
Definition at line 1748 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:| 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 1781 of file imap.c.
Here is the call graph for this function:
Here is the caller graph for this function:
|
static |
Imap Commands.
Definition at line 84 of file imap.c.