NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
private.h
Go to the documentation of this file.
1
24
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#define IMAP_LOG_CMD 2
48#define IMAP_LOG_LTRL 3
49#define IMAP_LOG_PASS 5
50
51/* IMAP command responses. Used in ImapCommand.state too */
52#define IMAP_RES_NO -2
53#define IMAP_RES_BAD -1
54#define IMAP_RES_OK 0
55#define IMAP_RES_CONTINUE 1
56#define IMAP_RES_RESPOND 2
57#define IMAP_RES_NEW 3
58
60#define SEQ_LEN 16
61
75typedef uint8_t ImapOpenFlags;
76
81{
83 IMAP_CMD_PASS = 1U << 0,
84 IMAP_CMD_QUEUE = 1U << 1,
85 IMAP_CMD_POLL = 1U << 2,
86 IMAP_CMD_SINGLE = 1U << 3,
87};
88typedef uint8_t ImapCmdFlags;
89
99
101#define IMAP_DATELEN 27
102
111
116{
117 /* States */
122
123 /* and pseudo-states */
125};
126
157typedef uint32_t ImapCapFlags;
158
159#define IMAP_CAP_ALL ((1 << 21) - 1)
160
165{
166 char *name;
167 char delim;
168 bool noselect;
170};
171
176{
177 char seq[SEQ_LEN + 1];
178 int state;
179};
180
185{
187 char *eostr;
189 int down;
190 unsigned int range_cur;
191 unsigned int range_end;
194};
195
196/* -- private IMAP functions -- */
197/* imap.c */
198int imap_create_mailbox(struct ImapAccountData *adata, const char *mailbox);
199int imap_rename_mailbox(struct ImapAccountData *adata, char *oldname, const char *newname);
200int imap_open_connection(struct ImapAccountData *adata);
201void imap_close_connection(struct ImapAccountData *adata);
202int imap_read_literal(FILE *fp, struct ImapAccountData *adata, unsigned long bytes, struct Progress *progress);
203void imap_expunge_mailbox(struct Mailbox *m, bool resort);
204int imap_login(struct ImapAccountData *adata);
205int imap_sync_message_for_copy(struct Mailbox *m, struct Email *e, struct Buffer *cmd, enum QuadOption *err_continue);
206bool imap_has_flag(struct ListHead *flag_list, const char *flag);
207int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata);
208int imap_reopen_mailbox(struct ImapAccountData *adata);
209
210/* auth.c */
211int imap_authenticate(struct ImapAccountData *adata);
212
213/* command.c */
214int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr);
215int imap_cmd_step(struct ImapAccountData *adata);
216void imap_cmd_finish(struct ImapAccountData *adata);
217bool imap_code(const char *s);
218const char *imap_cmd_trailer(struct ImapAccountData *adata);
219int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags);
220int imap_cmd_idle(struct ImapAccountData *adata);
221
222/* message.c */
223int imap_read_headers(struct Mailbox *m, unsigned int msn_begin, unsigned int msn_end, bool initial_download);
224char *imap_set_flags(struct Mailbox *m, struct Email *e, char *s, bool *server_changes);
225int imap_cache_del(struct Mailbox *m, struct Email *e);
226int imap_cache_clean(struct Mailbox *m);
227int imap_append_message(struct Mailbox *m, struct Message *msg);
228
229bool imap_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e);
230int imap_msg_close(struct Mailbox *m, struct Message *msg);
231int imap_msg_commit(struct Mailbox *m, struct Message *msg);
232int imap_msg_save_hcache(struct Mailbox *m, struct Email *e);
233
234/* util.c */
235#ifdef USE_HCACHE
236void imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata, bool create);
237void imap_hcache_close(struct ImapMboxData *mdata);
238struct Email *imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid);
239int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e);
240int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid);
243char *imap_hcache_get_uid_seqset(struct ImapMboxData *mdata);
244#endif
245
246enum QuadOption imap_continue(const char *msg, const char *resp);
247void imap_error(const char *where, const char *msg);
248void imap_mdata_cache_reset(struct ImapMboxData *mdata);
249char *imap_fix_path(const char *mailbox, char *path, size_t plen);
250char *imap_fix_path_with_delim(char delim, const char *mailbox, char *path, size_t plen);
251void imap_cachepath(char delim, const char *mailbox, struct Buffer *dest);
252int imap_get_literal_count(char *buf, unsigned int *bytes);
253char *imap_get_qualifier(char *buf);
254char *imap_next_word(char *s);
255void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path);
256void imap_buf_qualify_path(struct Buffer *buf, struct ConnAccount *conn_account, char *path);
257void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick);
258void imap_unquote_string(char *s);
259void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src);
260void imap_unmunge_mbox_name(bool unicode, char *s);
261struct SeqsetIterator *mutt_seqset_iterator_new(const char *seqset);
262int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next);
264bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2);
265void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen);
266bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2);
267
268/* utf7.c */
269void imap_utf_encode(bool unicode, char **s);
270void imap_utf_decode(bool unicode, char **s);
271void imap_allow_reopen(struct Mailbox *m);
272void imap_disallow_reopen(struct Mailbox *m);
273
274/* search.c */
275void cmd_parse_search(struct ImapAccountData *adata, const char *s);
276
277#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:2216
int imap_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit() -.
Definition message.c:2202
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:2009
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:2224
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition command.c:1216
void imap_unmunge_mbox_name(bool unicode, char *s)
Remove quoting from a mailbox name.
Definition util.c:988
int imap_cache_clean(struct Mailbox *m)
Delete all the entries in the message cache.
Definition message.c:1920
void imap_close_connection(struct ImapAccountData *adata)
Close an IMAP connection.
Definition imap.c:1029
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path)
Make an absolute IMAP folder target.
Definition util.c:860
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:1952
void imap_allow_reopen(struct Mailbox *m)
Allow re-opening a folder upon expunge.
Definition util.c:1078
void imap_disallow_reopen(struct Mailbox *m)
Disallow re-opening a folder upon expunge.
Definition util.c:1091
ImapState
IMAP connection state.
Definition private.h:116
@ IMAP_DISCONNECTED
Disconnected from server.
Definition private.h:118
@ IMAP_IDLE
Connection is idle.
Definition private.h:124
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition private.h:120
@ IMAP_SELECTED
Mailbox is selected.
Definition private.h:121
@ IMAP_CONNECTED
Connected to server.
Definition private.h:119
uint8_t ImapOpenFlags
Definition private.h:75
void imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata, bool create)
Open a header cache.
Definition util.c:307
int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata)
Store a UID Sequence Set in the header cache.
Definition util.c:423
int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e)
Add an entry to the header cache.
Definition util.c:388
int imap_reopen_mailbox(struct ImapAccountData *adata)
Re-SELECT the current mailbox after reconnecting.
Definition imap.c:2261
void imap_mdata_cache_reset(struct ImapMboxData *mdata)
Release and clear cache data of ImapMboxData structure.
Definition util.c:111
void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen)
Get an IMAP folder's parent.
Definition util.c:127
struct SeqsetIterator * mutt_seqset_iterator_new(const char *seqset)
Create a new Sequence Set Iterator.
Definition util.c:1138
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:891
char * imap_hcache_get_uid_seqset(struct ImapMboxData *mdata)
Get a UID Sequence Set from the header cache.
Definition util.c:458
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:654
void imap_unquote_string(char *s)
Equally stupid unquoting routine.
Definition util.c:934
struct Email * imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid)
Get a header cache entry by its UID.
Definition util.c:363
const char * imap_cmd_trailer(struct ImapAccountData *adata)
Extra information after tagged command response if any.
Definition command.c:1383
int imap_append_message(struct Mailbox *m, struct Message *msg)
Write an email back to the server.
Definition message.c:1555
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:874
int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next)
Get the next UID from a Sequence Set.
Definition util.c:1159
ImapExecResult
Imap_exec return code.
Definition private.h:94
@ IMAP_EXEC_SUCCESS
Imap command executed or queued successfully.
Definition private.h:95
@ IMAP_EXEC_ERROR
Imap command failure.
Definition private.h:96
@ IMAP_EXEC_FATAL
Imap connection failure.
Definition private.h:97
void mutt_seqset_iterator_free(struct SeqsetIterator **ptr)
Free a Sequence Set Iterator.
Definition util.c:1218
int imap_cmd_idle(struct ImapAccountData *adata)
Enter the IDLE state.
Definition command.c:1586
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition command.c:1230
int imap_get_literal_count(char *buf, unsigned int *bytes)
Write number of bytes in an IMAP literal into bytes.
Definition util.c:785
void imap_expunge_mailbox(struct Mailbox *m, bool resort)
Purge messages from the server.
Definition imap.c:849
int imap_open_connection(struct ImapAccountData *adata)
Open an IMAP connection.
Definition imap.c:921
#define SEQ_LEN
Length of IMAP sequence buffer.
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:754
int imap_rename_mailbox(struct ImapAccountData *adata, char *oldname, const char *newname)
Rename a mailbox.
Definition imap.c:584
int imap_create_mailbox(struct ImapAccountData *adata, const char *mailbox)
Create a new mailbox.
Definition imap.c:542
void imap_utf_decode(bool unicode, char **s)
Decode email from UTF-8 to local charset.
Definition utf7.c:430
char * imap_fix_path(const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition util.c:686
void imap_error(const char *where, const char *msg)
Show an error and abort.
Definition util.c:665
void imap_hcache_close(struct ImapMboxData *mdata)
Close the header cache.
Definition util.c:348
int imap_cache_del(struct Mailbox *m, struct Email *e)
Delete an email from the body cache.
Definition message.c:1901
ImapFlags
IMAP server responses.
Definition private.h:107
@ IMAP_BYE
Logged out from server.
Definition private.h:109
@ IMAP_FATAL
Unrecoverable error occurred.
Definition private.h:108
char * imap_fix_path_with_delim(char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition util.c:718
int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid)
Delete an item from the header cache.
Definition util.c:406
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:1366
ImapOpenFlag
State flags for IMAP mailbox reopen and sync handling.
Definition private.h:66
@ IMAP_EXPUNGE_PENDING
Messages on the server have been expunged.
Definition private.h:70
@ IMAP_NEWMAIL_PENDING
New mail is waiting on the server.
Definition private.h:71
@ IMAP_SYNC_IN_PROGRESS
Sync is in progress, block expunge/newmail processing.
Definition private.h:73
@ IMAP_EXPUNGE_EXPECTED
Messages will be expunged from the server.
Definition private.h:69
@ IMAP_OPEN_NONE
No flags are set.
Definition private.h:67
@ IMAP_FLAGS_PENDING
Flags have changed on the server.
Definition private.h:72
@ IMAP_REOPEN_ALLOW
Allow re-opening a folder upon expunge.
Definition private.h:68
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:1114
bool imap_code(const char *s)
Was the command successful.
Definition command.c:1372
int imap_hcache_clear_uid_seqset(struct ImapMboxData *mdata)
Delete a UID Sequence Set from the header cache.
Definition util.c:444
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:1106
void cmd_parse_search(struct ImapAccountData *adata, const char *s)
Store SEARCH response for later use.
Definition search.c:260
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:971
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:704
int imap_authenticate(struct ImapAccountData *adata)
Authenticate to an IMAP server.
Definition auth.c:116
ImapCapFlag
Capabilities we are interested in.
Definition private.h:133
@ IMAP_CAP_CONDSTORE
RFC7162.
Definition private.h:150
@ IMAP_CAP_QRESYNC
RFC7162.
Definition private.h:151
@ IMAP_CAP_NONE
No flags are set.
Definition private.h:134
@ IMAP_CAP_STARTTLS
RFC2595: STARTTLS.
Definition private.h:145
@ IMAP_CAP_AUTH_CRAM_MD5
RFC2195: CRAM-MD5 authentication.
Definition private.h:140
@ IMAP_CAP_AUTH_ANONYMOUS
AUTH=ANONYMOUS.
Definition private.h:142
@ IMAP_CAP_X_GM_EXT_1
https://developers.google.com/gmail/imap/imap-extensions
Definition private.h:154
@ IMAP_CAP_COMPRESS
RFC4978: COMPRESS=DEFLATE.
Definition private.h:153
@ IMAP_CAP_ENABLE
RFC5161.
Definition private.h:149
@ IMAP_CAP_IMAP4REV1
Server supports IMAP4rev1.
Definition private.h:136
@ IMAP_CAP_IMAP4
Server supports IMAP4.
Definition private.h:135
@ IMAP_CAP_NAMESPACE
RFC2342: IMAP4 Namespace.
Definition private.h:139
@ IMAP_CAP_LOGINDISABLED
RFC2595: LOGINDISABLED.
Definition private.h:146
@ IMAP_CAP_ID
RFC2971: IMAP4 ID extension.
Definition private.h:155
@ IMAP_CAP_AUTH_XOAUTH2
AUTH=XOAUTH2, deprecated but used by OWA.
Definition private.h:144
@ IMAP_CAP_AUTH_GSSAPI
RFC1731: GSSAPI authentication.
Definition private.h:141
@ IMAP_CAP_ACL
RFC2086: IMAP4 ACL extension.
Definition private.h:138
@ IMAP_CAP_STATUS
Server supports STATUS command.
Definition private.h:137
@ IMAP_CAP_AUTH_OAUTHBEARER
RFC7628: AUTH=OAUTHBEARER.
Definition private.h:143
@ IMAP_CAP_SASL_IR
SASL initial response draft.
Definition private.h:148
@ IMAP_CAP_LIST_EXTENDED
RFC5258: IMAP4 LIST Command Extensions.
Definition private.h:152
@ IMAP_CAP_IDLE
RFC2177: IDLE.
Definition private.h:147
bool imap_has_flag(struct ListHead *flag_list, const char *flag)
Does the flag exist in the list.
Definition imap.c:1054
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition util.c:829
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:1420
uint8_t ImapCmdFlags
Definition private.h:88
ImapCmdFlag
Flags for imap_exec(), e.g.
Definition private.h:81
@ IMAP_CMD_POLL
Poll the tcp connection before running the imap command.
Definition private.h:85
@ IMAP_CMD_SINGLE
Run a single command.
Definition private.h:86
@ IMAP_CMD_NONE
No flags are set.
Definition private.h:82
@ IMAP_CMD_QUEUE
Queue a command, do not execute.
Definition private.h:84
@ IMAP_CMD_PASS
Command contains a password. Suppress logging.
Definition private.h:83
uint32_t ImapCapFlags
Definition private.h:157
int imap_login(struct ImapAccountData *adata)
Open an IMAP connection.
Definition imap.c:2013
void imap_cmd_finish(struct ImapAccountData *adata)
Attempt to perform cleanup.
Definition command.c:1511
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.
Definition util.c:812
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:59
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:176
int state
Command state, e.g. IMAP_RES_NEW.
Definition private.h:178
char seq[SEQ_LEN+1]
Command tag, e.g. 'a0001'.
Definition private.h:177
Items in an IMAP browser.
Definition private.h:165
bool noselect
Mailbox is not selectable.
Definition private.h:168
bool noinferiors
Mailbox has no children.
Definition private.h:169
char * name
Mailbox name.
Definition private.h:166
char delim
Hierarchy delimiter.
Definition private.h:167
IMAP-specific Mailbox data -.
Definition mdata.h:40
A mailbox.
Definition mailbox.h:81
A local copy of an email.
Definition message.h:34
UID Sequence Set Iterator.
Definition private.h:185
char * eostr
End of string.
Definition private.h:187
char * substr_end
End of substring.
Definition private.h:193
unsigned int range_end
End of range.
Definition private.h:191
int down
Counting down.
Definition private.h:189
char * substr_cur
Current position in substring.
Definition private.h:192
int in_range
Currently in a range.
Definition private.h:188
char * full_seqset
Full sequence set string.
Definition private.h:186
unsigned int range_cur
Current range value.
Definition private.h:190