Manage IMAP messages. More...
#include "config.h"
#include <ctype.h>
#include <limits.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.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 "gui/lib.h"
#include "mutt.h"
#include "message.h"
#include "lib.h"
#include "bcache/lib.h"
#include "progress/lib.h"
#include "question/lib.h"
#include "adata.h"
#include "edata.h"
#include "external.h"
#include "mdata.h"
#include "msg_set.h"
#include "msn.h"
#include "mutt_logging.h"
#include "mx.h"
#include "protos.h"
#include <libintl.h>
#include "hcache/lib.h"
Go to the source code of this file.
Functions | |
static struct BodyCache * | imap_bcache_open (struct Mailbox *m) |
Open a message cache. | |
static FILE * | msg_cache_get (struct Mailbox *m, struct Email *e) |
Get the message cache entry for an email. | |
static FILE * | msg_cache_put (struct Mailbox *m, struct Email *e) |
Put an email into the message cache. | |
static int | msg_cache_commit (struct Mailbox *m, struct Email *e) |
Add to the message cache. | |
static int | imap_bcache_delete (const char *id, struct BodyCache *bcache, void *data) |
Delete an entry from the message cache - Implements bcache_list_t -. | |
static char * | msg_parse_flags (struct ImapHeader *h, char *s) |
Read a FLAGS token into an ImapHeader. | |
static int | msg_parse_fetch (struct ImapHeader *h, char *s) |
Handle headers returned from header fetch. | |
static int | msg_fetch_header (struct Mailbox *m, struct ImapHeader *ih, char *buf, FILE *fp) |
Import IMAP FETCH response into an ImapHeader. | |
static int | flush_buffer (char *buf, size_t *len, struct Connection *conn) |
Write data to a connection. | |
static bool | query_abort_header_download (struct ImapAccountData *adata) |
Ask the user whether to abort the download. | |
static void | imap_alloc_uid_hash (struct ImapAccountData *adata, unsigned int msn_count) |
Create a Hash Table for the UIDs. | |
static unsigned int | imap_fetch_msn_seqset (struct Buffer *buf, struct ImapAccountData *adata, bool evalhc, unsigned int msn_begin, unsigned int msn_end, unsigned int *fetch_msn_end) |
Generate a sequence set. | |
static void | set_changed_flag (struct Mailbox *m, struct Email *e, int local_changes, bool *server_changes, enum MessageType flag_name, bool old_hd_flag, bool new_hd_flag, bool h_flag) |
Have the flags of an email changed. | |
static int | read_headers_normal_eval_cache (struct ImapAccountData *adata, unsigned int msn_end, unsigned int uid_next, bool store_flag_updates, bool eval_condstore) |
Retrieve data from the header cache. | |
static int | read_headers_qresync_eval_cache (struct ImapAccountData *adata, char *uid_seqset) |
Retrieve data from the header cache. | |
static int | read_headers_condstore_qresync_updates (struct ImapAccountData *adata, unsigned int msn_end, unsigned int uid_next, unsigned long long hc_modseq, bool eval_qresync) |
Retrieve updates from the server. | |
static int | imap_verify_qresync (struct Mailbox *m) |
Check to see if QRESYNC got jumbled. | |
static int | read_headers_fetch_new (struct Mailbox *m, unsigned int msn_begin, unsigned int msn_end, bool evalhc, unsigned int *maxuid, bool initial_download) |
Retrieve new messages from the server. | |
int | imap_read_headers (struct Mailbox *m, unsigned int msn_begin, unsigned int msn_end, bool initial_download) |
Read headers from the server. | |
int | imap_append_message (struct Mailbox *m, struct Message *msg) |
Write an email back to the server. | |
static int | emails_to_uid_array (struct EmailArray *ea, struct UidArray *uida) |
Extract IMAP UIDs from Emails. | |
int | imap_copy_messages (struct Mailbox *m, struct EmailArray *ea, const char *dest, enum MessageSaveOpt save_opt) |
Server COPY messages to another folder. | |
int | imap_cache_del (struct Mailbox *m, struct Email *e) |
Delete an email from the body cache. | |
int | imap_cache_clean (struct Mailbox *m) |
Delete all the entries in the message cache. | |
char * | imap_set_flags (struct Mailbox *m, struct Email *e, char *s, bool *server_changes) |
Fill the message header according to the server flags. | |
bool | imap_msg_open (struct Mailbox *m, struct Message *msg, struct Email *e) |
Open an email message in a Mailbox - Implements MxOps::msg_open() -. | |
int | imap_msg_commit (struct Mailbox *m, struct Message *msg) |
Save changes to an email - Implements MxOps::msg_commit() -. | |
int | imap_msg_close (struct Mailbox *m, struct Message *msg) |
Close an email - Implements MxOps::msg_close() -. | |
int | imap_msg_save_hcache (struct Mailbox *m, struct Email *e) |
Save message to the header cache - Implements MxOps::msg_save_hcache() -. | |
Manage IMAP messages.
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 message.c.
Open a message cache.
m | Selected Imap Mailbox |
ptr | Success, using existing cache (or opened new cache) |
NULL | Failure |
Definition at line 81 of file message.c.
Get the message cache entry for an email.
ptr | Success, handle of cache entry |
NULL | Failure |
Definition at line 108 of file message.c.
Put an email into the message cache.
ptr | Success, handle of cache entry |
NULL | Failure |
Definition at line 129 of file message.c.
Add to the message cache.
0 | Success |
-1 | Failure |
Definition at line 150 of file message.c.
|
static |
Read a FLAGS token into an ImapHeader.
h | Header to store flags |
s | Command string containing flags |
ptr | The end of flags string |
NULL | Failure |
Definition at line 192 of file message.c.
|
static |
Handle headers returned from header fetch.
h | IMAP Header |
s | Command string |
0 | Success |
-1 | String is corrupted |
-2 | Fetch contains a body or header lines that still need to be parsed |
Definition at line 309 of file message.c.
|
static |
Import IMAP FETCH response into an ImapHeader.
m | Mailbox |
ih | ImapHeader |
buf | Server string containing FETCH response |
fp | Connection to server |
0 | Success |
-1 | String is not a fetch response |
-2 | String is a corrupt fetch response |
Expects string beginning with * n FETCH.
Definition at line 421 of file message.c.
|
static |
Write data to a connection.
buf | Buffer containing data |
len | Length of buffer |
conn | Network connection |
>0 | Number of bytes written |
-1 | Error |
Definition at line 487 of file message.c.
|
static |
Ask the user whether to abort the download.
adata | Imap Account data |
true | Abort the download |
If the user hits ctrl-c during an initial header download for a mailbox, prompt whether to completely abort the download and close the mailbox.
Definition at line 503 of file message.c.
|
static |
Create a Hash Table for the UIDs.
adata | Imap Account data |
msn_count | Number of MSNs in use |
This function is run after imap_imap_msn_reserve, so we skip the malicious msn_count size check.
Definition at line 527 of file message.c.
|
static |
Generate a sequence set.
[in] | buf | Buffer for the result |
[in] | adata | Imap Account data |
[in] | evalhc | If true, check the Header Cache |
[in] | msn_begin | First Message Sequence Number |
[in] | msn_end | Last Message Sequence Number |
[out] | fetch_msn_end | Highest Message Sequence Number fetched |
num | MSN count |
Generates a more complicated sequence set after using the header cache, in case there are missing MSNs in the middle.
This can happen if during a sync/close, messages are deleted from the cache, but the server doesn't get the updates (via a dropped network connection, or just plain refusing the updates).
Definition at line 551 of file message.c.
|
static |
Have the flags of an email changed.
[in] | m | Mailbox |
[in] | e | |
[in] | local_changes | Has the local mailbox been changed? |
[out] | server_changes | Set to true if the flag has changed |
[in] | flag_name | Flag to check, e.g. MUTT_FLAG |
[in] | old_hd_flag | Old header flags |
[in] | new_hd_flag | New header flags |
[in] | h_flag | Email's value for flag_name |
Sets server_changes to 1 if a change to a flag is made, or in the case of local_changes, if a change to a flag would have been made.
Definition at line 643 of file message.c.
|
static |
Retrieve data from the header cache.
adata | Imap Account data |
msn_end | Last Message Sequence number |
uid_next | UID of next email |
store_flag_updates | if true, save flags to the header cache |
eval_condstore | if true, use CONDSTORE to fetch flags |
0 | Success |
-1 | Error |
Without CONDSTORE or QRESYNC, we need to query all the current UIDs and update their flag state and current MSN.
For CONDSTORE, we still need to grab the existing UIDs and their MSN. The current flag state will be queried in read_headers_condstore_qresync_updates().
Definition at line 683 of file message.c.
|
static |
Retrieve data from the header cache.
adata | Imap Account data |
uid_seqset | Sequence Set of UIDs |
>=0 | Success |
-1 | Error |
For QRESYNC, we grab the UIDs in order by MSN from the header cache.
In read_headers_condstore_qresync_updates(). We will update change flags using CHANGEDSINCE and find out what UIDs have been expunged using VANISHED.
Definition at line 828 of file message.c.
|
static |
Retrieve updates from the server.
adata | Imap Account data |
msn_end | Last Message Sequence number |
uid_next | UID of next email |
hc_modseq | Timestamp of last Header Cache update |
eval_qresync | If true, use QRESYNC |
0 | Success |
-1 | Error |
CONDSTORE and QRESYNC use FETCH extensions to grab updates.
Definition at line 914 of file message.c.
|
static |
Check to see if QRESYNC got jumbled.
m | Imap Selected Mailbox |
0 | Success |
-1 | Error |
If so, wipe the context and try again with a normal download.
Definition at line 1013 of file message.c.
|
static |
Retrieve new messages from the server.
[in] | m | Imap Selected Mailbox |
[in] | msn_begin | First Message Sequence number |
[in] | msn_end | Last Message Sequence number |
[in] | evalhc | If true, check the Header Cache |
[out] | maxuid | Highest UID seen |
[in] | initial_download | true, if this is the first opening of the mailbox |
0 | Success |
-1 | Error |
Definition at line 1090 of file message.c.
int imap_read_headers | ( | struct Mailbox * | m, |
unsigned int | msn_begin, | ||
unsigned int | msn_end, | ||
bool | initial_download | ||
) |
Read headers from the server.
m | Imap Selected Mailbox |
msn_begin | First Message Sequence Number |
msn_end | Last Message Sequence Number |
initial_download | true, if this is the first opening of the mailbox |
num | Last MSN |
-1 | Failure |
Changed to read many headers instead of just one. It will return the msn of the last message read. It will return a value other than msn_end if mail comes in while downloading headers (in theory).
Definition at line 1340 of file message.c.
Write an email back to the server.
0 | Success |
-1 | Failure |
Definition at line 1529 of file message.c.
|
static |
Extract IMAP UIDs from Emails.
ea | Array of Emails |
uida | Empty UID array |
num | Number of UIDs in the array |
Definition at line 1662 of file message.c.
int imap_copy_messages | ( | struct Mailbox * | m, |
struct EmailArray * | ea, | ||
const char * | dest, | ||
enum MessageSaveOpt | save_opt | ||
) |
Server COPY messages to another folder.
m | Mailbox |
ea | Array of Emails to copy |
dest | Destination folder |
save_opt | Copy or move, e.g. SAVE_MOVE |
-1 | Error |
0 | Success |
1 | Non-fatal error - try fetch/append |
Definition at line 1687 of file message.c.
Delete an email from the body cache.
0 | Success |
-1 | Failure |
Definition at line 1869 of file message.c.
int imap_cache_clean | ( | struct Mailbox * | m | ) |
Delete all the entries in the message cache.
m | SelectedImap Mailbox |
0 | Always |
Definition at line 1888 of file message.c.
Fill the message header according to the server flags.
[in] | m | Imap Selected Mailbox |
[in] | e | |
[in] | s | Command string |
[out] | server_changes | Set to true if the flags have changed |
ptr | The end of flags string |
NULL | Failure |
Expects a flags line of the form "FLAGS (flag flag ...)"
imap_set_flags: fill out the message header according to the flags from the server. Expects a flags line of the form "FLAGS (flag flag ...)"
Sets server_changes to 1 if a change to a flag is made, or in the case of e->changed, if a change to a flag would have been made.
Definition at line 1920 of file message.c.