NeoMutt  2025-12-11-911-gd8d604
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
util.c File Reference

IMAP helper functions. More...

#include "config.h"
#include <arpa/inet.h>
#include <errno.h>
#include <netdb.h>
#include <signal.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <unistd.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "conn/lib.h"
#include "lib.h"
#include "bcache/lib.h"
#include "question/lib.h"
#include "store/lib.h"
#include "adata.h"
#include "edata.h"
#include "globals.h"
#include "mdata.h"
#include "msn.h"
#include "hcache/lib.h"
+ Include dependency graph for util.c:

Go to the source code of this file.

Functions

int imap_adata_find (const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
 Find the Account data for this path.
 
void imap_mdata_cache_reset (struct ImapMboxData *mdata)
 Release and clear cache data of ImapMboxData structure.
 
void imap_get_parent (const char *mbox, char delim, char *buf, size_t buflen)
 Get an IMAP folder's parent.
 
void imap_get_parent_path (const char *path, char *buf, size_t buflen)
 Get the path of the parent folder.
 
void imap_clean_path (char *path, size_t plen)
 Cleans an IMAP path using imap_fix_path.
 
static const char * imap_get_field (enum ConnAccountField field, void *gf_data)
 Get connection login credentials - Implements ConnAccount::get_field() -.
 
static void imap_msn_index_to_uid_seqset (struct Buffer *buf, struct ImapMboxData *mdata)
 Convert MSN index of UIDs to Seqset.
 
static void imap_hcache_namer (const struct StoreOps *store_ops, const char *path, struct Buffer *dest)
 Generate a filename for the header cache - Implements hcache_namer_t -.
 
void imap_hcache_open (struct ImapAccountData *adata, struct ImapMboxData *mdata, bool create)
 Open a header cache.
 
void imap_hcache_close (struct ImapMboxData *mdata)
 Close the header cache.
 
struct Emailimap_hcache_get (struct ImapMboxData *mdata, unsigned int uid)
 Get a header cache entry by its UID.
 
int imap_hcache_put (struct ImapMboxData *mdata, struct Email *e)
 Add an entry to the header cache.
 
int imap_hcache_del (struct ImapMboxData *mdata, unsigned int uid)
 Delete an item from the header cache.
 
int imap_hcache_store_uid_seqset (struct ImapMboxData *mdata)
 Store a UID Sequence Set in the header cache.
 
int imap_hcache_clear_uid_seqset (struct ImapMboxData *mdata)
 Delete a UID Sequence Set from the header cache.
 
char * imap_hcache_get_uid_seqset (struct ImapMboxData *mdata)
 Get a UID Sequence Set from the header cache.
 
int imap_parse_path (const char *path, struct ConnAccount *cac, char *mailbox, size_t mailboxlen)
 Parse an IMAP mailbox name into ConnAccount, name.
 
int imap_mxcmp (const char *mx1, const char *mx2)
 Compare mailbox names, giving priority to INBOX.
 
void imap_pretty_mailbox (char *path, size_t pathlen, const char *folder)
 Prettify an IMAP mailbox name.
 
enum QuadOption imap_continue (const char *msg, const char *resp)
 Display a message and ask the user if they want to go on.
 
void imap_error (const char *where, const char *msg)
 Show an error and abort.
 
char * imap_fix_path (const char *mailbox, char *path, size_t plen)
 Fix up the imap path.
 
char * imap_fix_path_with_delim (const char delim, const char *mailbox, char *path, size_t plen)
 Fix up the imap path.
 
void imap_cachepath (char delim, const char *mailbox, struct Buffer *dest)
 Generate a cache path for a mailbox.
 
int imap_get_literal_count (char *buf, unsigned int *bytes)
 Write number of bytes in an IMAP literal into bytes.
 
char * imap_get_qualifier (char *buf)
 Get the qualifier from a tagged response.
 
char * imap_next_word (char *s)
 Find where the next IMAP word begins.
 
void imap_qualify_path (char *buf, size_t buflen, struct ConnAccount *cac, char *path)
 Make an absolute IMAP folder target.
 
void imap_buf_qualify_path (struct Buffer *buf, struct ConnAccount *cac, char *path)
 Make an absolute IMAP folder target to a buffer.
 
void imap_quote_string (char *dest, size_t dlen, const char *src, bool quote_backtick)
 Quote string according to IMAP rules.
 
void imap_unquote_string (char *s)
 Equally stupid unquoting routine.
 
void imap_munge_mbox_name (bool unicode, char *dest, size_t dlen, const char *src)
 Quote awkward characters in a mailbox name.
 
void imap_unmunge_mbox_name (bool unicode, char *s)
 Remove quoting from a mailbox name.
 
void imap_keep_alive (void)
 Poll the current folder to keep the connection alive.
 
int imap_wait_keep_alive (pid_t pid)
 Wait for a process to change state.
 
void imap_allow_reopen (struct Mailbox *m)
 Allow re-opening a folder upon expunge.
 
void imap_disallow_reopen (struct Mailbox *m)
 Disallow re-opening a folder upon expunge.
 
bool imap_account_match (const struct ConnAccount *a1, const struct ConnAccount *a2)
 Compare two Accounts.
 
struct SeqsetIteratormutt_seqset_iterator_new (const char *seqset)
 Create a new Sequence Set Iterator.
 
int mutt_seqset_iterator_next (struct SeqsetIterator *iter, unsigned int *next)
 Get the next UID from a Sequence Set.
 
void mutt_seqset_iterator_free (struct SeqsetIterator **ptr)
 Free a Sequence Set Iterator.
 

Detailed Description

IMAP helper functions.

Authors
  • Michael R. Elkins
  • Brandon Long
  • Brendan Cully
  • Richard Russon
  • Mehdi Abaakouk
  • Pietro Cerutti
  • Thomas Klausner

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 util.c.

Function Documentation

◆ imap_adata_find()

int imap_adata_find ( const char * path,
struct ImapAccountData ** adata,
struct ImapMboxData ** mdata )

Find the Account data for this path.

Parameters
pathPath to search for
adataImap Account data
mdataImap Mailbox data
Return values
0Success
-1Failure

Definition at line 73 of file util.c.

75{
76 struct ConnAccount cac = { { 0 } };
77 struct ImapAccountData *tmp_adata = NULL;
78 char tmp[1024] = { 0 };
79
80 if (imap_parse_path(path, &cac, tmp, sizeof(tmp)) < 0)
81 return -1;
82
83 struct Account **ap = NULL;
85 {
86 struct Account *a = *ap;
87 if (a->type != MUTT_IMAP)
88 continue;
89
90 tmp_adata = a->adata;
91 if (!tmp_adata)
92 continue;
93 if (imap_account_match(&tmp_adata->conn->account, &cac))
94 {
95 if (mdata)
96 {
97 *mdata = imap_mdata_new(tmp_adata, tmp);
98 }
99 *adata = tmp_adata;
100 return 0;
101 }
102 }
103 mutt_debug(LL_DEBUG3, "no ImapAccountData found\n");
104 return -1;
105}
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
Definition array.h:223
@ MUTT_IMAP
'IMAP' Mailbox type
Definition mailbox.h:49
#define mutt_debug(LEVEL,...)
Definition logging2.h:91
struct ImapMboxData * imap_mdata_new(struct ImapAccountData *adata, const char *name)
Allocate and initialise a new ImapMboxData structure.
Definition mdata.c:74
@ LL_DEBUG3
Log at debug level 3.
Definition logging2.h:47
A group of associated Mailboxes.
Definition account.h:36
enum MailboxType type
Type of Mailboxes this Account contains.
Definition account.h:37
void * adata
Private data (for Mailbox backends)
Definition account.h:42
Login details for a remote server.
Definition connaccount.h:59
struct ConnAccount account
Account details: username, password, etc.
Definition connection.h:49
IMAP-specific Account data -.
Definition adata.h:40
struct Connection * conn
Connection to IMAP server.
Definition adata.h:41
Container for Accounts, Notifications.
Definition neomutt.h:41
struct AccountArray accounts
All Accounts.
Definition neomutt.h:50
int imap_parse_path(const char *path, struct ConnAccount *cac, char *mailbox, size_t mailboxlen)
Parse an IMAP mailbox name into ConnAccount, name.
Definition util.c:482
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
Definition util.c:1106
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_mdata_cache_reset()

void imap_mdata_cache_reset ( struct ImapMboxData * mdata)

Release and clear cache data of ImapMboxData structure.

Parameters
mdataImap Mailbox data

Definition at line 111 of file util.c.

112{
114 mdata->reopen = IMAP_OPEN_NONE;
115 mutt_hash_free(&mdata->uid_hash);
116 imap_msn_free(&mdata->msn);
117 mutt_bcache_close(&mdata->bcache);
118}
void mutt_bcache_close(struct BodyCache **ptr)
Close an Email-Body Cache.
Definition bcache.c:167
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition hash.c:459
@ IMAP_OPEN_NONE
No flags are set.
Definition private.h:67
void imap_msn_free(struct MSNArray *msn)
Free the cache.
Definition msn.c:62
ImapOpenFlags reopen
Flags, e.g. IMAP_REOPEN_ALLOW.
Definition mdata.h:45
struct BodyCache * bcache
Email body cache.
Definition mdata.h:62
struct HashTable * uid_hash
Hash Table: "uid" -> Email.
Definition mdata.h:60
ImapOpenFlags check_status
Flags, e.g. IMAP_NEWMAIL_PENDING.
Definition mdata.h:46
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_get_parent()

void imap_get_parent ( const char * mbox,
char delim,
char * buf,
size_t buflen )

Get an IMAP folder's parent.

Parameters
mboxMailbox whose parent is to be determined
delimPath delimiter
bufBuffer for the result
buflenLength of the buffer

Definition at line 127 of file util.c.

128{
129 /* Make a copy of the mailbox name, but only if the pointers are different */
130 if (mbox != buf)
131 mutt_str_copy(buf, mbox, buflen);
132
133 int n = mutt_str_len(buf);
134
135 /* Let's go backwards until the next delimiter
136 *
137 * If buf[n] is a '/', the first n-- will allow us
138 * to ignore it. If it isn't, then buf looks like
139 * "/aaaaa/bbbb". There is at least one "b", so we can't skip
140 * the "/" after the 'a's.
141 *
142 * If buf == '/', then n-- => n == 0, so the loop ends
143 * immediately */
144 for (n--; (n >= 0) && (buf[n] != delim); n--)
145 ; // do nothing
146
147 /* We stopped before the beginning. There is a trailing slash. */
148 if (n > 0)
149 {
150 /* Strip the trailing delimiter. */
151 buf[n] = '\0';
152 }
153 else
154 {
155 buf[0] = (n == 0) ? delim : '\0';
156 }
157}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition string.c:503
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
Definition string.c:586
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_get_parent_path()

void imap_get_parent_path ( const char * path,
char * buf,
size_t buflen )

Get the path of the parent folder.

Parameters
pathMailbox whose parent is to be determined
bufBuffer for the result
buflenLength of the buffer

Provided an imap path, returns in buf the parent directory if existent. Else returns the same path.

Definition at line 168 of file util.c.

169{
170 struct ImapAccountData *adata = NULL;
171 struct ImapMboxData *mdata = NULL;
172 char mbox[1024] = { 0 };
173
174 if (imap_adata_find(path, &adata, &mdata) < 0)
175 {
176 mutt_str_copy(buf, path, buflen);
177 return;
178 }
179
180 /* Gets the parent mbox in mbox */
181 imap_get_parent(mdata->name, adata->delim, mbox, sizeof(mbox));
182
183 /* Returns a fully qualified IMAP url */
184 imap_qualify_path(buf, buflen, &adata->conn->account, mbox);
185 imap_mdata_free((void *) &mdata);
186}
void imap_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free() -.
Definition mdata.c:40
char delim
Path delimiter.
Definition adata.h:79
IMAP-specific Mailbox data -.
Definition mdata.h:40
void * mdata
Driver specific data.
Definition mailbox.h:134
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *cac, char *path)
Make an absolute IMAP folder target.
Definition util.c:860
void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen)
Get an IMAP folder's parent.
Definition util.c:127
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition util.c:73
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_clean_path()

