NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
private.h
Go to the documentation of this file.
1
25#ifndef MUTT_IMAP_PRIVATE_H
26#define MUTT_IMAP_PRIVATE_H
27
28#include "config.h"
29#include <stdbool.h>
30#include <stdint.h>
31#include <stdio.h>
32#include "config/lib.h"
33
34struct Buffer;
35struct ConnAccount;
36struct Email;
37struct ImapAccountData;
38struct ImapMboxData;
39struct ListHead;
40struct Mailbox;
41struct Message;
42struct Progress;
43
44#define IMAP_PORT 143
45#define IMAP_SSL_PORT 993
46
47/* logging levels */
48#define IMAP_LOG_CMD 2
49#define IMAP_LOG_LTRL 3
50#define IMAP_LOG_PASS 5
51
52/* IMAP command responses. Used in ImapCommand.state too */
53#define IMAP_RES_NO -2
54#define IMAP_RES_BAD -1
55#define IMAP_RES_OK 0
56#define IMAP_RES_CONTINUE 1
57#define IMAP_RES_RESPOND 2
58#define IMAP_RES_NEW 3
59
60#define SEQ_LEN 16
61
62typedef uint8_t ImapOpenFlags;
63#define IMAP_OPEN_NO_FLAGS 0
64#define IMAP_REOPEN_ALLOW (1 << 0)
65#define IMAP_EXPUNGE_EXPECTED (1 << 1)
66#define IMAP_EXPUNGE_PENDING (1 << 2)
67#define IMAP_NEWMAIL_PENDING (1 << 3)
68#define IMAP_FLAGS_PENDING (1 << 4)
69
70typedef uint8_t ImapCmdFlags;
71#define IMAP_CMD_NO_FLAGS 0
72#define IMAP_CMD_PASS (1 << 0)
73#define IMAP_CMD_QUEUE (1 << 1)
74#define IMAP_CMD_POLL (1 << 2)
75#define IMAP_CMD_SINGLE (1 << 3)
76
81{
85};
86
87/* length of "DD-MMM-YYYY HH:MM:SS +ZZzz" (null-terminated) */
88#define IMAP_DATELEN 27
89
94{
97};
98
103{
104 /* States */
109
110 /* and pseudo-states */
112};
113
119typedef uint32_t ImapCapFlags;
120#define IMAP_CAP_NO_FLAGS 0
121#define IMAP_CAP_IMAP4 (1 << 0)
122#define IMAP_CAP_IMAP4REV1 (1 << 1)
123#define IMAP_CAP_STATUS (1 << 2)
124#define IMAP_CAP_ACL (1 << 3)
125#define IMAP_CAP_NAMESPACE (1 << 4)
126#define IMAP_CAP_AUTH_CRAM_MD5 (1 << 5)
127#define IMAP_CAP_AUTH_GSSAPI (1 << 6)
128#define IMAP_CAP_AUTH_ANONYMOUS (1 << 7)
129#define IMAP_CAP_AUTH_OAUTHBEARER (1 << 8)
130#define IMAP_CAP_AUTH_XOAUTH2 (1 << 9)
131#define IMAP_CAP_STARTTLS (1 << 10)
132#define IMAP_CAP_LOGINDISABLED (1 << 11)
133#define IMAP_CAP_IDLE (1 << 12)
134#define IMAP_CAP_SASL_IR (1 << 13)
135#define IMAP_CAP_ENABLE (1 << 14)
136#define IMAP_CAP_CONDSTORE (1 << 15)
137#define IMAP_CAP_QRESYNC (1 << 16)
138#define IMAP_CAP_LIST_EXTENDED (1 << 17)
139#define IMAP_CAP_COMPRESS (1 << 18)
140#define IMAP_CAP_X_GM_EXT_1 (1 << 19)
141#define IMAP_CAP_ID (1 << 20)
142
143#define IMAP_CAP_ALL ((1 << 21) - 1)
144
149{
150 char *name;
151 char delim;
154};
155
160{
161 char seq[SEQ_LEN + 1];
162 int state;
163};
164
169{
171 char *eostr;
173 int down;
174 unsigned int range_cur;
175 unsigned int range_end;
178};
179
180/* -- private IMAP functions -- */
181/* imap.c */
182int imap_create_mailbox(struct ImapAccountData *adata, const char *mailbox);
183int imap_rename_mailbox(struct ImapAccountData *adata, char *oldname, const char *newname);
184int imap_open_connection(struct ImapAccountData *adata);
185void imap_close_connection(struct ImapAccountData *adata);
186int imap_read_literal(FILE *fp, struct ImapAccountData *adata, unsigned long bytes, struct Progress *progress);
187void imap_expunge_mailbox(struct Mailbox *m, bool resort);
188int imap_login(struct ImapAccountData *adata);
189int imap_sync_message_for_copy(struct Mailbox *m, struct Email *e, struct Buffer *cmd, enum QuadOption *err_continue);
190bool imap_has_flag(struct ListHead *flag_list, const char *flag);
191int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata);
192
193/* auth.c */
194int imap_authenticate(struct ImapAccountData *adata);
195
196/* command.c */
197int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr);
198int imap_cmd_step(struct ImapAccountData *adata);
199void imap_cmd_finish(struct ImapAccountData *adata);
200bool imap_code(const char *s);
201const char *imap_cmd_trailer(struct ImapAccountData *adata);
202int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags);
203int imap_cmd_idle(struct ImapAccountData *adata);
204
205/* message.c */
206int imap_read_headers(struct Mailbox *m, unsigned int msn_begin, unsigned int msn_end, bool initial_download);
207char *imap_set_flags(struct Mailbox *m, struct Email *e, char *s, bool *server_changes);
208int imap_cache_del(struct Mailbox *m, struct Email *e);
209int imap_cache_clean(struct Mailbox *m);
210int imap_append_message(struct Mailbox *m, struct Message *msg);
211
212bool imap_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e);
213int imap_msg_close(struct Mailbox *m, struct Message *msg);
214int imap_msg_commit(struct Mailbox *m, struct Message *msg);
215int imap_msg_save_hcache(struct Mailbox *m, struct Email *e);
216
217/* util.c */
218#ifdef USE_HCACHE
219void imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata);
220void imap_hcache_close(struct ImapMboxData *mdata);
221struct Email *imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid);
222int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e);
223int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid);
226char *imap_hcache_get_uid_seqset(struct ImapMboxData *mdata);
227#endif
228
229enum QuadOption imap_continue(const char *msg, const char *resp);
230void imap_error(const char *where, const char *msg);
231void imap_mdata_cache_reset(struct ImapMboxData *mdata);
232char *imap_fix_path(char delim, const char *mailbox, char *path, size_t plen);
233void imap_cachepath(char delim, const char *mailbox, struct Buffer *dest);
234int imap_get_literal_count(const char *buf, unsigned int *bytes);
235char *imap_get_qualifier(char *buf);
236char *imap_next_word(char *s);
237void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path);
238void imap_buf_qualify_path(struct Buffer *buf, struct ConnAccount *conn_account, char *path);
239void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick);
240void imap_unquote_string(char *s);
241void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src);
242void imap_unmunge_mbox_name(bool unicode, char *s);
243struct SeqsetIterator *mutt_seqset_iterator_new(const char *seqset);
244int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next);
246bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2);
247void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen);
248bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2);
249
250/* utf7.c */
251void imap_utf_encode(bool unicode, char **s);
252void imap_utf_decode(bool unicode, char **s);
253void imap_allow_reopen(struct Mailbox *m);
254void imap_disallow_reopen(struct Mailbox *m);
255
256/* search.c */
257void cmd_parse_search(struct ImapAccountData *adata, const char *s);
258
259#endif /* MUTT_IMAP_PRIVATE_H */
Convenience wrapper for the config headers.
int imap_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close() -.
Definition: message.c:2184
int imap_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit() -.
Definition: message.c:2170
bool imap_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e)
Open an email message in a Mailbox - Implements MxOps::msg_open() -.
Definition: message.c:1977
int imap_msg_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Implements MxOps::msg_save_hcache() -.
Definition: message.c:2192
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition: command.c:1118
void imap_unmunge_mbox_name(bool unicode, char *s)
Remove quoting from a mailbox name.
Definition: util.c:938
int imap_cache_clean(struct Mailbox *m)
Delete all the entries in the message cache.
Definition: message.c:1888
void imap_close_connection(struct ImapAccountData *adata)
Close an IMAP connection.
Definition: imap.c:850
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path)
Make an absolute IMAP folder target.
Definition: util.c:816
char * imap_set_flags(struct Mailbox *m, struct Email *e, char *s, bool *server_changes)
Fill the message header according to the server flags.
Definition: message.c:1920
void imap_allow_reopen(struct Mailbox *m)
Allow re-opening a folder upon expunge.
Definition: util.c:1026
void imap_disallow_reopen(struct Mailbox *m)
Disallow re-opening a folder upon expunge.
Definition: util.c:1039
ImapState
IMAP connection state.
Definition: private.h:103
@ IMAP_DISCONNECTED
Disconnected from server.
Definition: private.h:105
@ IMAP_IDLE
Connection is idle.
Definition: private.h:111
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition: private.h:107
@ IMAP_SELECTED
Mailbox is selected.
Definition: private.h:108
@ IMAP_CONNECTED
Connected to server.
Definition: private.h:106
uint8_t ImapOpenFlags
Flags, e.g. MUTT_THREAD_COLLAPSE.
Definition: private.h:62
int imap_get_literal_count(const char *buf, unsigned int *bytes)
Write number of bytes in an IMAP literal into bytes.
Definition: util.c:741
int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata)
Store a UID Sequence Set in the header cache.
Definition: util.c:415
int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e)
Add an entry to the header cache.
Definition: util.c:380
void imap_mdata_cache_reset(struct ImapMboxData *mdata)
Release and clear cache data of ImapMboxData structure.
Definition: util.c:107
void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen)
Get an IMAP folder's parent.
Definition: util.c:121
struct SeqsetIterator * mutt_seqset_iterator_new(const char *seqset)
Create a new Sequence Set Iterator.
Definition: util.c:1086
bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
void imap_utf_encode(bool unicode, char **s)
Encode email from local charset to UTF-8.
Definition: utf7.c:397
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
Quote string according to IMAP rules.
Definition: util.c:847
char * imap_hcache_get_uid_seqset(struct ImapMboxData *mdata)
Get a UID Sequence Set from the header cache.
Definition: util.c:450
enum QuadOption imap_continue(const char *msg, const char *resp)
Display a message and ask the user if they want to go on.
Definition: util.c:646
void imap_unquote_string(char *s)
Equally stupid unquoting routine.
Definition: util.c:884
struct Email * imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid)
Get a header cache entry by its UID.
Definition: util.c:355
const char * imap_cmd_trailer(struct ImapAccountData *adata)
Extra information after tagged command response if any.
Definition: command.c:1270
int imap_append_message(struct Mailbox *m, struct Message *msg)
Write an email back to the server.
Definition: message.c:1530
void imap_buf_qualify_path(struct Buffer *buf, struct ConnAccount *conn_account, char *path)
Make an absolute IMAP folder target to a buffer.
Definition: util.c:830
int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next)
Get the next UID from a Sequence Set.
Definition: util.c:1107
ImapExecResult
Imap_exec return code.
Definition: private.h:81
@ IMAP_EXEC_SUCCESS
Imap command executed or queued successfully.
Definition: private.h:82
@ IMAP_EXEC_ERROR
Imap command failure.
Definition: private.h:83
@ IMAP_EXEC_FATAL
Imap connection failure.
Definition: private.h:84
void mutt_seqset_iterator_free(struct SeqsetIterator **ptr)
Free a Sequence Set Iterator.
Definition: util.c:1166
int imap_cmd_idle(struct ImapAccountData *adata)
Enter the IDLE state.
Definition: command.c:1439
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1132
char * imap_fix_path(char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition: util.c:679
void imap_expunge_mailbox(struct Mailbox *m, bool resort)
Purge messages from the server.
Definition: imap.c:670
int imap_open_connection(struct ImapAccountData *adata)
Open an IMAP connection.
Definition: imap.c:742
#define SEQ_LEN
Definition: private.h:60
void imap_cachepath(char delim, const char *mailbox, struct Buffer *dest)
Generate a cache path for a mailbox.
Definition: util.c:710
int imap_rename_mailbox(struct ImapAccountData *adata, char *oldname, const char *newname)
Rename a mailbox.
Definition: imap.c:479
int imap_create_mailbox(struct ImapAccountData *adata, const char *mailbox)
Create a new mailbox.
Definition: imap.c:437
void imap_utf_decode(bool unicode, char **s)
Decode email from UTF-8 to local charset.
Definition: utf7.c:430
void imap_error(const char *where, const char *msg)
Show an error and abort.
Definition: util.c:657
void imap_hcache_close(struct ImapMboxData *mdata)
Close the header cache.
Definition: util.c:340
int imap_cache_del(struct Mailbox *m, struct Email *e)
Delete an email from the body cache.
Definition: message.c:1869
ImapFlags
IMAP server responses.
Definition: private.h:94
@ IMAP_BYE
Logged out from server.
Definition: private.h:96
@ IMAP_FATAL
Unrecoverable error occurred.
Definition: private.h:95
int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid)
Delete an item from the header cache.
Definition: util.c:398
int imap_read_headers(struct Mailbox *m, unsigned int msn_begin, unsigned int msn_end, bool initial_download)
Read headers from the server.
Definition: message.c:1341
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.
Definition: imap.c:927
bool imap_code(const char *s)
Was the command successful.
Definition: command.c:1259
int imap_hcache_clear_uid_seqset(struct ImapMboxData *mdata)
Delete a UID Sequence Set from the header cache.
Definition: util.c:436
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:73
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
Definition: util.c:1054
void cmd_parse_search(struct ImapAccountData *adata, const char *s)
Store SEARCH response for later use.
Definition: search.c:256
void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src)
Quote awkward characters in a mailbox name.
Definition: util.c:921
void imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata)
Open a header cache.
Definition: util.c:299
int imap_read_literal(FILE *fp, struct ImapAccountData *adata, unsigned long bytes, struct Progress *progress)
Read bytes bytes from server into file.
Definition: imap.c:591
int imap_authenticate(struct ImapAccountData *adata)
Authenticate to an IMAP server.
Definition: auth.c:115
bool imap_has_flag(struct ListHead *flag_list, const char *flag)
Does the flag exist in the list.
Definition: imap.c:875
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition: util.c:785
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1307
uint8_t ImapCmdFlags
Flags for imap_exec(), e.g. IMAP_CMD_PASS.
Definition: private.h:70
uint32_t ImapCapFlags
Capabilities we are interested in.
Definition: private.h:119
int imap_login(struct ImapAccountData *adata)
Open an IMAP connection.
Definition: imap.c:1776
void imap_cmd_finish(struct ImapAccountData *adata)
Attempt to perform cleanup.
Definition: command.c:1372
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.
Definition: util.c:768
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
String manipulation buffer.
Definition: buffer.h:36
Login details for a remote server.
Definition: connaccount.h:53
The envelope/body of an email.
Definition: email.h:39
char * path
Path of Email (for local Mailboxes)
Definition: email.h:70
IMAP-specific Account data -.
Definition: adata.h:40
IMAP command structure.
Definition: private.h:160
int state
Command state, e.g. IMAP_RES_NEW.
Definition: private.h:162
char seq[SEQ_LEN+1]
Command tag, e.g. 'a0001'.
Definition: private.h:161
Items in an IMAP browser.
Definition: private.h:149
bool noselect
Definition: private.h:152
bool noinferiors
Definition: private.h:153
char * name
Definition: private.h:150
char delim
Definition: private.h:151
IMAP-specific Mailbox data -.
Definition: mdata.h:40
A mailbox.
Definition: mailbox.h:79
A local copy of an email.
Definition: message.h:34
UID Sequence Set Iterator.
Definition: private.h:169
char * eostr
Definition: private.h:171
char * substr_end
Definition: private.h:177
unsigned int range_end
Definition: private.h:175
char * substr_cur
Definition: private.h:176
char * full_seqset
Definition: private.h:170
unsigned int range_cur
Definition: private.h:174