NeoMutt  2020-11-20
Teaching an old dog new tricks
Go to the documentation of this file.
25 #ifndef MUTT_MX_H
26 #define MUTT_MX_H
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"
35 struct Email;
36 struct Context;
37 struct stat;
39 extern const struct MxOps *mx_ops[];
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;
47 extern struct EnumDef MboxTypeDef;
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)
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)
72 {
77 };
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 };
104 struct MxOps
105 {
106  enum MailboxType type;
107  const char *name;
108  bool is_local;
121  struct Account *(*ac_find) (struct Account *a, const char *path);
134  int (*ac_add) (struct Account *a, struct Mailbox *m);
146  int (*mbox_open) (struct Mailbox *m);
158  int (*mbox_open_append)(struct Mailbox *m, OpenMailboxFlags flags);
169  int (*mbox_check) (struct Mailbox *m);
182  int (*mbox_check_stats)(struct Mailbox *m, int flags);
193  int (*mbox_sync) (struct Mailbox *m);
204  int (*mbox_close) (struct Mailbox *m);
219  int (*msg_open) (struct Mailbox *m, struct Message *msg, int msgno);
233  int (*msg_open_new) (struct Mailbox *m, struct Message *msg, const struct Email *e);
246  int (*msg_commit) (struct Mailbox *m, struct Message *msg);
259  int (*msg_close) (struct Mailbox *m, struct Message *msg);
269  int (*msg_padding_size)(struct Mailbox *m);
282  int (*msg_save_hcache) (struct Mailbox *m, struct Email *e);
298  int (*tags_edit) (struct Mailbox *m, const char *tags, char *buf, size_t buflen);
313  int (*tags_commit) (struct Mailbox *m, struct Email *e, char *buf);
324  enum MailboxType (*path_probe)(const char *path, const struct stat *st);
336  int (*path_canon) (char *buf, size_t buflen);
349  int (*path_pretty) (char *buf, size_t buflen, const char *folder);
361  int (*path_parent) (char *buf, size_t buflen);
373  int (*path_is_empty) (const char *path);
374 };
376 /* Wrappers for the Mailbox API, see MxOps */
377 int mx_mbox_check (struct Mailbox *m);
378 int mx_mbox_check_stats(struct Mailbox *m, int flags);
379 int mx_mbox_close (struct Context **ptr);
380 struct Context *mx_mbox_open (struct Mailbox *m, OpenMailboxFlags flags);
381 int mx_mbox_sync (struct Mailbox *m);
382 int mx_msg_close (struct Mailbox *m, struct Message **msg);
383 int mx_msg_commit (struct Mailbox *m, struct Message *msg);
384 struct Message *mx_msg_open_new (struct Mailbox *m, const struct Email *e, MsgOpenFlags flags);
385 struct Message *mx_msg_open (struct Mailbox *m, int msgno);
386 int mx_msg_padding_size(struct Mailbox *m);
387 int mx_save_hcache (struct Mailbox *m, struct Email *e);
388 int mx_path_canon (char *buf, size_t buflen, const char *folder, enum MailboxType *type);
389 int mx_path_canon2 (struct Mailbox *m, const char *folder);
390 int mx_path_parent (char *buf, size_t buflen);
391 int mx_path_pretty (char *buf, size_t buflen, const char *folder);
392 enum MailboxType mx_path_probe (const char *path);
393 struct Mailbox *mx_path_resolve (const char *path);
394 struct Mailbox *mx_resolve (const char *path_or_name);
395 int mx_tags_commit (struct Mailbox *m, struct Email *e, char *tags);
396 int mx_tags_edit (struct Mailbox *m, const char *tags, char *buf, size_t buflen);
398 struct Account *mx_ac_find (struct Mailbox *m);
399 struct Mailbox *mx_mbox_find (struct Account *a, const char *path);
400 struct Mailbox *mx_mbox_find2 (const char *path);
401 bool mx_mbox_ac_link(struct Mailbox *m);
402 int mx_ac_add (struct Account *a, struct Mailbox *m);
403 int mx_ac_remove (struct Mailbox *m);
405 int mx_access (const char *path, int flags);
406 void mx_alloc_memory (struct Mailbox *m);
407 int mx_path_is_empty (const char *path);
408 void mx_fastclose_mailbox(struct Mailbox *m);
409 const struct MxOps *mx_get_ops (enum MailboxType type);
410 bool mx_tags_is_supported(struct Mailbox *m);
412 #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:1554
bool replied
Definition: mx.h:92
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1204
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:1750
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:1308
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 $spoolfile to $mbox when read.
Definition: mx.c:85
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:1381
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:1230
bool C_KeepFlagged
Config: Don&#39;t move flagged messages from $spoolfile to $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:1784
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:1819
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:1568
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:1681
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:1802
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:1592
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:1768
struct Mailbox * mx_mbox_find2(const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1654
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:1510
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:1538
char * committed_path
the final path generated by mx_msg_commit()
Definition: mx.h:86
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:1288
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:1183
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:1335
int mx_path_canon2(struct Mailbox *m, const char *folder)
Canonicalise the path to realpath.
Definition: mx.c:1482
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
int mx_path_is_empty(const char *path)
Is the mailbox empty.
Definition: mx.c:1265
The Mailbox API.
Definition: mx.h:104
bool mx_tags_is_supported(struct Mailbox *m)
return true if mailbox support tagging
Definition: mx.c:1325