void imap_clean_path ( char * path,
size_t plen )

Cleans an IMAP path using imap_fix_path.

Parameters
pathPath to be cleaned
plenLength of the buffer

Does it in place.

Definition at line 195 of file util.c.

196{
197 struct ImapAccountData *adata = NULL;
198 struct ImapMboxData *mdata = NULL;
199
200 if (imap_adata_find(path, &adata, &mdata) < 0)
201 return;
202
203 /* Returns a fully qualified IMAP url */
204 imap_qualify_path(path, plen, &adata->conn->account, mdata->name);
205 imap_mdata_free((void *) &mdata);
206}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_msn_index_to_uid_seqset()

static void imap_msn_index_to_uid_seqset ( struct Buffer * buf,
struct ImapMboxData * mdata )
static

Convert MSN index of UIDs to Seqset.

Parameters
bufBuffer for the result
mdataImap Mailbox data

Generates a seqseq of the UIDs in msn_index to persist in the header cache. Empty spots are stored as 0.

Definition at line 238 of file util.c.

239{
240 int first = 1, state = 0;
241 unsigned int cur_uid = 0, last_uid = 0;
242 unsigned int range_begin = 0, range_end = 0;
243 const size_t max_msn = imap_msn_highest(&mdata->msn);
244
245 for (unsigned int msn = 1; msn <= max_msn + 1; msn++)
246 {
247 bool match = false;
248 if (msn <= max_msn)
249 {
250 struct Email *e_cur = imap_msn_get(&mdata->msn, msn - 1);
251 cur_uid = e_cur ? imap_edata_get(e_cur)->uid : 0;
252 if (!state || (cur_uid && ((cur_uid - 1) == last_uid)))
253 match = true;
254 last_uid = cur_uid;
255 }
256
257 if (match)
258 {
259 switch (state)
260 {
261 case 1: /* single: convert to a range */
262 state = 2;
264
265 case 2: /* extend range ending */
266 range_end = cur_uid;
267 break;
268 default:
269 state = 1;
270 range_begin = cur_uid;
271 break;
272 }
273 }
274 else if (state)
275 {
276 if (first)
277 first = 0;
278 else
279 buf_addch(buf, ',');
280
281 if (state == 1)
282 buf_add_printf(buf, "%u", range_begin);
283 else if (state == 2)
284 buf_add_printf(buf, "%u:%u", range_begin, range_end);
285
286 state = 1;
287 range_begin = cur_uid;
288 }
289 }
290}
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition buffer.c:204
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition buffer.c:241
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition edata.c:66
struct Email * imap_msn_get(const struct MSNArray *msn, int idx)
Return the Email associated with an msn.
Definition msn.c:83
size_t imap_msn_highest(const struct MSNArray *msn)
Return the highest MSN in use.
Definition msn.c:72
#define FALLTHROUGH
Definition lib.h:117
The envelope/body of an email.
Definition email.h:39
unsigned int uid
32-bit Message UID
Definition edata.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_hcache_open()

