NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
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 #include "mutt.h"
34 
35 struct Buffer;
36 struct ConnAccount;
37 struct Email;
38 struct ImapAccountData;
39 struct ImapMboxData;
40 struct ListHead;
41 struct Mailbox;
42 struct Message;
43 struct Progress;
44 
45 #define IMAP_PORT 143
46 #define IMAP_SSL_PORT 993
47 
48 /* logging levels */
49 #define IMAP_LOG_CMD 2
50 #define IMAP_LOG_LTRL 3
51 #define IMAP_LOG_PASS 5
52 
53 /* IMAP command responses. Used in ImapCommand.state too */
54 #define IMAP_RES_NO -2
55 #define IMAP_RES_BAD -1
56 #define IMAP_RES_OK 0
57 #define IMAP_RES_CONTINUE 1
58 #define IMAP_RES_RESPOND 2
59 #define IMAP_RES_NEW 3
60 
61 #define SEQ_LEN 16
62 #define IMAP_MAX_CMDLEN 1024
63 
64 typedef uint8_t ImapOpenFlags;
65 #define IMAP_OPEN_NO_FLAGS 0
66 #define IMAP_REOPEN_ALLOW (1 << 0)
67 #define IMAP_EXPUNGE_EXPECTED (1 << 1)
68 #define IMAP_EXPUNGE_PENDING (1 << 2)
69 #define IMAP_NEWMAIL_PENDING (1 << 3)
70 #define IMAP_FLAGS_PENDING (1 << 4)
71 
72 typedef uint8_t ImapCmdFlags;
73 #define IMAP_CMD_NO_FLAGS 0
74 #define IMAP_CMD_PASS (1 << 0)
75 #define IMAP_CMD_QUEUE (1 << 1)
76 #define IMAP_CMD_POLL (1 << 2)
77 #define IMAP_CMD_SINGLE (1 << 3)
78 
79 
83 {
87 };
88 
89 /* length of "DD-MMM-YYYY HH:MM:SS +ZZzz" (null-terminated) */
90 #define IMAP_DATELEN 27
91 
96 {
97  IMAP_FATAL = 1,
99 };
100 
105 {
106  /* States */
111 
112  /* and pseudo-states */
114 };
115 
121 typedef uint32_t ImapCapFlags;
122 #define IMAP_CAP_NO_FLAGS 0
123 #define IMAP_CAP_IMAP4 (1 << 0)
124 #define IMAP_CAP_IMAP4REV1 (1 << 1)
125 #define IMAP_CAP_STATUS (1 << 2)
126 #define IMAP_CAP_ACL (1 << 3)
127 #define IMAP_CAP_NAMESPACE (1 << 4)
128 #define IMAP_CAP_AUTH_CRAM_MD5 (1 << 5)
129 #define IMAP_CAP_AUTH_GSSAPI (1 << 6)
130 #define IMAP_CAP_AUTH_ANONYMOUS (1 << 7)
131 #define IMAP_CAP_AUTH_OAUTHBEARER (1 << 8)
132 #define IMAP_CAP_STARTTLS (1 << 9)
133 #define IMAP_CAP_LOGINDISABLED (1 << 10)
134 #define IMAP_CAP_IDLE (1 << 11)
135 #define IMAP_CAP_SASL_IR (1 << 12)
136 #define IMAP_CAP_ENABLE (1 << 13)
137 #define IMAP_CAP_CONDSTORE (1 << 14)
138 #define IMAP_CAP_QRESYNC (1 << 15)
139 #define IMAP_CAP_LIST_EXTENDED (1 << 16)
140 #define IMAP_CAP_COMPRESS (1 << 17)
141 #define IMAP_CAP_X_GM_EXT_1 (1 << 18)
142 
143 #define IMAP_CAP_ALL ((1 << 19) - 1)
144 
148 struct ImapList
149 {
150  char *name;
151  char delim;
152  bool noselect;
154 };
155 
160 {
161  char seq[SEQ_LEN + 1];
162  int state;
163 };
164 
169 {
170  char *full_seqset;
171  char *eostr;
172  int in_range;
173  int down;
174  unsigned int range_cur;
175  unsigned int range_end;
176  char *substr_cur;
177  char *substr_end;
178 };
179 
180 /* -- private IMAP functions -- */
181 /* imap.c */
182 int imap_create_mailbox(struct ImapAccountData *adata, char *mailbox);
183 int imap_rename_mailbox(struct ImapAccountData *adata, char *oldname, const char *newname);
184 int imap_exec_msgset(struct Mailbox *m, const char *pre, const char *post,
185  enum MessageType flag, bool changed, bool invert);
186 int imap_open_connection(struct ImapAccountData *adata);
187 void imap_close_connection(struct ImapAccountData *adata);
188 int imap_read_literal(FILE *fp, struct ImapAccountData *adata, unsigned long bytes, struct Progress *pbar);
189 void imap_expunge_mailbox(struct Mailbox *m);
190 int imap_login(struct ImapAccountData *adata);
191 int imap_sync_message_for_copy(struct Mailbox *m, struct Email *e, struct Buffer *cmd, enum QuadOption *err_continue);
192 bool imap_has_flag(struct ListHead *flag_list, const char *flag);
193 int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata);
194 
195 /* auth.c */
196 int imap_authenticate(struct ImapAccountData *adata);
197 
198 /* command.c */
199 int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr);
200 int imap_cmd_step(struct ImapAccountData *adata);
201 void imap_cmd_finish(struct ImapAccountData *adata);
202 bool imap_code(const char *s);
203 const char *imap_cmd_trailer(struct ImapAccountData *adata);
204 int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags);
205 int imap_cmd_idle(struct ImapAccountData *adata);
206 
207 /* message.c */
208 int imap_read_headers(struct Mailbox *m, unsigned int msn_begin, unsigned int msn_end, bool initial_download);
209 char *imap_set_flags(struct Mailbox *m, struct Email *e, char *s, bool *server_changes);
210 int imap_cache_del(struct Mailbox *m, struct Email *e);
211 int imap_cache_clean(struct Mailbox *m);
212 int imap_append_message(struct Mailbox *m, struct Message *msg);
213 
214 bool imap_msg_open(struct Mailbox *m, struct Message *msg, int msgno);
215 int imap_msg_close(struct Mailbox *m, struct Message *msg);
216 int imap_msg_commit(struct Mailbox *m, struct Message *msg);
217 int imap_msg_save_hcache(struct Mailbox *m, struct Email *e);
218 
219 /* util.c */
220 #ifdef USE_HCACHE
221 void imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata);
222 void imap_hcache_close(struct ImapMboxData *mdata);
223 struct Email *imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid);
224 int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e);
225 int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid);
226 int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata);
227 int imap_hcache_clear_uid_seqset(struct ImapMboxData *mdata);
228 char *imap_hcache_get_uid_seqset(struct ImapMboxData *mdata);
229 #endif
230 
231 enum QuadOption imap_continue(const char *msg, const char *resp);
232 void imap_error(const char *where, const char *msg);
233 void imap_mdata_cache_reset(struct ImapMboxData *mdata);
234 char *imap_fix_path(char delim, const char *mailbox, char *path, size_t plen);
235 void imap_cachepath(char delim, const char *mailbox, struct Buffer *dest);
236 int imap_get_literal_count(const char *buf, unsigned int *bytes);
237 char *imap_get_qualifier(char *buf);
238 char *imap_next_word(char *s);
239 void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path);
240 void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick);
241 void imap_unquote_string(char *s);
242 void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src);
243 void imap_unmunge_mbox_name(bool unicode, char *s);
244 struct SeqsetIterator *mutt_seqset_iterator_new(const char *seqset);
245 int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next);
246 void mutt_seqset_iterator_free(struct SeqsetIterator **ptr);
247 bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2);
248 void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen);
249 bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2);
250 
251 /* utf7.c */
252 void imap_utf_encode(bool unicode, char **s);
253 void imap_utf_decode(bool unicode, char **s);
254 void imap_allow_reopen(struct Mailbox *m);
255 void imap_disallow_reopen(struct Mailbox *m);
256 
257 /* search.c */
258 void cmd_parse_search(struct ImapAccountData *adata, const char *s);
259 
260 #endif /* MUTT_IMAP_PRIVATE_H */
int imap_cmd_idle(struct ImapAccountData *adata)
Enter the IDLE state.
Definition: command.c:1383
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
char * eostr
Definition: private.h:171
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *conn_account, char *path)
Make an absolute IMAP folder target.
Definition: util.c:823
void imap_disallow_reopen(struct Mailbox *m)
Disallow re-opening a folder upon expunge.
Definition: util.c:1034
void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen)
Get an IMAP folder&#39;s parent.
Definition: util.c:120
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:2153
The envelope/body of an email.
Definition: email.h:37
void imap_mdata_cache_reset(struct ImapMboxData *mdata)
Release and clear cache data of ImapMboxData structure.
Definition: util.c:106
Logged out from server.
Definition: private.h:98
int imap_rename_mailbox(struct ImapAccountData *adata, char *oldname, const char *newname)
Rename a mailbox.
Definition: imap.c:489
Imap connection failure.
Definition: private.h:86
Connection is authenticated.
Definition: private.h:109
Unrecoverable error occurred.
Definition: private.h:97
int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e)
Add an entry to the header cache.
Definition: util.c:381
int imap_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit() -.
Definition: message.c:2131
static size_t plen
Length of cached packet.
Definition: pgppacket.c:39
int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid)
Delete an item from the header cache.
Definition: util.c:399
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:914
int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata)
Store a UID Sequence Set in the header cache.
Definition: util.c:416
void imap_utf_decode(bool unicode, char **s)
Decode email from UTF-8 to local charset.
Definition: utf7.c:348
struct SeqsetIterator * mutt_seqset_iterator_new(const char *seqset)
Create a new Sequence Set Iterator.
Definition: util.c:1081
String manipulation buffer.
Definition: buffer.h:33
bool imap_msg_open(struct Mailbox *m, struct Message *msg, int msgno)
Open an email message in a Mailbox - Implements MxOps::msg_open() -.
Definition: message.c:1927
int imap_cmd_start(struct ImapAccountData *adata, const char *cmdstr)
Given an IMAP command, send it to the server.
Definition: command.c:1065
Items in an IMAP browser.
Definition: private.h:148
ImapExecResult
imap_exec return code
Definition: private.h:82
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
Definition: util.c:1049
void imap_cmd_finish(struct ImapAccountData *adata)
Attempt to perform cleanup.
Definition: command.c:1316
char * imap_hcache_get_uid_seqset(struct ImapMboxData *mdata)
Get a UID Sequence Set from the header cache.
Definition: util.c:452
char delim
Definition: private.h:151
uint8_t ImapOpenFlags
Flags, e.g. MUTT_THREAD_COLLAPSE.
Definition: private.h:64
A Progress Bar.
Definition: progress.c:47
int imap_create_mailbox(struct ImapAccountData *adata, char *mailbox)
Create a new mailbox.
Definition: imap.c:448
void cmd_parse_search(struct ImapAccountData *adata, const char *s)
store SEARCH response for later use
Definition: search.c:259
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:1870
Imap command executed or queued successfully.
Definition: private.h:84
QuadOption
Possible values for a quad-option.
Definition: quad.h:35
Convenience wrapper for the config headers.
int imap_login(struct ImapAccountData *adata)
Open an IMAP connection.
Definition: imap.c:1849
bool imap_code(const char *s)
Was the command successful.
Definition: command.c:1202
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:72
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition: util.c:792
int imap_cmd_step(struct ImapAccountData *adata)
Reads server responses from an IMAP command.
Definition: command.c:1079
Disconnected from server.
Definition: private.h:107
void imap_hcache_close(struct ImapMboxData *mdata)
Close the header cache.
Definition: util.c:340
MessageType
To set flags or match patterns.
Definition: mutt.h:85
Many unsorted constants and some structs.
unsigned int range_end
Definition: private.h:175
ImapFlags
IMAP server responses.
Definition: private.h:95
Mailbox is selected.
Definition: private.h:110
Connected to server.
Definition: private.h:108
IMAP command structure.
Definition: private.h:159
bool imap_has_flag(struct ListHead *flag_list, const char *flag)
Does the flag exist in the list.
Definition: imap.c:878
void imap_unquote_string(char *s)
equally stupid unquoting routine
Definition: util.c:877
void imap_error(const char *where, const char *msg)
show an error and abort
Definition: util.c:665
void imap_utf_encode(bool unicode, char **s)
Encode email from local charset to UTF-8.
Definition: utf7.c:318
int imap_open_connection(struct ImapAccountData *adata)
Open an IMAP connection.
Definition: imap.c:745
A local copy of an email.
Definition: mxapi.h:41
A mailbox.
Definition: mailbox.h:81
char * name
Definition: private.h:150
void mutt_seqset_iterator_free(struct SeqsetIterator **ptr)
Free a Sequence Set Iterator.
Definition: util.c:1159
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:1004
#define SEQ_LEN
Definition: private.h:61
const char * imap_cmd_trailer(struct ImapAccountData *adata)
Extra information after tagged command response if any.
Definition: command.c:1213
void imap_allow_reopen(struct Mailbox *m)
Allow re-opening a folder upon expunge.
Definition: util.c:1021
void imap_expunge_mailbox(struct Mailbox *m)
Purge messages from the server.
Definition: imap.c:676
Login details for a remote server.
Definition: connaccount.h:51
uint32_t ImapCapFlags
Capabilities we are interested in.
Definition: private.h:121
bool noinferiors
Definition: private.h:153
Connection is idle.
Definition: private.h:113
Imap command failure.
Definition: private.h:85
char * substr_cur
Definition: private.h:176
int imap_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close() -.
Definition: message.c:2145
int imap_get_literal_count(const char *buf, unsigned int *bytes)
write number of bytes in an IMAP literal into bytes
Definition: util.c:748
IMAP-specific Account data -.
Definition: adata.h:39
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.
Definition: util.c:775
int imap_authenticate(struct ImapAccountData *adata)
Authenticate to an IMAP server.
Definition: auth.c:107
struct Email * imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid)
Get a header cache entry by its UID.
Definition: util.c:356
char * imap_fix_path(char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition: util.c:687
IMAP-specific Mailbox data -.
Definition: mdata.h:38
bool mutt_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
int state
Command state, e.g. IMAP_RES_NEW.
Definition: private.h:162
uint8_t ImapCmdFlags
Flags for imap_exec(), e.g. IMAP_CMD_PASS.
Definition: private.h:72
void imap_cachepath(char delim, const char *mailbox, struct Buffer *dest)
Generate a cache path for a mailbox.
Definition: util.c:719
char * path
Path of Email (for local Mailboxes)
Definition: email.h:92
int imap_append_message(struct Mailbox *m, struct Message *msg)
Write an email back to the server.
Definition: message.c:1511
int imap_cache_clean(struct Mailbox *m)
Delete all the entries in the message cache.
Definition: message.c:1838
int imap_cache_del(struct Mailbox *m, struct Email *e)
Delete an email from the body cache.
Definition: message.c:1819
ImapState
IMAP connection state.
Definition: private.h:104
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.
Definition: imap.c:927
int imap_read_literal(FILE *fp, struct ImapAccountData *adata, unsigned long bytes, struct Progress *pbar)
Read bytes bytes from server into file.
Definition: imap.c:600
int imap_hcache_clear_uid_seqset(struct ImapMboxData *mdata)
Delete a UID Sequence Set from the header cache.
Definition: util.c:438
char * substr_end
Definition: private.h:177
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:1250
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:1299
void imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata)
Open a header cache.
Definition: util.c:297
char * full_seqset
Definition: private.h:170
void imap_close_connection(struct ImapAccountData *adata)
Close an IMAP connection.
Definition: imap.c:853
int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next)
Get the next UID from a Sequence Set.
Definition: util.c:1102
unsigned int range_cur
Definition: private.h:174
void imap_unmunge_mbox_name(bool unicode, char *s)
Remove quoting from a mailbox name.
Definition: util.c:931
bool noselect
Definition: private.h:152
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
quote string according to IMAP rules
Definition: util.c:840
UID Sequence Set Iterator.
Definition: private.h:168