NeoMutt  2020-06-26-30-g76c339
Teaching an old dog new tricks
DOXYGEN
mx.h
Go to the documentation of this file.
1 
25 #ifndef MUTT_MX_H
26 #define MUTT_MX_H
27 
28 #include <stdbool.h>
29 #include <stdint.h>
30 #include <stdio.h>
31 #include <time.h>
32 #include "config/lib.h"
33 #include "core/lib.h"
34 
35 struct Email;
36 struct Context;
37 struct stat;
38 
39 extern const struct MxOps *mx_ops[];
40 
41 /* These Config Variables are only used in mx.c */
42 extern unsigned char C_CatchupNewsgroup;
43 extern bool C_KeepFlagged;
44 extern unsigned char C_MboxType;
45 extern unsigned char C_Move;
46 extern char * C_Trash;
47 
48 extern struct EnumDef MboxTypeDef;
49 
50 /* flags for mutt_open_mailbox() */
51 typedef uint8_t OpenMailboxFlags;
52 #define MUTT_OPEN_NO_FLAGS 0
53 #define MUTT_NOSORT (1 << 0)
54 #define MUTT_APPEND (1 << 1)
55 #define MUTT_READONLY (1 << 2)
56 #define MUTT_QUIET (1 << 3)
57 #define MUTT_NEWFOLDER (1 << 4)
58 #define MUTT_PEEK (1 << 5)
61 #define MUTT_APPENDNEW (1 << 6)
62 
64 typedef uint8_t MsgOpenFlags;
65 #define MUTT_MSG_NO_FLAGS 0
66 #define MUTT_ADD_FROM (1 << 0)
67 #define MUTT_SET_DRAFT (1 << 1)
68 
69 
73 {
78 };
79 
83 struct Message
84 {
85  FILE *fp;
86  char *path;
88  bool write;
89  struct
90  {
91  bool read : 1;
92  bool flagged : 1;
93  bool replied : 1;
94  bool draft : 1;
95  } flags;
96  time_t received;
97 };
98 
105 struct MxOps
106 {
107  enum MailboxType type;
108  const char *name;
109  bool is_local;
110 
118  struct Account *(*ac_find) (struct Account *a, const char *path);
119 
127  int (*ac_add) (struct Account *a, struct Mailbox *m);
128 
136  int (*mbox_open) (struct Mailbox *m);
137 
145  int (*mbox_open_append)(struct Mailbox *m, OpenMailboxFlags flags);
146 
154  int (*mbox_check) (struct Mailbox *m, int *index_hint);
155 
164  int (*mbox_check_stats)(struct Mailbox *m, int flags);
165 
173  int (*mbox_sync) (struct Mailbox *m, int *index_hint);
174 
181  int (*mbox_close) (struct Mailbox *m);
182 
191  int (*msg_open) (struct Mailbox *m, struct Message *msg, int msgno);
192 
201  int (*msg_open_new) (struct Mailbox *m, struct Message *msg, struct Email *e);
202 
210  int (*msg_commit) (struct Mailbox *m, struct Message *msg);
211 
219  int (*msg_close) (struct Mailbox *m, struct Message *msg);
220 
226  int (*msg_padding_size)(struct Mailbox *m);
227 
235  int (*msg_save_hcache) (struct Mailbox *m, struct Email *e);
236 
247  int (*tags_edit) (struct Mailbox *m, const char *tags, char *buf, size_t buflen);
248 
257  int (*tags_commit) (struct Mailbox *m, struct Email *e, char *buf);
258 
265  enum MailboxType (*path_probe)(const char *path, const struct stat *st);
266 
274  int (*path_canon) (char *buf, size_t buflen);
275 
284  int (*path_pretty) (char *buf, size_t buflen, const char *folder);
285 
293  int (*path_parent) (char *buf, size_t buflen);
294 };
295 
296 /* Wrappers for the Mailbox API, see MxOps */
297 int mx_mbox_check (struct Mailbox *m, int *index_hint);
298 int mx_mbox_check_stats(struct Mailbox *m, int flags);
299 int mx_mbox_close (struct Context **ptr);
300 struct Context *mx_mbox_open (struct Mailbox *m, OpenMailboxFlags flags);
301 int mx_mbox_sync (struct Mailbox *m, int *index_hint);
302 int mx_msg_close (struct Mailbox *m, struct Message **msg);
303 int mx_msg_commit (struct Mailbox *m, struct Message *msg);
304 struct Message *mx_msg_open_new (struct Mailbox *m, struct Email *e, MsgOpenFlags flags);
305 struct Message *mx_msg_open (struct Mailbox *m, int msgno);
306 int mx_msg_padding_size(struct Mailbox *m);
307 int mx_save_hcache (struct Mailbox *m, struct Email *e);
308 int mx_path_canon (char *buf, size_t buflen, const char *folder, enum MailboxType *type);
309 int mx_path_canon2 (struct Mailbox *m, const char *folder);
310 int mx_path_parent (char *buf, size_t buflen);
311 int mx_path_pretty (char *buf, size_t buflen, const char *folder);
312 enum MailboxType mx_path_probe (const char *path);
313 struct Mailbox *mx_path_resolve (const char *path);
314 int mx_tags_commit (struct Mailbox *m, struct Email *e, char *tags);
315 int mx_tags_edit (struct Mailbox *m, const char *tags, char *buf, size_t buflen);
316 
317 struct Account *mx_ac_find (struct Mailbox *m);
318 struct Mailbox *mx_mbox_find (struct Account *a, const char *path);
319 struct Mailbox *mx_mbox_find2(const char *path);
320 int mx_ac_add (struct Account *a, struct Mailbox *m);
321 int mx_ac_remove (struct Mailbox *m);
322 
323 int mx_access (const char *path, int flags);
324 void mx_alloc_memory (struct Mailbox *m);
325 int mx_check_empty (const char *path);
326 void mx_fastclose_mailbox(struct Mailbox *m);
327 const struct MxOps *mx_get_ops (enum MailboxType type);
328 bool mx_tags_is_supported(struct Mailbox *m);
329 
330 #endif /* MUTT_MX_H */
The "current" mailbox.
Definition: context.h:37
An enumeration.
Definition: enum.h:31
struct EnumDef MboxTypeDef
Definition: mx.c:99
bool is_local
True, if Mailbox type has local files/dirs.
Definition: mx.h:109
The envelope/body of an email.
Definition: email.h:37
int mx_msg_padding_size(struct Mailbox *m)
Bytes of padding between messages - Wrapper for MxOps::msg_padding_size()
Definition: mx.c:1544
bool replied
Definition: mx.h:93
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1181
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
return a stream pointer for a message
Definition: mx.c:1133
A group of associated Mailboxes.
Definition: account.h:36
int mx_tags_commit(struct Mailbox *m, struct Email *e, char *tags)
Save tags to the Mailbox - Wrapper for MxOps::tags_commit()
Definition: mx.c:1301
struct Message * mx_msg_open_new(struct Mailbox *m, struct Email *e, MsgOpenFlags flags)
Open a new message.
Definition: mx.c:1046
unsigned char C_MboxType
Config: Default type for creating new mailboxes.
Definition: mx.c:85
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
Definition: mx.h:51
unsigned char C_Move
Config: Move emails from C_Spoolfile to C_Mbox when read.
Definition: mx.c:86
MxCheckReturns
Return values from mx_mbox_check()
Definition: mx.h:72
int mx_path_canon(char *buf, size_t buflen, const char *folder, enum MailboxType *type)
Canonicalise a mailbox path - Wrapper for MxOps::path_canon()
Definition: mx.c:1374
Convenience wrapper for the config headers.
int mx_mbox_sync(struct Mailbox *m, int *index_hint)
Save changes to mailbox.
Definition: mx.c:911
unsigned char C_CatchupNewsgroup
Config: (nntp) Mark all articles as read when leaving a newsgroup.
Definition: mx.c:83
int mx_access(const char *path, int flags)
Wrapper for access, checks permissions on a given mailbox.
Definition: mx.c:181
Convenience wrapper for the core headers.
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1207
bool C_KeepFlagged
Config: Don&#39;t move flagged messages from C_Spoolfile to C_Mbox.
Definition: mx.c:84
enum MailboxType type
Mailbox type, e.g. MUTT_IMAP.
Definition: mx.h:107
int mx_ac_remove(struct Mailbox *m)
Remove a Mailbox from an Account and delete Account if empty.
Definition: mx.c:1707
int mx_mbox_check(struct Mailbox *m, int *index_hint)
Check for new mail - Wrapper for MxOps::mbox_check()
Definition: mx.c:1114
int mx_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Wrapper for MxOps::msg_save_hcache()
Definition: mx.c:1742
struct Account * mx_ac_find(struct Mailbox *m)
Find the Account owning a Mailbox.
Definition: mx.c:1558
bool flagged
Definition: mx.h:92
A local copy of an email.
Definition: mx.h:83
struct Message::@0 flags
A mailbox.
Definition: mailbox.h:81
Nondestructive flags change (IMAP)
Definition: mx.h:77
char * C_Trash
Config: Folder to put deleted emails.
Definition: mx.c:87
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1671
int mx_check_empty(const char *path)
Is the mailbox empty.
Definition: mx.c:1242
int mx_mbox_check_stats(struct Mailbox *m, int flags)
Check the statistics for a mailbox - Wrapper for MxOps::mbox_check_stats()
Definition: mx.c:1725
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:142
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1582
struct Context * mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:265
bool draft
Definition: mx.h:94
void mx_fastclose_mailbox(struct Mailbox *m)
free up memory associated with the Mailbox
Definition: mx.c:424
uint8_t MsgOpenFlags
Flags for mx_msg_open_new(), e.g. MUTT_ADD_FROM.
Definition: mx.h:64
int mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add()
Definition: mx.c:1691
struct Mailbox * mx_mbox_find2(const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1644
bool write
nonzero if message is open for writing
Definition: mx.h:88
int mx_path_pretty(char *buf, size_t buflen, const char *folder)
Abbreviate a mailbox path - Wrapper for MxOps::path_pretty()
Definition: mx.c:1503
const char * name
Mailbox name, e.g. "imap".
Definition: mx.h:108
int mx_path_parent(char *buf, size_t buflen)
Find the parent of a mailbox path - Wrapper for MxOps::path_parent()
Definition: mx.c:1528
char * committed_path
the final path generated by mx_msg_commit()
Definition: mx.h:87
MailboxType
Supported mailbox formats.
Definition: mailbox.h:43
int mx_tags_edit(struct Mailbox *m, const char *tags, char *buf, size_t buflen)
start the tag editor of the mailbox
Definition: mx.c:1281
int mbox_check(struct Mailbox *m, struct stat *sb, bool check_stats)
FILE * fp
pointer to the message data
Definition: mx.h:85
time_t received
the time at which this message was received
Definition: mx.h:96
Couldn&#39;t lock the Mailbox.
Definition: mx.h:75
New mail received in Mailbox.
Definition: mx.h:74
bool read
Definition: mx.h:91
Mailbox was reopened.
Definition: mx.h:76
int mx_msg_commit(struct Mailbox *m, struct Message *msg)
Commit a message to a folder - Wrapper for MxOps::msg_commit()
Definition: mx.c:1160
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1328
int mx_path_canon2(struct Mailbox *m, const char *folder)
Canonicalise the path to realpath.
Definition: mx.c:1475
int mx_mbox_close(struct Context **ptr)
Save changes and close mailbox.
Definition: mx.c:603
char * path
path to temp file
Definition: mx.h:86
The Mailbox API.
Definition: mx.h:105
bool mx_tags_is_supported(struct Mailbox *m)
return true if mailbox support tagging
Definition: mx.c:1318