NeoMutt  2025-12-11-800-ga0ee0f
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
msg_set.h File Reference

IMAP Message Sets. More...

#include "mutt/lib.h"
+ Include dependency graph for msg_set.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

 ARRAY_HEAD (UidArray, unsigned int)
 Set of Email UIDs to work on.
 
int imap_sort_uid (const void *a, const void *b, void *sdata)
 Compare two UIDs - Implements sort_t -.
 
int imap_make_msg_set (struct UidArray *uida, struct Buffer *buf, int *pos)
 Generate a compressed message set of UIDs.
 
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.
 

Detailed Description

IMAP Message Sets.

Authors
  • Richard Russon

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file msg_set.h.

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( UidArray ,
unsigned int  )

Set of Email UIDs to work on.

◆ imap_make_msg_set()

int imap_make_msg_set ( struct UidArray * uida,
struct Buffer * buf,
int * pos )

Generate a compressed message set of UIDs.

Parameters
uidaArray of UIDs
bufBuffer for message set
posCursor used for multiple calls to this function
Return values
numNumber of UIDs processed

Compress a sorted list of UIDs, e.g.

  • 1,2,3,4,6,8,9,10 becomes 1:4,6,8:10

Definition at line 66 of file msg_set.c.

67{
68 if (!uida || !buf || !pos)
69 return 0;
70
71 const int array_size = ARRAY_SIZE(uida);
72 if ((array_size == 0) || (*pos >= array_size))
73 return 0;
74
75 int count = 1; // Number of UIDs added to the set
76 int i = *pos;
77 unsigned int start = *ARRAY_GET(uida, i);
78 unsigned int prev = start;
79
81 for (i++; (i < array_size) && (buf_len(buf) < mod_data->imap_max_cmdlen); i++, count++)
82 {
83 unsigned int uid = *ARRAY_GET(uida, i);
84
85 // Keep adding to current set
86 if (uid == (prev + 1))
87 {
88 prev = uid;
89 continue;
90 }
91
92 // End the current set
93 if (start == prev)
94 buf_add_printf(buf, "%u,", start);
95 else
96 buf_add_printf(buf, "%u:%u,", start, prev);
97
98 // Start a new set
99 start = uid;
100 prev = uid;
101 }
102
103 if (start == prev)
104 buf_add_printf(buf, "%u", start);
105 else
106 buf_add_printf(buf, "%u:%u", start, prev);
107
108 *pos = i;
109
110 return count;
111}
#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
@ MODULE_ID_IMAP
ModuleImap, Imap Mailbox
Definition module_api.h:71
void * neomutt_get_module_data(struct NeoMutt *n, enum ModuleId id)
Get the private data for a Module.
Definition neomutt.c:663
Imap private Module data.
Definition module_data.h:30
int imap_max_cmdlen
Maximum length of IMAP commands before split.
Definition module_data.h:32
Container for Accounts, Notifications.
Definition neomutt.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_exec_msg_set()

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.

Parameters
adataImap Account data
prePrefix commands
postPostfix commands
uidaSorted array of UIDs
Return values
numNumber of messages sent
-1Error

Commands are of the form: TAG PRE MESSAGE-SET POST e.g. A01 UID COPY 1:4 MAILBOX

Note
Must be flushed with imap_exec()

Definition at line 127 of file msg_set.c.

129{
130 struct Buffer *cmd = buf_pool_get();
131
132 int count = 0;
133 int pos = 0;
134 int rc = 0;
135
136 do
137 {
138 buf_reset(cmd);
139 buf_add_printf(cmd, "%s ", pre);
140 rc = imap_make_msg_set(uida, cmd, &pos);
141 if (rc > 0)
142 {
143 buf_add_printf(cmd, " %s", post);
145 {
146 rc = -1;
147 goto out;
148 }
149 count += rc;
150 }
151 } while (rc > 0);
152
153 rc = count;
154
155out:
156 buf_pool_release(&cmd);
157 return rc;
158}
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
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:1415
@ 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 imap_make_msg_set(struct UidArray *uida, struct Buffer *buf, int *pos)
Generate a compressed message set of UIDs.
Definition msg_set.c:66
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition pool.c:91
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition pool.c:111
String manipulation buffer.
Definition buffer.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function: