NeoMutt  2020-08-21-74-g346364
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 bool C_KeepFlagged;
43 extern unsigned char C_MboxType;
44 extern unsigned char C_Move;
45 extern char * C_Trash;
46 
47 extern struct EnumDef MboxTypeDef;
48 
49 /* flags for mutt_open_mailbox() */
50 typedef uint8_t OpenMailboxFlags;
51 #define MUTT_OPEN_NO_FLAGS 0
52 #define MUTT_NOSORT (1 << 0)
53 #define MUTT_APPEND (1 << 1)
54 #define MUTT_READONLY (1 << 2)
55 #define MUTT_QUIET (1 << 3)
56 #define MUTT_NEWFOLDER (1 << 4)
57 #define MUTT_PEEK (1 << 5)
60 #define MUTT_APPENDNEW (1 << 6)
61 
63 typedef uint8_t MsgOpenFlags;
64 #define MUTT_MSG_NO_FLAGS 0
65 #define MUTT_ADD_FROM (1 << 0)
66 #define MUTT_SET_DRAFT (1 << 1)
67 
68 
72 {
77 };
78 
82 struct Message
83 {
84  FILE *fp;
85  char *path;
87  bool write;
88  struct
89  {
90  bool read : 1;
91  bool flagged : 1;
92  bool replied : 1;
93  bool draft : 1;
94  } flags;
95  time_t received;
96 };
97 
104 struct MxOps
105 {
106  enum MailboxType type;
107  const char *name;
108  bool is_local;
109 
117  struct Account *(*ac_find) (struct Account *a, const char *path);
118 
126  int (*ac_add) (struct Account *a, struct Mailbox *m);
127 
135  int (*mbox_open) (struct Mailbox *m);
136 
144  int (*mbox_open_append)(struct Mailbox *m, OpenMailboxFlags flags);
145 
152  int (*mbox_check) (struct Mailbox *m);
153 
162  int (*mbox_check_stats)(struct Mailbox *m, int flags);
163 
170  int (*mbox_sync) (struct Mailbox *m);
171 
178  int (*mbox_close) (struct Mailbox *m);
179 
188  int (*msg_open) (struct Mailbox *m, struct Message *msg, int msgno);
189 
198  int (*msg_open_new) (struct Mailbox *m, struct Message *msg, const struct Email *e);
199 
207  int (*msg_commit) (struct Mailbox *m, struct Message *msg);
208 
216  int (*msg_close) (struct Mailbox *m, struct Message *msg);
217 
223  int (*msg_padding_size)(struct Mailbox *m);
224 
232  int (*msg_save_hcache) (struct Mailbox *m, struct Email *e);
233 
244  int (*tags_edit) (struct Mailbox *m, const char *tags, char *buf, size_t buflen);
245 
254  int (*tags_commit) (struct Mailbox *m, struct Email *e, char *buf);
255 
262  enum MailboxType (*path_probe)(const char *path, const struct stat *st);
263 
271  int (*path_canon) (char *buf, size_t buflen);
272 
281  int (*path_pretty) (char *buf, size_t buflen, const char *folder);
282 
290  int (*path_parent) (char *buf, size_t buflen);
291 };
292 
293 /* Wrappers for the Mailbox API, see MxOps */
294 int mx_mbox_check (struct Mailbox *m);
295 int mx_mbox_check_stats(struct Mailbox *m, int flags);
296 int mx_mbox_close (struct Context **ptr);
297 struct Context *mx_mbox_open (struct Mailbox *m, OpenMailboxFlags flags);
298 int mx_mbox_sync (struct Mailbox *m);
299 int mx_msg_close (struct Mailbox *m, struct Message **msg);
300 int mx_msg_commit (struct Mailbox *m, struct Message *msg);
301 struct Message *mx_msg_open_new (struct Mailbox *m, const struct Email *e, MsgOpenFlags flags);
302 struct Message *mx_msg_open (struct Mailbox *m, int msgno);
303 int mx_msg_padding_size(struct Mailbox *m);
304 int mx_save_hcache (struct Mailbox *m, struct Email *e);
305 int mx_path_canon (char *buf, size_t buflen, const char *folder, enum MailboxType *type);
306 int mx_path_canon2 (struct Mailbox *m, const char *folder);
307 int mx_path_parent (char *buf, size_t buflen);
308 int mx_path_pretty (char *buf, size_t buflen, const char *folder);
309 enum MailboxType mx_path_probe (const char *path);
310 struct Mailbox *mx_path_resolve (const char *path);
311 struct Mailbox *mx_resolve (const char *path_or_name);
312 int mx_tags_commit (struct Mailbox *m, struct Email *e, char *tags);
313 int mx_tags_edit (struct Mailbox *m, const char *tags, char *buf, size_t buflen);
314 
315 struct Account *mx_ac_find (struct Mailbox *m);
316 struct Mailbox *mx_mbox_find (struct Account *a, const char *path);
317 struct Mailbox *mx_mbox_find2 (const char *path);
318 bool mx_mbox_ac_link(struct Mailbox *m);
319 int mx_ac_add (struct Account *a, struct Mailbox *m);
320 int mx_ac_remove (struct Mailbox *m);
321 
322 int mx_access (const char *path, int flags);
323 void mx_alloc_memory (struct Mailbox *m);
324 int mx_check_empty (const char *path);
325 void mx_fastclose_mailbox(struct Mailbox *m);
326 const struct MxOps *mx_get_ops (enum MailboxType type);
327 bool mx_tags_is_supported(struct Mailbox *m);
328 
329 #endif /* MUTT_MX_H */
The "current" mailbox.
Definition: context.h:38
An enumeration.
Definition: enum.h:31
struct EnumDef MboxTypeDef
Definition: mx.c:98
bool is_local
True, if Mailbox type has local files/dirs.
Definition: mx.h:108
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:1569
bool replied
Definition: mx.h:92
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1206
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
return a stream pointer for a message
Definition: mx.c:1158
struct Mailbox * mx_resolve(const char *path_or_name)
Get a Mailbox from either a path or name.
Definition: mx.c:1765
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:1326
unsigned char C_MboxType
Config: Default type for creating new mailboxes.
Definition: mx.c:84
bool mx_mbox_ac_link(struct Mailbox *m)
Link a Mailbox to an existing or new Account.
Definition: mx.c:266
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
Definition: mx.h:50
int mx_mbox_check(struct Mailbox *m)
Check for new mail - Wrapper for MxOps::mbox_check()
Definition: mx.c:1139
unsigned char C_Move
Config: Move emails from C_Spoolfile to C_Mbox when read.
Definition: mx.c:85
MxCheckReturns
Return values from mx_mbox_check()
Definition: mx.h:71
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:1399
Convenience wrapper for the config headers.
int mx_access(const char *path, int flags)
Wrapper for access, checks permissions on a given mailbox.
Definition: mx.c:183
Convenience wrapper for the core headers.
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1232
bool C_KeepFlagged
Config: Don&#39;t move flagged messages from C_Spoolfile to C_Mbox.
Definition: mx.c:83
enum MailboxType type
Mailbox type, e.g. MUTT_IMAP.
Definition: mx.h:106
int mx_ac_remove(struct Mailbox *m)
Remove a Mailbox from an Account and delete Account if empty.
Definition: mx.c:1799
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:1834
struct Message * mx_msg_open_new(struct Mailbox *m, const struct Email *e, MsgOpenFlags flags)
Open a new message.
Definition: mx.c:1072
struct Account * mx_ac_find(struct Mailbox *m)
Find the Account owning a Mailbox.
Definition: mx.c:1583
bool flagged
Definition: mx.h:91
A local copy of an email.
Definition: mx.h:82
struct Message::@0 flags
A mailbox.
Definition: mailbox.h:81
Nondestructive flags change (IMAP)
Definition: mx.h:76
char * C_Trash
Config: Folder to put deleted emails.
Definition: mx.c:86
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1696
int mx_check_empty(const char *path)
Is the mailbox empty.
Definition: mx.c:1267
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:1817
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:141
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1607
struct Context * mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:303
bool draft
Definition: mx.h:93
void mx_fastclose_mailbox(struct Mailbox *m)
free up memory associated with the Mailbox
Definition: mx.c:445
uint8_t MsgOpenFlags
Flags for mx_msg_open_new(), e.g. MUTT_ADD_FROM.
Definition: mx.h:63
int mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add()
Definition: mx.c:1783
struct Mailbox * mx_mbox_find2(const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1669
bool write
nonzero if message is open for writing
Definition: mx.h:87
int mx_path_pretty(char *buf, size_t buflen, const char *folder)
Abbreviate a mailbox path - Wrapper for MxOps::path_pretty()
Definition: mx.c:1528
const char * name
Mailbox name, e.g. "imap".
Definition: mx.h:107
int mx_path_parent(char *buf, size_t buflen)
Find the parent of a mailbox path - Wrapper for MxOps::path_parent()
Definition: mx.c:1553
char * committed_path
the final path generated by mx_msg_commit()
Definition: mx.h:86
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:1306
int mbox_check(struct Mailbox *m, struct stat *sb, bool check_stats)
FILE * fp
pointer to the message data
Definition: mx.h:84
time_t received
the time at which this message was received
Definition: mx.h:95
Couldn&#39;t lock the Mailbox.
Definition: mx.h:74
New mail received in Mailbox.
Definition: mx.h:73
bool read
Definition: mx.h:90
Mailbox was reopened.
Definition: mx.h:75
int mx_msg_commit(struct Mailbox *m, struct Message *msg)
Commit a message to a folder - Wrapper for MxOps::msg_commit()
Definition: mx.c:1185
int mx_mbox_sync(struct Mailbox *m)
Save changes to mailbox.
Definition: mx.c:937
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1353
int mx_path_canon2(struct Mailbox *m, const char *folder)
Canonicalise the path to realpath.
Definition: mx.c:1500
int mx_mbox_close(struct Context **ptr)
Save changes and close mailbox.
Definition: mx.c:630
char * path
path to temp file
Definition: mx.h:85
The Mailbox API.
Definition: mx.h:104
bool mx_tags_is_supported(struct Mailbox *m)
return true if mailbox support tagging
Definition: mx.c:1343