NeoMutt  2022-04-29-249-gaae397
Teaching an old dog new tricks
DOXYGEN
msn.c
Go to the documentation of this file.
1
29#include "config.h"
30#include <limits.h>
31#include <stdlib.h>
32#include "mutt/lib.h"
33#include "msn.h"
34#include "mdata.h" // IWYU pragma: keep
35
41void imap_msn_reserve(struct MSN *msn, size_t num)
42{
43 /* This is a conservative check to protect against a malicious imap
44 * server. Most likely size_t is bigger than an unsigned int, but
45 * if msn_count is this big, we have a serious problem. */
46 if (num >= (UINT_MAX / sizeof(struct Email *)))
47 {
48 mutt_error(_("Out of memory"));
49 mutt_exit(1);
50 }
51
52 ARRAY_RESERVE(msn, num);
53}
54
59void imap_msn_free(struct MSN *msn)
60{
61 ARRAY_FREE(msn);
62}
63
69size_t imap_msn_highest(const struct MSN *msn)
70{
71 return ARRAY_SIZE(msn);
72}
73
80struct Email *imap_msn_get(const struct MSN *msn, size_t idx)
81{
82 struct Email **ep = ARRAY_GET(msn, idx);
83 return ep ? *ep : NULL;
84}
85
92void imap_msn_set(struct MSN *msn, size_t idx, struct Email *e)
93{
94 ARRAY_SET(msn, idx, e);
95}
96
103size_t imap_msn_shrink(struct MSN *msn, size_t num)
104{
105 return ARRAY_SHRINK(msn, num);
106}
107
113void imap_msn_remove(struct MSN *msn, size_t idx)
114{
115 struct Email **ep = ARRAY_GET(msn, idx);
116 if (ep)
117 *ep = NULL;
118}
#define ARRAY_SHRINK(head, num)
Mark a number of slots at the end of the array as unused.
Definition: array.h:171
#define ARRAY_SET(head, idx, elem)
Set an element in the array.
Definition: array.h:122
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:188
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:203
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:108
#define mutt_error(...)
Definition: logging.h:87
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:248
void imap_msn_set(struct MSN *msn, size_t idx, struct Email *e)
Cache an Email into a given position.
Definition: msn.c:92
void imap_msn_free(struct MSN *msn)
Free the cache.
Definition: msn.c:59
size_t imap_msn_shrink(struct MSN *msn, size_t num)
Remove a number of entries from the end of the cache.
Definition: msn.c:103
void imap_msn_reserve(struct MSN *msn, size_t num)
Create / reallocate the cache.
Definition: msn.c:41
void imap_msn_remove(struct MSN *msn, size_t idx)
Remove an entry from the cache.
Definition: msn.c:113
size_t imap_msn_highest(const struct MSN *msn)
Return the highest MSN in use.
Definition: msn.c:69
struct Email * imap_msn_get(const struct MSN *msn, size_t idx)
Return the Email associated with an msn.
Definition: msn.c:80
IMAP MSN helper functions.
Convenience wrapper for the library headers.
#define _(a)
Definition: message.h:28
Notmuch-specific Mailbox data.
The envelope/body of an email.
Definition: email.h:37