NeoMutt  2025-01-09-144-gb44c67
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
msg_set.c
Go to the documentation of this file.
1
37#include "config.h"
38#include "private.h"
39#include "mutt/lib.h"
40#include "config/lib.h"
41#include "msg_set.h"
42
49int ImapMaxCmdlen = 8192;
50
54int imap_sort_uid(const void *a, const void *b, void *sdata)
55{
56 unsigned int ua = *(unsigned int *) a;
57 unsigned int ub = *(unsigned int *) b;
58
59 return mutt_numeric_cmp(ua, ub);
60}
61
72int imap_make_msg_set(struct UidArray *uida, struct Buffer *buf, int *pos)
73{
74 if (!uida || !buf || !pos)
75 return 0;
76
77 const int array_size = ARRAY_SIZE(uida);
78 if ((array_size == 0) || (*pos >= array_size))
79 return 0;
80
81 int count = 1; // Number of UIDs added to the set
82 int i = *pos;
83 unsigned int start = *ARRAY_GET(uida, i);
84 unsigned int prev = start;
85
86 for (i++; (i < array_size) && (buf_len(buf) < ImapMaxCmdlen); i++, count++)
87 {
88 unsigned int uid = *ARRAY_GET(uida, i);
89
90 // Keep adding to current set
91 if (uid == (prev + 1))
92 {
93 prev = uid;
94 continue;
95 }
96
97 // End the current set
98 if (start == prev)
99 buf_add_printf(buf, "%u,", start);
100 else
101 buf_add_printf(buf, "%u:%u,", start, prev);
102
103 // Start a new set
104 start = uid;
105 prev = uid;
106 }
107
108 if (start == prev)
109 buf_add_printf(buf, "%u", start);
110 else
111 buf_add_printf(buf, "%u:%u", start, prev);
112
113 *pos = i;
114
115 return count;
116}
117
132int imap_exec_msg_set(struct ImapAccountData *adata, const char *pre,
133 const char *post, struct UidArray *uida)
134{
135 struct Buffer *cmd = buf_pool_get();
136
137 int count = 0;
138 int pos = 0;
139 int rc = 0;
140
141 do
142 {
143 buf_reset(cmd);
144 buf_add_printf(cmd, "%s ", pre);
145 rc = imap_make_msg_set(uida, cmd, &pos);
146 if (rc > 0)
147 {
148 buf_add_printf(cmd, " %s", post);
150 {
151 rc = -1;
152 goto out;
153 }
154 count += rc;
155 }
156 } while (rc > 0);
157
158 rc = count;
159
160out:
161 buf_pool_release(&cmd);
162 return rc;
163}
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:87
#define ARRAY_GET(head, idx)
Return the element at index.
Definition: array.h:109
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:204
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:491
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:76
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:96
Convenience wrapper for the config headers.
#define mutt_numeric_cmp(a, b)
Definition: sort.h:26
int imap_sort_uid(const void *a, const void *b, void *sdata)
Compare two UIDs - Implements sort_t -.
Definition: msg_set.c:54
int imap_exec(struct ImapAccountData *adata, const char *cmdstr, ImapCmdFlags flags)
Execute a command and wait for the response from the server.
Definition: command.c:1303
@ IMAP_EXEC_SUCCESS
Imap command executed or queued successfully.
Definition: private.h:82
#define IMAP_CMD_QUEUE
Queue a command, do not execute.
Definition: private.h:73
int ImapMaxCmdlen
Maximum length of IMAP commands before they must be split.
Definition: msg_set.c:49
int imap_make_msg_set(struct UidArray *uida, struct Buffer *buf, int *pos)
Generate a compressed message set of UIDs.
Definition: msg_set.c:72
int imap_exec_msg_set(struct ImapAccountData *adata, const char *pre, const char *post, struct UidArray *uida)
Execute a command using a set of UIDs.
Definition: msg_set.c:132
IMAP Message Sets.
Convenience wrapper for the library headers.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:82
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:96
GUI display the mailboxes in a side panel.
String manipulation buffer.
Definition: buffer.h:36
IMAP-specific Account data -.
Definition: adata.h:40