NeoMutt  2021-02-05-89-gabe350
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 {
79 };
80 
85 {
89 };
90 
94 struct Message
95 {
96  FILE *fp;
97  char *path;
99  bool write;
100  struct
101  {
102  bool read : 1;
103  bool flagged : 1;
104  bool replied : 1;
105  bool draft : 1;
106  } flags;
107  time_t received;
108 };
109 
116 struct MxOps
117 {
119  const char *name;
120  bool is_local;
121 
133  bool (*ac_owns_path)(struct Account *a, const char *path);
134 
146  bool (*ac_add)(struct Account *a, struct Mailbox *m);
147 
156  enum MxOpenReturns (*mbox_open)(struct Mailbox *m);
157 
169 
178  enum MxStatus (*mbox_check)(struct Mailbox *m);
179 
189  enum MxStatus (*mbox_check_stats)(struct Mailbox *m, uint8_t flags);
190 
199  enum MxStatus (*mbox_sync)(struct Mailbox *m);
200 
209  enum MxStatus (*mbox_close)(struct Mailbox *m);
210 
224  bool (*msg_open)(struct Mailbox *m, struct Message *msg, int msgno);
225 
238  bool (*msg_open_new)(struct Mailbox *m, struct Message *msg, const struct Email *e);
239 
251  int (*msg_commit) (struct Mailbox *m, struct Message *msg);
252 
264  int (*msg_close) (struct Mailbox *m, struct Message *msg);
265 
274  int (*msg_padding_size)(struct Mailbox *m);
275 
287  int (*msg_save_hcache) (struct Mailbox *m, struct Email *e);
288 
303  int (*tags_edit) (struct Mailbox *m, const char *tags, char *buf, size_t buflen);
304 
318  int (*tags_commit) (struct Mailbox *m, struct Email *e, char *buf);
319 
329  enum MailboxType (*path_probe)(const char *path, const struct stat *st);
330 
341  int (*path_canon) (char *buf, size_t buflen);
342 
354  int (*path_pretty) (char *buf, size_t buflen, const char *folder);
355 
366  int (*path_parent) (char *buf, size_t buflen);
367 
378  int (*path_is_empty) (const char *path);
379 };
380 
381 /* Wrappers for the Mailbox API, see MxOps */
382 enum MxStatus mx_mbox_check (struct Mailbox *m);
383 enum MxStatus mx_mbox_check_stats(struct Mailbox *m, uint8_t flags);
384 enum MxStatus mx_mbox_close (struct Context **ptr);
385 struct Context *mx_mbox_open (struct Mailbox *m, OpenMailboxFlags flags);
386 enum MxStatus mx_mbox_sync (struct Mailbox *m);
387 int mx_msg_close (struct Mailbox *m, struct Message **msg);
388 int mx_msg_commit (struct Mailbox *m, struct Message *msg);
389 struct Message *mx_msg_open_new (struct Mailbox *m, const struct Email *e, MsgOpenFlags flags);
390 struct Message *mx_msg_open (struct Mailbox *m, int msgno);
391 int mx_msg_padding_size(struct Mailbox *m);
392 int mx_save_hcache (struct Mailbox *m, struct Email *e);
393 int mx_path_canon (char *buf, size_t buflen, const char *folder, enum MailboxType *type);
394 int mx_path_canon2 (struct Mailbox *m, const char *folder);
395 int mx_path_parent (char *buf, size_t buflen);
396 int mx_path_pretty (char *buf, size_t buflen, const char *folder);
397 enum MailboxType mx_path_probe (const char *path);
398 struct Mailbox *mx_path_resolve (const char *path);
399 struct Mailbox *mx_resolve (const char *path_or_name);
400 int mx_tags_commit (struct Mailbox *m, struct Email *e, char *tags);
401 int mx_tags_edit (struct Mailbox *m, const char *tags, char *buf, size_t buflen);
402 
403 struct Account *mx_ac_find (struct Mailbox *m);
404 struct Mailbox *mx_mbox_find (struct Account *a, const char *path);
405 struct Mailbox *mx_mbox_find2 (const char *path);
406 bool mx_mbox_ac_link(struct Mailbox *m);
407 bool mx_ac_add (struct Account *a, struct Mailbox *m);
408 int mx_ac_remove (struct Mailbox *m);
409 
410 int mx_access (const char *path, int flags);
411 void mx_alloc_memory (struct Mailbox *m);
412 int mx_path_is_empty (const char *path);
413 void mx_fastclose_mailbox(struct Mailbox *m);
414 const struct MxOps *mx_get_ops (enum MailboxType type);
415 bool mx_tags_is_supported(struct Mailbox *m);
416 
417 #endif /* MUTT_MX_H */
MX_STATUS_LOCKED
@ MX_STATUS_LOCKED
Couldn't lock the Mailbox.
Definition: mx.h:76
MxOps::msg_padding_size
int(* msg_padding_size)(struct Mailbox *m)
Bytes of padding between messages.
Definition: mx.h:274
Message::flags
struct Message::@1 flags
mx_mbox_close
enum MxStatus mx_mbox_close(struct Context **ptr)
Save changes and close mailbox.
Definition: mx.c:632
MxOps::mbox_check_stats
enum MxStatus(* mbox_check_stats)(struct Mailbox *m, uint8_t flags)
Check the Mailbox statistics.
Definition: mx.h:189
MxStatus
MxStatus
Return values from mx_mbox_check(), mx_mbox_sync(), and mx_mbox_close()
Definition: mx.h:71
MxOps::tags_edit
int(* tags_edit)(struct Mailbox *m, const char *tags, char *buf, size_t buflen)
Prompt and validate new messages tags.
Definition: mx.h:303
mx_fastclose_mailbox
void mx_fastclose_mailbox(struct Mailbox *m)
free up memory associated with the Mailbox
Definition: mx.c:451
MxOps::name
const char * name
Mailbox name, e.g. "imap".
Definition: mx.h:119
MxOps::type
enum MailboxType type
Mailbox type, e.g. MUTT_IMAP.
Definition: mx.h:118
mx_tags_commit
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
Mailbox
A mailbox.
Definition: mailbox.h:81
mx_path_resolve
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
Definition: mx.c:1681
MxOps::mbox_sync
enum MxStatus(* mbox_sync)(struct Mailbox *m)
Save changes to the Mailbox.
Definition: mx.h:199
MxOps::msg_open_new
bool(* msg_open_new)(struct Mailbox *m, struct Message *msg, const struct Email *e)
Open a new message in a Mailbox.
Definition: mx.h:238
mx_msg_padding_size
int mx_msg_padding_size(struct Mailbox *m)
Bytes of padding between messages - Wrapper for MxOps::msg_padding_size()
Definition: mx.c:1554
mx_tags_is_supported
bool mx_tags_is_supported(struct Mailbox *m)
return true if mailbox support tagging
Definition: mx.c:1325
MxOps::msg_save_hcache
int(* msg_save_hcache)(struct Mailbox *m, struct Email *e)
Save message to the header cache.
Definition: mx.h:287
mx_mbox_open
struct Context * mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
Definition: mx.c:309
MxOpenReturns
MxOpenReturns
Return values for mbox_open()
Definition: mx.h:84
MxOps::msg_close
int(* msg_close)(struct Mailbox *m, struct Message *msg)
Close an email.
Definition: mx.h:264
MxOps
The Mailbox API.
Definition: mx.h:116
mx_path_canon2
int mx_path_canon2(struct Mailbox *m, const char *folder)
Canonicalise the path to realpath.
Definition: mx.c:1482
mx_msg_open
struct Message * mx_msg_open(struct Mailbox *m, int msgno)
return a stream pointer for a message
Definition: mx.c:1158
Context
The "current" mailbox.
Definition: context.h:38
Message::received
time_t received
the time at which this message was received
Definition: mx.h:107
Mailbox::flags
uint8_t flags
e.g. MB_NORMAL
Definition: mailbox.h:134
MX_OPEN_OK
@ MX_OPEN_OK
Open succeeded.
Definition: mx.h:86
MxOps::ac_add
bool(* ac_add)(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account.
Definition: mx.h:146
Email::path
char * path
Path of Email (for local Mailboxes)
Definition: email.h:92
mx_msg_open_new
struct Message * mx_msg_open_new(struct Mailbox *m, const struct Email *e, MsgOpenFlags flags)
Open a new message.
Definition: mx.c:1072
C_Move
unsigned char C_Move
Config: Move emails from $spool_file to $mbox when read.
Definition: mx.c:91
mx_mbox_ac_link
bool mx_mbox_ac_link(struct Mailbox *m)
Link a Mailbox to an existing or new Account.
Definition: mx.c:272
MxOps::path_pretty
int(* path_pretty)(char *buf, size_t buflen, const char *folder)
Abbreviate a Mailbox path.
Definition: mx.h:354
MX_STATUS_REOPENED
@ MX_STATUS_REOPENED
Mailbox was reopened.
Definition: mx.h:77
mx_ac_remove
int mx_ac_remove(struct Mailbox *m)
Remove a Mailbox from an Account and delete Account if empty.
Definition: mx.c:1780
MX_STATUS_NEW_MAIL
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
Definition: mx.h:75
lib.h
mx_mbox_find2
struct Mailbox * mx_mbox_find2(const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1654
Message::committed_path
char * committed_path
the final path generated by mx_msg_commit()
Definition: mx.h:98
MxOps::mbox_open_append
bool(* mbox_open_append)(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending.
Definition: mx.h:168
MxOps::mbox_close
enum MxStatus(* mbox_close)(struct Mailbox *m)
Close a Mailbox.
Definition: mx.h:209
mx_mbox_check
enum MxStatus mx_mbox_check(struct Mailbox *m)
Check for new mail - Wrapper for MxOps::mbox_check()
Definition: mx.c:1137
mx_ac_find
struct Account * mx_ac_find(struct Mailbox *m)
Find the Account owning a Mailbox.
Definition: mx.c:1568
Account
A group of associated Mailboxes.
Definition: account.h:36
Message::write
bool write
nonzero if message is open for writing
Definition: mx.h:99
MxOps::msg_commit
int(* msg_commit)(struct Mailbox *m, struct Message *msg)
Save changes to an email.
Definition: mx.h:251
Message::path
char * path
path to temp file
Definition: mx.h:97
mx_path_canon
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
MxOps::is_local
bool is_local
True, if Mailbox type has local files/dirs.
Definition: mx.h:120
Message::draft
bool draft
Definition: mx.h:105
lib.h
Message::read
bool read
Definition: mx.h:102
MxOps::msg_open
bool(* msg_open)(struct Mailbox *m, struct Message *msg, int msgno)
Open an email message in a Mailbox.
Definition: mx.h:224
MxOps::path_probe
enum MailboxType(* path_probe)(const char *path, const struct stat *st)
Does this Mailbox type recognise this path?
Definition: mx.h:329
C_MboxType
unsigned char C_MboxType
Config: Default type for creating new mailboxes.
Definition: mx.c:90
mx_path_probe
enum MailboxType mx_path_probe(const char *path)
Find a mailbox that understands a path.
Definition: mx.c:1335
mx_mbox_check_stats
enum MxStatus mx_mbox_check_stats(struct Mailbox *m, uint8_t flags)
Check the statistics for a mailbox - Wrapper for MxOps::mbox_check_stats()
Definition: mx.c:1798
mx_path_pretty
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
MxOps::tags_commit
int(* tags_commit)(struct Mailbox *m, struct Email *e, char *buf)
Save the tags to a message.
Definition: mx.h:318
mx_ac_add
bool mx_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Wrapper for MxOps::ac_add()
Definition: mx.c:1768
Message::replied
bool replied
Definition: mx.h:104
mx_resolve
struct Mailbox * mx_resolve(const char *path_or_name)
Get a Mailbox from either a path or name.
Definition: mx.c:1750
Message::fp
FILE * fp
pointer to the message data
Definition: mx.h:96
MX_STATUS_ERROR
@ MX_STATUS_ERROR
An error occurred.
Definition: mx.h:73
mx_save_hcache
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:1815
mx_alloc_memory
void mx_alloc_memory(struct Mailbox *m)
Create storage for the emails.
Definition: mx.c:1230
mx_msg_close
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
Definition: mx.c:1204
Message::flagged
bool flagged
Definition: mx.h:103
mx_access
int mx_access(const char *path, int flags)
Wrapper for access, checks permissions on a given mailbox.
Definition: mx.c:189
mx_mbox_find
struct Mailbox * mx_mbox_find(struct Account *a, const char *path)
Find a Mailbox on an Account.
Definition: mx.c:1592
OpenMailboxFlags
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
Definition: mx.h:50
MsgOpenFlags
uint8_t MsgOpenFlags
Flags for mx_msg_open_new(), e.g. MUTT_ADD_FROM.
Definition: mx.h:63
mx_ops
const struct MxOps * mx_ops[]
All the Mailbox backends.
Definition: mx.c:113
MxOps::path_canon
int(* path_canon)(char *buf, size_t buflen)
Canonicalise a Mailbox path.
Definition: mx.h:341
C_Trash
char * C_Trash
Config: Folder to put deleted emails.
Definition: mx.c:92
mx_mbox_sync
enum MxStatus mx_mbox_sync(struct Mailbox *m)
Save changes to mailbox.
Definition: mx.c:937
MX_OPEN_ABORT
@ MX_OPEN_ABORT
Open was aborted.
Definition: mx.h:88
MailboxType
MailboxType
Supported mailbox formats.
Definition: mailbox.h:43
MxOps::ac_owns_path
bool(* ac_owns_path)(struct Account *a, const char *path)
Check whether an Account owns a Mailbox path.
Definition: mx.h:133
mx_path_is_empty
int mx_path_is_empty(const char *path)
Is the mailbox empty.
Definition: mx.c:1265
MxOps::path_is_empty
int(* path_is_empty)(const char *path)
Is the Mailbox empty?
Definition: mx.h:378
MX_STATUS_FLAGS
@ MX_STATUS_FLAGS
Nondestructive flags change (IMAP)
Definition: mx.h:78
mx_msg_commit
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
EnumDef
An enumeration.
Definition: enum.h:31
mx_path_parent
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
mx_tags_edit
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
Email
The envelope/body of an email.
Definition: email.h:37
mx_get_ops
const struct MxOps * mx_get_ops(enum MailboxType type)
Get mailbox operations.
Definition: mx.c:147
MX_OPEN_ERROR
@ MX_OPEN_ERROR
Open failed with an error.
Definition: mx.h:87
MxOps::mbox_open
enum MxOpenReturns(* mbox_open)(struct Mailbox *m)
Open a Mailbox.
Definition: mx.h:156
C_KeepFlagged
bool C_KeepFlagged
Config: Don't move flagged messages from $spool_file to $mbox
Definition: mx.c:89
Message
A local copy of an email.
Definition: mx.h:94
MxOps::mbox_check
enum MxStatus(* mbox_check)(struct Mailbox *m)
Check for new mail.
Definition: mx.h:178
MxOps::path_parent
int(* path_parent)(char *buf, size_t buflen)
Find the parent of a Mailbox path.
Definition: mx.h:366
MX_STATUS_OK
@ MX_STATUS_OK
No changes.
Definition: mx.h:74
MboxTypeDef
struct EnumDef MboxTypeDef
Definition: mx.c:104