NeoMutt  2024-03-23-23-gec7045
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
msn.c
Go to the documentation of this file.
1
30#include "config.h"
31#include <limits.h>
32#include <stdlib.h>
33#include "mutt/lib.h"
34#include "msn.h"
35#include "mdata.h" // IWYU pragma: keep
36
42void imap_msn_reserve(struct MSNArray *msn, size_t num)
43{
44 /* This is a conservative check to protect against a malicious imap
45 * server. Most likely size_t is bigger than an unsigned int, but
46 * if msn_count is this big, we have a serious problem. */
47 if (num >= (UINT_MAX / sizeof(struct Email *)))
48 {
49 mutt_error(_("Out of memory"));
50 mutt_exit(1);
51 }
52
53 ARRAY_RESERVE(msn, num);
54}
55
60void imap_msn_free(struct MSNArray *msn)
61{
62 ARRAY_FREE(msn);
63}
64
70size_t imap_msn_highest(const struct MSNArray *msn)
71{
72 return ARRAY_SIZE(msn);
73}
74
81struct Email *imap_msn_get(const struct MSNArray *msn, size_t idx)
82{
83 struct Email **ep = ARRAY_GET(msn, idx);
84 return ep ? *ep : NULL;
85}
86
93void imap_msn_set(struct MSNArray *msn, size_t idx, struct Email *e)
94{
95 ARRAY_SET(msn, idx, e);
96}
97
104size_t imap_msn_shrink(struct MSNArray *msn, size_t num)
105{
106 return ARRAY_SHRINK(msn, num);
107}
108
114void imap_msn_remove(struct MSNArray *msn, size_t idx)
115{
116 struct Email **ep = ARRAY_GET(msn, idx);
117 if (ep)
118 *ep = NULL;
119}
#define ARRAY_SHRINK(head, num)
Mark a number of slots at the end of the array as unused.
Definition: array.h:172
#define ARRAY_SET(head, idx, elem)
Set an element in the array.
Definition: array.h:123
#define ARRAY_RESERVE(head, num)
Reserve memory for the array.
Definition: array.h:189
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_FREE(head)
Release all memory.
Definition: array.h:204
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
#define mutt_error(...)
Definition: logging2.h:92
void mutt_exit(int code)
Leave NeoMutt NOW.
Definition: main.c:231
size_t imap_msn_shrink(struct MSNArray *msn, size_t num)
Remove a number of entries from the end of the cache.
Definition: msn.c:104
void imap_msn_free(struct MSNArray *msn)
Free the cache.
Definition: msn.c:60
size_t imap_msn_highest(const struct MSNArray *msn)
Return the highest MSN in use.
Definition: msn.c:70
struct Email * imap_msn_get(const struct MSNArray *msn, size_t idx)
Return the Email associated with an msn.
Definition: msn.c:81
void imap_msn_set(struct MSNArray *msn, size_t idx, struct Email *e)
Cache an Email into a given position.
Definition: msn.c:93
void imap_msn_reserve(struct MSNArray *msn, size_t num)
Create / reallocate the cache.
Definition: msn.c:42
void imap_msn_remove(struct MSNArray *msn, size_t idx)
Remove an entry from the cache.
Definition: msn.c:114
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:39