void imap_hcache_open ( struct ImapAccountData * adata,
struct ImapMboxData * mdata,
bool create )

Open a header cache.

Parameters
adataImap Account data
mdataImap Mailbox data
createCreate a new header cache if missing?

Definition at line 307 of file util.c.

308{
309 if (!adata || !mdata)
310 return;
311
312 if (mdata->hcache)
313 return;
314
315 struct HeaderCache *hc = NULL;
316 struct Buffer *mbox = buf_pool_get();
317 struct Buffer *cachepath = buf_pool_get();
318
319 imap_cachepath(adata->delim, mdata->name, mbox);
320
321 if (strstr(buf_string(mbox), "/../") || mutt_str_equal(buf_string(mbox), "..") ||
322 mutt_strn_equal(buf_string(mbox), "../", 3))
323 {
324 goto cleanup;
325 }
326 size_t len = buf_len(mbox);
327 if ((len > 3) && (mutt_str_equal(buf_string(mbox) + len - 3, "/..")))
328 goto cleanup;
329
330 struct Url url = { 0 };
331 account_to_url(&adata->conn->account, &url);
332 url.path = mbox->data;
333 url_tobuffer(&url, cachepath, U_PATH);
334
335 const char *const c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
336 hc = hcache_open(c_header_cache, buf_string(cachepath), imap_hcache_namer, create);
337
338cleanup:
339 buf_pool_release(&mbox);
340 buf_pool_release(&cachepath);
341 mdata->hcache = hc;
342}
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition buffer.c:491
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition buffer.h:96
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition helpers.c:168
static void imap_hcache_namer(const struct StoreOps *store_ops, const char *path, struct Buffer *dest)
Generate a filename for the header cache - Implements hcache_namer_t -.
Definition util.c:295
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer, bool create)
Multiplexor for StoreOps::open.
Definition hcache.c:477
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:665
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
Definition string.c:429
void account_to_url(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
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
char * data
Pointer to data.
Definition buffer.h:37
Header Cache.
Definition lib.h:87
struct HeaderCache * hcache
Email header cache.
Definition mdata.h:64
char * name
Mailbox name.
Definition mdata.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
A parsed URL proto://user:password@host:port/path?a=1&b=2
Definition url.h:69
char * path
Path.
Definition url.h:75
int url_tobuffer(const struct Url *url, struct Buffer *buf, uint8_t flags)
Output the URL string for a given Url object.
Definition url.c:361
#define U_PATH
Path is included in URL.
Definition url.h:50
void imap_cachepath(char delim, const char *mailbox, struct Buffer *dest)
Generate a cache path for a mailbox.
Definition util.c:754
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_hcache_close()

void imap_hcache_close ( struct ImapMboxData * mdata)

Close the header cache.

Parameters
mdataImap Mailbox data

Definition at line 348 of file util.c.

349{
350 if (!mdata->hcache)
351 return;
352
353 hcache_close(&mdata->hcache);
354}
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition hcache.c:549
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_hcache_get()

struct Email * imap_hcache_get ( struct ImapMboxData * mdata,
unsigned int uid )

Get a header cache entry by its UID.

Parameters
mdataImap Mailbox data
uidUID to find
Return values
ptrEmail
NULLFailure

Definition at line 363 of file util.c.

364{
365 if (!mdata->hcache)
366 return NULL;
367
368 char key[16] = { 0 };
369
370 snprintf(key, sizeof(key), "%u", uid);
371 struct HCacheEntry hce = hcache_fetch_email(mdata->hcache, key, mutt_str_len(key),
372 mdata->uidvalidity);
373 if (!hce.email && hce.uidvalidity)
374 {
375 mutt_debug(LL_DEBUG3, "hcache uidvalidity mismatch: %u\n", hce.uidvalidity);
376 }
377
378 return hce.email;
379}
struct HCacheEntry hcache_fetch_email(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
Definition hcache.c:569
Wrapper for Email retrieved from the header cache.
Definition lib.h:100
uint32_t uidvalidity
IMAP-specific UIDVALIDITY.
Definition lib.h:101
struct Email * email
Retrieved email.
Definition lib.h:103
uint32_t uidvalidity
UID validity.
Definition mdata.h:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_hcache_put()

int imap_hcache_put ( struct ImapMboxData * mdata,
struct Email * e )

Add an entry to the header cache.

Parameters
mdataImap Mailbox data
eEmail
Return values
0Success
-1Failure

Definition at line 388 of file util.c.

389{
390 if (!mdata->hcache)
391 return -1;
392
393 char key[16] = { 0 };
394
395 snprintf(key, sizeof(key), "%u", imap_edata_get(e)->uid);
396 return hcache_store_email(mdata->hcache, key, mutt_str_len(key), e, mdata->uidvalidity);
397}
int hcache_store_email(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
Definition hcache.c:683
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_hcache_del()

int imap_hcache_del ( struct ImapMboxData * mdata,
unsigned int uid )

Delete an item from the header cache.

Parameters
mdataImap Mailbox data
uidUID of entry to delete
Return values
0Success
-1Failure

Definition at line 406 of file util.c.

407{
408 if (!mdata->hcache)
409 return -1;
410
411 char key[16] = { 0 };
412
413 snprintf(key, sizeof(key), "%u", uid);
414 return hcache_delete_email(mdata->hcache, key, mutt_str_len(key));
415}
int hcache_delete_email(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition hcache.c:752
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_hcache_store_uid_seqset()

int imap_hcache_store_uid_seqset ( struct ImapMboxData * mdata)

Store a UID Sequence Set in the header cache.

Parameters
mdataImap Mailbox data
Return values
0Success
-1Error

Definition at line 423 of file util.c.

424{
425 if (!mdata->hcache)
426 return -1;
427
428 struct Buffer *buf = buf_pool_get();
429 buf_alloc(buf, 8192); // The seqset is likely large. Preallocate to reduce reallocs
431
432 int rc = hcache_store_raw(mdata->hcache, "UIDSEQSET", 9, buf->data, buf_len(buf) + 1);
433 mutt_debug(LL_DEBUG3, "Stored UIDSEQSET %s\n", buf_string(buf));
434 buf_pool_release(&buf);
435 return rc;
436}
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
Definition buffer.c:337
int hcache_store_raw(struct HeaderCache *hc, const char *key, size_t keylen, void *data, size_t dlen)
Store a key / data pair.
Definition hcache.c:737
static void imap_msn_index_to_uid_seqset(struct Buffer *buf, struct ImapMboxData *mdata)
Convert MSN index of UIDs to Seqset.
Definition util.c:238
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_hcache_clear_uid_seqset()

int imap_hcache_clear_uid_seqset ( struct ImapMboxData * mdata)

Delete a UID Sequence Set from the header cache.

Parameters
mdataImap Mailbox data
Return values
0Success
-1Error

Definition at line 444 of file util.c.

445{
446 if (!mdata->hcache)
447 return -1;
448
449 return hcache_delete_raw(mdata->hcache, "UIDSEQSET", 9);
450}
int hcache_delete_raw(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition hcache.c:765
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_hcache_get_uid_seqset()

char * imap_hcache_get_uid_seqset ( struct ImapMboxData * mdata)

Get a UID Sequence Set from the header cache.

Parameters
mdataImap Mailbox data
Return values
ptrUID Sequence Set
NULLError

Definition at line 458 of file util.c.

459{
460 if (!mdata->hcache)
461 return NULL;
462
463 char *seqset = hcache_fetch_raw_str(mdata->hcache, "UIDSEQSET", 9);
464 mutt_debug(LL_DEBUG3, "Retrieved UIDSEQSET %s\n", NONULL(seqset));
465
466 return seqset;
467}
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
Definition hcache.c:662
#define NONULL(x)
Definition string2.h:44
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_parse_path()

int imap_parse_path ( const char * path,
struct ConnAccount * cac,
char * mailbox,
size_t mailboxlen )

Parse an IMAP mailbox name into ConnAccount, name.

Parameters
pathMailbox path to parse
cacAccount credentials
mailboxBuffer for mailbox name
mailboxlenLength of buffer
Return values
0Success
-1Failure

Given an IMAP mailbox name, return host, port and a path IMAP servers will recognize.

Definition at line 482 of file util.c.

483{
484 static unsigned short ImapPort = 0;
485 static unsigned short ImapsPort = 0;
486
487 if (ImapPort == 0)
488 {
489 struct servent *service = getservbyname("imap", "tcp");
490 if (service)
491 ImapPort = ntohs(service->s_port);
492 else
493 ImapPort = IMAP_PORT;
494 mutt_debug(LL_DEBUG3, "Using default IMAP port %d\n", ImapPort);
495 }
496
497 if (ImapsPort == 0)
498 {
499 struct servent *service = getservbyname("imaps", "tcp");
500 if (service)
501 ImapsPort = ntohs(service->s_port);
502 else
503 ImapsPort = IMAP_SSL_PORT;
504 mutt_debug(LL_DEBUG3, "Using default IMAPS port %d\n", ImapsPort);
505 }
506
507 /* Defaults */
508 cac->port = ImapPort;
510 cac->service = "imap";
512
513 struct Url *url = url_parse(path);
514 if (!url)
515 return -1;
516
517 if ((url->scheme != U_IMAP) && (url->scheme != U_IMAPS))
518 {
519 url_free(&url);
520 return -1;
521 }
522
523 if ((account_from_url(cac, url) < 0) || (cac->host[0] == '\0'))
524 {
525 url_free(&url);
526 return -1;
527 }
528
529 if (url->scheme == U_IMAPS)
530 cac->flags |= MUTT_ACCT_SSL;
531
532 mutt_str_copy(mailbox, url->path, mailboxlen);
533
534 url_free(&url);
535
536 if ((cac->flags & MUTT_ACCT_SSL) && !(cac->flags & MUTT_ACCT_PORT))
537 cac->port = ImapsPort;
538
539 return 0;
540}
@ MUTT_ACCT_PORT
Port field has been set.
Definition connaccount.h:47
@ MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition connaccount.h:51
static const char * imap_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field() -.
Definition util.c:211
#define IMAP_PORT
Default port for IMAP.
Definition private.h:44
#define IMAP_SSL_PORT
Port for IMAP over SSL/TLS.
Definition private.h:45
int account_from_url(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
@ MUTT_ACCT_TYPE_IMAP
Imap Account.
const char * service
Name of the service, e.g. "imap".
Definition connaccount.h:67
char host[128]
Server to login to.
Definition connaccount.h:60
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Definition connaccount.h:76
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition connaccount.h:65
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition connaccount.h:66
unsigned short port
Port to connect to.
Definition connaccount.h:64
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
Definition url.h:70
struct Url * url_parse(const char *src)
Fill in Url.
Definition url.c:242
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition url.c:124
@ U_IMAP
Url is imap://.
Definition url.h:39
@ U_IMAPS
Url is imaps://.
Definition url.h:40
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_mxcmp()

int imap_mxcmp ( const char * mx1,
const char * mx2 )

Compare mailbox names, giving priority to INBOX.

Parameters
mx1First mailbox name
mx2Second mailbox name
Return values
<0First mailbox precedes Second mailbox
0Mailboxes are the same
>0Second mailbox precedes First mailbox

Like a normal sort function except that "INBOX" will be sorted to the beginning of the list.

Definition at line 553 of file util.c.

554{
555 char *b1 = NULL;
556 char *b2 = NULL;
557 int rc;
558
559 if (!mx1 || (*mx1 == '\0'))
560 mx1 = "INBOX";
561 if (!mx2 || (*mx2 == '\0'))
562 mx2 = "INBOX";
563 if (mutt_istr_equal(mx1, "INBOX") && mutt_istr_equal(mx2, "INBOX"))
564 {
565 return 0;
566 }
567
568 b1 = MUTT_MEM_MALLOC(strlen(mx1) + 1, char);
569 b2 = MUTT_MEM_MALLOC(strlen(mx2) + 1, char);
570
571 imap_fix_path(mx1, b1, strlen(mx1) + 1);
572 imap_fix_path(mx2, b2, strlen(mx2) + 1);
573
574 rc = mutt_str_cmp(b1, b2);
575 FREE(&b1);
576 FREE(&b2);
577
578 return rc;
579}
#define FREE(x)
Free memory and set the pointer to NULL.
Definition memory.h:68
#define MUTT_MEM_MALLOC(n, type)
Definition memory.h:53
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition string.c:403
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition string.c:677
char * imap_fix_path(const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition util.c:686
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_pretty_mailbox()

void imap_pretty_mailbox ( char * path,
size_t pathlen,
const char * folder )

Prettify an IMAP mailbox name.

Parameters
pathMailbox name to be tidied
pathlenLength of path
folderPath to use for '+' abbreviations

Called by mutt_pretty_mailbox() to make IMAP paths look nice.

Definition at line 589 of file util.c.

590{
591 struct ConnAccount cac_target = { { 0 } };
592 struct ConnAccount cac_home = { { 0 } };
593 struct Url url = { 0 };
594 const char *delim = NULL;
595 int tlen;
596 int hlen = 0;
597 bool home_match = false;
598 char target_mailbox[1024] = { 0 };
599 char home_mailbox[1024] = { 0 };
600
601 if (imap_parse_path(path, &cac_target, target_mailbox, sizeof(target_mailbox)) < 0)
602 return;
603
604 if (imap_path_probe(folder, NULL) != MUTT_IMAP)
605 goto fallback;
606
607 if (imap_parse_path(folder, &cac_home, home_mailbox, sizeof(home_mailbox)) < 0)
608 goto fallback;
609
610 tlen = mutt_str_len(target_mailbox);
611 hlen = mutt_str_len(home_mailbox);
612
613 /* check whether we can do '+' substitution */
614 if (tlen && imap_account_match(&cac_home, &cac_target) &&
615 mutt_strn_equal(home_mailbox, target_mailbox, hlen))
616 {
617 const char *const c_imap_delim_chars = cs_subset_string(NeoMutt->sub, "imap_delim_chars");
618 if (hlen == 0)
619 {
620 home_match = true;
621 }
622 else if (c_imap_delim_chars)
623 {
624 for (delim = c_imap_delim_chars; *delim != '\0'; delim++)
625 if (target_mailbox[hlen] == *delim)
626 home_match = true;
627 }
628 }
629
630 /* do the '+' substitution */
631 if (home_match)
632 {
633 *path++ = '+';
634 /* copy remaining path, skipping delimiter */
635 if (hlen != 0)
636 hlen++;
637 memcpy(path, target_mailbox + hlen, tlen - hlen);
638 path[tlen - hlen] = '\0';
639 return;
640 }
641
642fallback:
643 account_to_url(&cac_target, &url);
644 url.path = target_mailbox;
645 url_tostring(&url, path, pathlen, U_NONE);
646}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition helpers.c:291
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox?
Definition imap.c:2681
int url_tostring(const struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition url.c:426
#define U_NONE
No flags are set for URL parsing.
Definition url.h:49
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_continue()

enum QuadOption imap_continue ( const char * msg,
const char * resp )

Display a message and ask the user if they want to go on.

Parameters
msgLocation of the error
respMessage for user
Return values
QuadOptionResult, e.g. MUTT_NO

Definition at line 654 of file util.c.

655{
656 imap_error(msg, resp);
657 return query_yesorno(_("Continue?"), MUTT_NO);
658}
#define _(a)
Definition message.h:28
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition quad.h:38
enum QuadOption query_yesorno(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question.
Definition question.c:329
void imap_error(const char *where, const char *msg)
Show an error and abort.
Definition util.c:665
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_error()

void imap_error ( const char * where,
const char * msg )

Show an error and abort.

Parameters
whereLocation of the error
msgMessage for user

Definition at line 665 of file util.c.

666{
667 mutt_error("%s [%s]", where, msg);
668}
#define mutt_error(...)
Definition logging2.h:94
+ Here is the caller graph for this function:

◆ imap_fix_path()

char * imap_fix_path ( const char * mailbox,
char * path,
size_t plen )

Fix up the imap path.

Parameters
mailboxMailbox path
pathBuffer for the result
plenLength of buffer
Return values
ptrFixed-up path
Note
the first character in mailbox matching any of the characters in $imap_delim_chars is used as a delimiter.

This is necessary because the rest of neomutt assumes a hierarchy delimiter of '/', which is not necessarily true in IMAP. Additionally, the filesystem converts multiple hierarchy delimiters into a single one, ie "///" is equal to "/". IMAP servers are not required to do this. Moreover, IMAP servers may dislike the path ending with the delimiter.

Definition at line 686 of file util.c.

687{
688 const char *const c_imap_delim_chars = cs_subset_string(NeoMutt->sub, "imap_delim_chars");
689
690 char *out = path;
691 size_t space_left = plen - 1;
692
693 if (mailbox)
694 {
695 for (const char *c = mailbox; *c && space_left; c++, space_left--)
696 {
697 if (strchr(NONULL(c_imap_delim_chars), *c))
698 {
699 return imap_fix_path_with_delim(*c, mailbox, path, plen);
700 }
701 *out++ = *c;
702 }
703 }
704
705 *out = '\0';
706 return path;
707}
char * imap_fix_path_with_delim(const char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition util.c:718
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_fix_path_with_delim()

char * imap_fix_path_with_delim ( const char delim,
const char * mailbox,
char * path,
size_t plen )

Fix up the imap path.

Parameters
delimDelimiter specified by the server
mailboxMailbox path
pathBuffer for the result
plenLength of buffer
Return values
ptrFixed-up path

Definition at line 718 of file util.c.

719{
720 char *out = path;
721 size_t space_left = plen - 1;
722
723 if (mailbox)
724 {
725 for (const char *c = mailbox; *c && space_left; c++, space_left--)
726 {
727 if (*c == delim || *c == '/')
728 {
729 while (*c && *(c + 1) == *c)
730 c++;
731 *out++ = delim;
732 }
733 else
734 {
735 *out++ = *c;
736 }
737 }
738 }
739
740 if (out != path && *(out - 1) == delim)
741 {
742 out--;
743 }
744 *out = '\0';
745 return path;
746}
+ Here is the caller graph for this function:

◆ imap_cachepath()

void imap_cachepath ( char delim,
const char * mailbox,
struct Buffer * dest )

Generate a cache path for a mailbox.

Parameters
delimImap server delimiter
mailboxMailbox name
destBuffer to store cache path

Definition at line 754 of file util.c.

755{
756 const char *p = mailbox;
757 buf_reset(dest);
758 if (!p)
759 return;
760
761 while (*p)
762 {
763 if (p[0] == delim)
764 {
765 buf_addch(dest, '/');
766 /* simple way to avoid collisions with UIDs */
767 if ((p[1] >= '0') && (p[1] <= '9'))
768 buf_addch(dest, '_');
769 }
770 else
771 {
772 buf_addch(dest, *p);
773 }
774 p++;
775 }
776}
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition buffer.c:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_get_literal_count()

int imap_get_literal_count ( char * buf,
unsigned int * bytes )

Write number of bytes in an IMAP literal into bytes.

Parameters
[in]bufNumber as a string
[out]bytesResulting number
Return values
0Success
-1Failure

Definition at line 785 of file util.c.

786{
787 char *pc = NULL;
788 char *pn = NULL;
789
790 if (!buf || !(pc = strchr(buf, '{')))
791 return -1;
792
793 pc++;
794 pn = pc;
795 while (mutt_isdigit(*pc))
796 pc++;
797 *pc = '\0';
798 if (!mutt_str_atoui(pn, bytes))
799 return -1;
800
801 return 0;
802}
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition atoi.c:217
bool mutt_isdigit(int arg)
Wrapper for isdigit(3)
Definition ctype.c:66
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_get_qualifier()

char * imap_get_qualifier ( char * buf)

Get the qualifier from a tagged response.

Parameters
bufCommand string to process
Return values
ptrStart of the qualifier

In a tagged response, skip tag and status for the qualifier message. Used by imap_copy_message for TRYCREATE

Definition at line 812 of file util.c.

813{
814 char *s = buf;
815
816 /* skip tag */
817 s = imap_next_word(s);
818 /* skip OK/NO/BAD response */
819 s = imap_next_word(s);
820
821 return s;
822}
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition util.c:829
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_next_word()

char * imap_next_word ( char * s)

Find where the next IMAP word begins.

Parameters
sCommand string to process
Return values
ptrNext IMAP word

Definition at line 829 of file util.c.

830{
831 bool quoted = false;
832
833 while (*s)
834 {
835 if (*s == '\\')
836 {
837 s++;
838 if (*s)
839 s++;
840 continue;
841 }
842 if (*s == '\"')
843 quoted = !quoted;
844 if (!quoted && mutt_isspace(*s))
845 break;
846 s++;
847 }
848
849 SKIPWS(s);
850 return s;
851}
bool mutt_isspace(int arg)
Wrapper for isspace(3)
Definition ctype.c:96
#define SKIPWS(ch)
Definition string2.h:52
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_qualify_path()

void imap_qualify_path ( char * buf,
size_t buflen,
struct ConnAccount * cac,
char * path )

Make an absolute IMAP folder target.

Parameters
bufBuffer for the result
buflenLength of buffer
cacConnAccount of the account
pathPath relative to the mailbox

Definition at line 860 of file util.c.

861{
862 struct Url url = { 0 };
863 account_to_url(cac, &url);
864 url.path = path;
865 url_tostring(&url, buf, buflen, U_NONE);
866}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_buf_qualify_path()

void imap_buf_qualify_path ( struct Buffer * buf,
struct ConnAccount * cac,
char * path )

Make an absolute IMAP folder target to a buffer.

Parameters
bufBuffer for the result
cacConnAccount of the account
pathPath relative to the mailbox

Definition at line 874 of file util.c.

875{
876 struct Url url = { 0 };
877 account_to_url(cac, &url);
878 url.path = path;
879 url_tobuffer(&url, buf, U_NONE);
880}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_quote_string()

void imap_quote_string ( char * dest,
size_t dlen,
const char * src,
bool quote_backtick )

Quote string according to IMAP rules.

Parameters
destBuffer for the result
dlenLength of the buffer
srcString to be quoted
quote_backtickIf true, quote backticks too

Surround string with quotes, escape " and \ with backslash

Definition at line 891 of file util.c.

892{
893 const char *quote = "`\"\\";
894 if (!quote_backtick)
895 quote++;
896
897 char *pt = dest;
898 const char *s = src;
899
900 if (dlen < 3)
901 {
902 *dest = '\0';
903 return;
904 }
905
906 *pt++ = '"';
907 /* save room for quote-chars */
908 dlen -= 3;
909
910 for (; *s && dlen; s++)
911 {
912 if (strchr(quote, *s))
913 {
914 if (dlen < 2)
915 break;
916 dlen -= 2;
917 *pt++ = '\\';
918 *pt++ = *s;
919 }
920 else
921 {
922 *pt++ = *s;
923 dlen--;
924 }
925 }
926 *pt++ = '"';
927 *pt = '\0';
928}
+ Here is the caller graph for this function:

◆ imap_unquote_string()

void imap_unquote_string ( char * s)

Equally stupid unquoting routine.

Parameters
sString to be unquoted

Definition at line 934 of file util.c.

935{
936 char *d = s;
937
938 if (*s == '\"')
939 s++;
940 else
941 return;
942
943 while (*s)
944 {
945 if (*s == '\"')
946 {
947 *d = '\0';
948 return;
949 }
950 if (*s == '\\')
951 {
952 s++;
953 }
954 if (*s)
955 {
956 *d = *s;
957 d++;
958 s++;
959 }
960 }
961 *d = '\0';
962}
+ Here is the caller graph for this function:

◆ imap_munge_mbox_name()

void imap_munge_mbox_name ( bool unicode,
char * dest,
size_t dlen,
const char * src )

Quote awkward characters in a mailbox name.

Parameters
unicodetrue if Unicode is allowed
destBuffer to store safe mailbox name
dlenLength of buffer
srcMailbox name

Definition at line 971 of file util.c.

972{
973 char *buf = mutt_str_dup(src);
974 imap_utf_encode(unicode, &buf);
975
976 imap_quote_string(dest, dlen, buf, false);
977
978 FREE(&buf);
979}
void imap_utf_encode(bool unicode, char **s)
Encode email from local charset to UTF-8.
Definition utf7.c:397
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
Quote string according to IMAP rules.
Definition util.c:891
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_unmunge_mbox_name()

void imap_unmunge_mbox_name ( bool unicode,
char * s )

Remove quoting from a mailbox name.

Parameters
unicodetrue if Unicode is allowed
sMailbox name

The string will be altered in-place.

Definition at line 988 of file util.c.

989{
991
992 char *buf = mutt_str_dup(s);
993 if (buf)
994 {
995 imap_utf_decode(unicode, &buf);
996 strncpy(s, buf, strlen(s));
997 }
998
999 FREE(&buf);
1000}
void imap_utf_decode(bool unicode, char **s)
Decode email from UTF-8 to local charset.
Definition utf7.c:430
void imap_unquote_string(char *s)
Equally stupid unquoting routine.
Definition util.c:934
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_keep_alive()

void imap_keep_alive ( void )

Poll the current folder to keep the connection alive.

Definition at line 1005 of file util.c.

1006{
1007 time_t now = mutt_date_now();
1008 const short c_imap_keep_alive = cs_subset_number(NeoMutt->sub, "imap_keep_alive");
1009
1010 struct Account **ap = NULL;
1012 {
1013 struct Account *a = *ap;
1014 if (a->type != MUTT_IMAP)
1015 continue;
1016
1017 struct ImapAccountData *adata = a->adata;
1018 if (!adata || !adata->mailbox)
1019 continue;
1020
1021 if ((adata->state >= IMAP_AUTHENTICATED) && (now >= (adata->lastread + c_imap_keep_alive)))
1022 imap_check_mailbox(adata->mailbox, true);
1023 }
1024}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition helpers.c:143
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition private.h:120
enum MxStatus imap_check_mailbox(struct Mailbox *m, bool force)
Use the NOOP or IDLE command to poll for new mail.
Definition imap.c:1220
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition date.c:457
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_wait_keep_alive()

int imap_wait_keep_alive ( pid_t pid)

Wait for a process to change state.

Parameters
pidProcess ID to listen to
Return values
num'wstatus' from waitpid()

Definition at line 1031 of file util.c.

1032{
1033 struct sigaction oldalrm = { 0 };
1034 struct sigaction act = { 0 };
1035 sigset_t oldmask = { 0 };
1036 int rc;
1037
1038 const bool c_imap_passive = cs_subset_bool(NeoMutt->sub, "imap_passive");
1039 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", true, NULL);
1040 OptKeepQuiet = true;
1041
1042 sigprocmask(SIG_SETMASK, NULL, &oldmask);
1043
1044 sigemptyset(&act.sa_mask);
1045 act.sa_handler = mutt_sig_empty_handler;
1046#ifdef SA_INTERRUPT
1047 act.sa_flags = SA_INTERRUPT;
1048#else
1049 act.sa_flags = 0;
1050#endif
1051
1052 sigaction(SIGALRM, &act, &oldalrm);
1053
1054 const short c_imap_keep_alive = cs_subset_number(NeoMutt->sub, "imap_keep_alive");
1055 alarm(c_imap_keep_alive);
1056 while ((waitpid(pid, &rc, 0) < 0) && (errno == EINTR))
1057 {
1058 alarm(0); /* cancel a possibly pending alarm */
1060 alarm(c_imap_keep_alive);
1061 }
1062
1063 alarm(0); /* cancel a possibly pending alarm */
1064
1065 sigaction(SIGALRM, &oldalrm, NULL);
1066 sigprocmask(SIG_SETMASK, &oldmask, NULL);
1067
1068 OptKeepQuiet = false;
1069 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", c_imap_passive, NULL);
1070
1071 return rc;
1072}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program
Definition globals.c:49
void mutt_sig_empty_handler(int sig)
Dummy signal handler.
Definition signal.c:130
int cs_subset_str_native_set(const struct ConfigSubset *sub, const char *name, intptr_t value, struct Buffer *err)
Natively set the value of a string config item.
Definition subset.c:303
void imap_keep_alive(void)
Poll the current folder to keep the connection alive.
Definition util.c:1005
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_allow_reopen()

void imap_allow_reopen ( struct Mailbox * m)

Allow re-opening a folder upon expunge.

Parameters
mMailbox

Definition at line 1078 of file util.c.

1079{
1081 struct ImapMboxData *mdata = imap_mdata_get(m);
1082 if (!adata || !adata->mailbox || (adata->mailbox != m) || !mdata)
1083 return;
1084 mdata->reopen |= IMAP_REOPEN_ALLOW;
1085}
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition adata.c:162
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition mdata.c:61
@ IMAP_REOPEN_ALLOW
Allow re-opening a folder upon expunge.
Definition private.h:68
struct Mailbox * mailbox
Current selected mailbox.
Definition adata.h:80
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_disallow_reopen()

void imap_disallow_reopen ( struct Mailbox * m)

Disallow re-opening a folder upon expunge.

Parameters
mMailbox

Definition at line 1091 of file util.c.

1092{
1094 struct ImapMboxData *mdata = imap_mdata_get(m);
1095 if (!adata || !adata->mailbox || (adata->mailbox != m) || !mdata)
1096 return;
1097 mdata->reopen &= ~IMAP_REOPEN_ALLOW;
1098}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_account_match()

bool imap_account_match ( const struct ConnAccount * a1,
const struct ConnAccount * a2 )

Compare two Accounts.

Parameters
a1First ConnAccount
a2Second ConnAccount
Return values
trueAccounts match

Definition at line 1106 of file util.c.

1107{
1108 if (!a1 || !a2)
1109 return false;
1110 if (a1->type != a2->type)
1111 return false;
1112 if (!mutt_istr_equal(a1->host, a2->host))
1113 return false;
1114 if ((a1->port != 0) && (a2->port != 0) && (a1->port != a2->port))
1115 return false;
1116 if (a1->flags & a2->flags & MUTT_ACCT_USER)
1117 return mutt_str_equal(a1->user, a2->user);
1118
1119 const char *user = NONULL(NeoMutt->username);
1120
1121 const char *const c_imap_user = cs_subset_string(NeoMutt->sub, "imap_user");
1122 if ((a1->type == MUTT_ACCT_TYPE_IMAP) && c_imap_user)
1123 user = c_imap_user;
1124
1125 if (a1->flags & MUTT_ACCT_USER)
1126 return mutt_str_equal(a1->user, user);
1127 if (a2->flags & MUTT_ACCT_USER)
1128 return mutt_str_equal(a2->user, user);
1129
1130 return true;
1131}
@ MUTT_ACCT_USER
User field has been set.
Definition connaccount.h:48
char user[128]
Username.
Definition connaccount.h:62
char * username
User's login name.
Definition neomutt.h:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_seqset_iterator_new()

struct SeqsetIterator * mutt_seqset_iterator_new ( const char * seqset)

Create a new Sequence Set Iterator.

Parameters
seqsetSource Sequence Set
Return values
ptrNewly allocated Sequence Set Iterator

Definition at line 1138 of file util.c.

1139{
1140 if (!seqset || (*seqset == '\0'))
1141 return NULL;
1142
1143 struct SeqsetIterator *iter = MUTT_MEM_CALLOC(1, struct SeqsetIterator);
1144 iter->full_seqset = mutt_str_dup(seqset);
1145 iter->eostr = strchr(iter->full_seqset, '\0');
1146 iter->substr_cur = iter->substr_end = iter->full_seqset;
1147
1148 return iter;
1149}
#define MUTT_MEM_CALLOC(n, type)
Definition memory.h:52
UID Sequence Set Iterator.
Definition private.h:185
char * eostr
End of string.
Definition private.h:187
char * substr_end
End of substring.
Definition private.h:193
char * substr_cur
Current position in substring.
Definition private.h:192
char * full_seqset
Full sequence set string.
Definition private.h:186
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_seqset_iterator_next()

int mutt_seqset_iterator_next ( struct SeqsetIterator * iter,
unsigned int * next )

Get the next UID from a Sequence Set.

Parameters
[in]iterSequence Set Iterator
[out]nextNext UID in set
Return values
0Next sequence is generated
1Iterator is finished
-1error

Definition at line 1159 of file util.c.

1160{
1161 if (!iter || !next)
1162 return -1;
1163
1164 if (iter->in_range)
1165 {
1166 if ((iter->down && (iter->range_cur == (iter->range_end - 1))) ||
1167 (!iter->down && (iter->range_cur == (iter->range_end + 1))))
1168 {
1169 iter->in_range = 0;
1170 }
1171 }
1172
1173 if (!iter->in_range)
1174 {
1175 iter->substr_cur = iter->substr_end;
1176 if (iter->substr_cur == iter->eostr)
1177 return 1;
1178
1179 iter->substr_end = strchr(iter->substr_cur, ',');
1180 if (!iter->substr_end)
1181 iter->substr_end = iter->eostr;
1182 else
1183 *(iter->substr_end++) = '\0';
1184
1185 char *range_sep = strchr(iter->substr_cur, ':');
1186 if (range_sep)
1187 *range_sep++ = '\0';
1188
1189 if (!mutt_str_atoui_full(iter->substr_cur, &iter->range_cur))
1190 return -1;
1191 if (range_sep)
1192 {
1193 if (!mutt_str_atoui_full(range_sep, &iter->range_end))
1194 return -1;
1195 }
1196 else
1197 {
1198 iter->range_end = iter->range_cur;
1199 }
1200
1201 iter->down = (iter->range_end < iter->range_cur);
1202 iter->in_range = 1;
1203 }
1204
1205 *next = iter->range_cur;
1206 if (iter->down)
1207 iter->range_cur--;
1208 else
1209 iter->range_cur++;
1210
1211 return 0;
1212}
unsigned int range_end
End of range.
Definition private.h:191
int down
Counting down.
Definition private.h:189
int in_range
Currently in a range.
Definition private.h:188
unsigned int range_cur
Current range value.
Definition private.h:190
+ Here is the caller graph for this function:

◆ mutt_seqset_iterator_free()

void mutt_seqset_iterator_free ( struct SeqsetIterator ** ptr)

Free a Sequence Set Iterator.

Parameters
[out]ptrIterator to free

Definition at line 1218 of file util.c.

1219{
1220 if (!ptr || !*ptr)
1221 return;
1222
1223 struct SeqsetIterator *iter = *ptr;
1224 FREE(&iter->full_seqset);
1225 FREE(ptr);
1226}
+ Here is the caller graph for this function: