NeoMutt  2024-10-02-37-gfa9146
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 <errno.h>
32#include <limits.h>
33#include <stdlib.h>
34#include <string.h>
35#include "mutt/lib.h"
36#include "msn.h"
37#include "mdata.h" // IWYU pragma: keep
38
44void imap_msn_reserve(struct MSNArray *msn, size_t num)
45{
46 /* This is a conservative check to protect against a malicious imap
47 * server. Most likely size_t is bigger than an unsigned int, but
48 * if msn_count is this big, we have a serious problem. */
49 if (num >= (UINT_MAX / sizeof(struct Email *)))
50 {
51 mutt_error("%s", strerror(ENOMEM));
52 mutt_exit(1);
53 }
54
55 ARRAY_RESERVE(msn, num);
56}
57
62void imap_msn_free(struct MSNArray *msn)
63{
64 ARRAY_FREE(msn);
65}
66
72size_t imap_msn_highest(const struct MSNArray *msn)
73{
74 return ARRAY_SIZE(msn);
75}
76
83struct Email *imap_msn_get(const struct MSNArray *msn, size_t idx)
84{
85 struct Email **ep = ARRAY_GET(msn, idx);
86 return ep ? *ep : NULL;
87}
88
95void imap_msn_set(struct MSNArray *msn, size_t idx, struct Email *e)
96{
97 ARRAY_SET(msn, idx, e);
98}
99
106size_t imap_msn_shrink(struct MSNArray *msn, size_t num)
107{
108 return ARRAY_SHRINK(msn, num);
109}
110
116void imap_msn_remove(struct MSNArray *msn, size_t idx)
117{
118 struct Email **ep = ARRAY_GET(msn, idx);
119 if (ep)
120 *ep = NULL;
121}
#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:269
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:106
void imap_msn_free(struct MSNArray *msn)
Free the cache.
Definition: msn.c:62
size_t imap_msn_highest(const struct MSNArray *msn)
Return the highest MSN in use.
Definition: msn.c:72
struct Email * imap_msn_get(const struct MSNArray *msn, size_t idx)
Return the Email associated with an msn.
Definition: msn.c:83
void imap_msn_set(struct MSNArray *msn, size_t idx, struct Email *e)
Cache an Email into a given position.
Definition: msn.c:95
void imap_msn_reserve(struct MSNArray *msn, size_t num)
Create / reallocate the cache.
Definition: msn.c:44
void imap_msn_remove(struct MSNArray *msn, size_t idx)
Remove an entry from the cache.
Definition: msn.c:116
IMAP MSN helper functions.
Convenience wrapper for the library headers.
Notmuch-specific Mailbox data.
The envelope/body of an email.
Definition: email.h:39