NeoMutt  2024-10-02-37-gfa9146
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 <ctype.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 "adata.h"
#include "edata.h"
#include "globals.h"
#include "mdata.h"
#include "msn.h"
#include "mutt_account.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 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 (const 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

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 *np = NULL;
84 TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
85 {
86 if (np->type != MUTT_IMAP)
87 continue;
88
89 tmp_adata = np->adata;
90 if (!tmp_adata)
91 continue;
92 if (imap_account_match(&tmp_adata->conn->account, &cac))
93 {
94 if (mdata)
95 {
96 *mdata = imap_mdata_new(tmp_adata, tmp);
97 }
98 *adata = tmp_adata;
99 return 0;
100 }
101 }
102 mutt_debug(LL_DEBUG3, "no ImapAccountData found\n");
103 return -1;
104}
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
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:45
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
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:53
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:42
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:47
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:478
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
Definition: util.c:1094
+ 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 110 of file util.c.

111{
112 mutt_hash_free(&mdata->uid_hash);
113 imap_msn_free(&mdata->msn);
114 mutt_bcache_close(&mdata->bcache);
115}
void mutt_bcache_close(struct BodyCache **ptr)
Close an Email-Body Cache.
Definition: bcache.c:169
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
void imap_msn_free(struct MSNArray *msn)
Free the cache.
Definition: msn.c:62
struct BodyCache * bcache
Email body cache.
Definition: mdata.h:61
struct HashTable * uid_hash
Hash Table: "uid" -> Email.
Definition: mdata.h:59
+ 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 124 of file util.c.

125{
126 /* Make a copy of the mailbox name, but only if the pointers are different */
127 if (mbox != buf)
128 mutt_str_copy(buf, mbox, buflen);
129
130 int n = mutt_str_len(buf);
131
132 /* Let's go backwards until the next delimiter
133 *
134 * If buf[n] is a '/', the first n-- will allow us
135 * to ignore it. If it isn't, then buf looks like
136 * "/aaaaa/bbbb". There is at least one "b", so we can't skip
137 * the "/" after the 'a's.
138 *
139 * If buf == '/', then n-- => n == 0, so the loop ends
140 * immediately */
141 for (n--; (n >= 0) && (buf[n] != delim); n--)
142 ; // do nothing
143
144 /* We stopped before the beginning. There is a trailing slash. */
145 if (n > 0)
146 {
147 /* Strip the trailing delimiter. */
148 buf[n] = '\0';
149 }
150 else
151 {
152 buf[0] = (n == 0) ? delim : '\0';
153 }
154}
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
Definition: string.c:496
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:581
+ 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 165 of file util.c.

166{
167 struct ImapAccountData *adata = NULL;
168 struct ImapMboxData *mdata = NULL;
169 char mbox[1024] = { 0 };
170
171 if (imap_adata_find(path, &adata, &mdata) < 0)
172 {
173 mutt_str_copy(buf, path, buflen);
174 return;
175 }
176
177 /* Gets the parent mbox in mbox */
178 imap_get_parent(mdata->name, adata->delim, mbox, sizeof(mbox));
179
180 /* Returns a fully qualified IMAP url */
181 imap_qualify_path(buf, buflen, &adata->conn->account, mbox);
182 imap_mdata_free((void *) &mdata);
183}
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:75
IMAP-specific Mailbox data -.
Definition: mdata.h:40
void * mdata
Driver specific data.
Definition: mailbox.h:132
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *cac, char *path)
Make an absolute IMAP folder target.
Definition: util.c:856
void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen)
Get an IMAP folder's parent.
Definition: util.c:124
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 192 of file util.c.

193{
194 struct ImapAccountData *adata = NULL;
195 struct ImapMboxData *mdata = NULL;
196
197 if (imap_adata_find(path, &adata, &mdata) < 0)
198 return;
199
200 /* Returns a fully qualified IMAP url */
201 imap_qualify_path(path, plen, &adata->conn->account, mdata->name);
202 imap_mdata_free((void *) &mdata);
203}
+ 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 235 of file util.c.

236{
237 int first = 1, state = 0;
238 unsigned int cur_uid = 0, last_uid = 0;
239 unsigned int range_begin = 0, range_end = 0;
240 const size_t max_msn = imap_msn_highest(&mdata->msn);
241
242 for (unsigned int msn = 1; msn <= max_msn + 1; msn++)
243 {
244 bool match = false;
245 if (msn <= max_msn)
246 {
247 struct Email *e_cur = imap_msn_get(&mdata->msn, msn - 1);
248 cur_uid = e_cur ? imap_edata_get(e_cur)->uid : 0;
249 if (!state || (cur_uid && ((cur_uid - 1) == last_uid)))
250 match = true;
251 last_uid = cur_uid;
252 }
253
254 if (match)
255 {
256 switch (state)
257 {
258 case 1: /* single: convert to a range */
259 state = 2;
261
262 case 2: /* extend range ending */
263 range_end = cur_uid;
264 break;
265 default:
266 state = 1;
267 range_begin = cur_uid;
268 break;
269 }
270 }
271 else if (state)
272 {
273 if (first)
274 first = 0;
275 else
276 buf_addch(buf, ',');
277
278 if (state == 1)
279 buf_add_printf(buf, "%u", range_begin);
280 else if (state == 2)
281 buf_add_printf(buf, "%u:%u", range_begin, range_end);
282
283 state = 1;
284 range_begin = cur_uid;
285 }
286 }
287}
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:67
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
#define FALLTHROUGH
Definition: lib.h:111
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 303 of file util.c.

304{
305 if (!adata || !mdata)
306 return;
307
308 if (mdata->hcache)
309 return;
310
311 struct HeaderCache *hc = NULL;
312 struct Buffer *mbox = buf_pool_get();
313 struct Buffer *cachepath = buf_pool_get();
314
315 imap_cachepath(adata->delim, mdata->name, mbox);
316
317 if (strstr(buf_string(mbox), "/../") || mutt_str_equal(buf_string(mbox), "..") ||
318 mutt_strn_equal(buf_string(mbox), "../", 3))
319 {
320 goto cleanup;
321 }
322 size_t len = buf_len(mbox);
323 if ((len > 3) && (mutt_str_equal(buf_string(mbox) + len - 3, "/..")))
324 goto cleanup;
325
326 struct Url url = { 0 };
327 mutt_account_tourl(&adata->conn->account, &url);
328 url.path = mbox->data;
329 url_tobuffer(&url, cachepath, U_PATH);
330
331 const char *const c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
332 hc = hcache_open(c_header_cache, buf_string(cachepath), imap_hcache_namer, create);
333
334cleanup:
335 buf_pool_release(&mbox);
336 buf_pool_release(&cachepath);
337 mdata->hcache = hc;
338}
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 char *path, struct Buffer *dest)
Generate a filename for the header cache - Implements hcache_namer_t -.
Definition: util.c:292
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer, bool create)
Multiplexor for StoreOps::open.
Definition: hcache.c:471
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:660
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:425
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:80
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
String manipulation buffer.
Definition: buffer.h:36
char * data
Pointer to data.
Definition: buffer.h:37
Header Cache.
Definition: lib.h:86
struct HeaderCache * hcache
Email header cache.
Definition: mdata.h:63
char * name
Mailbox name.
Definition: mdata.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:46
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:358
#define U_PATH
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:750
+ 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 344 of file util.c.

345{
346 if (!mdata->hcache)
347 return;
348
349 hcache_close(&mdata->hcache);
350}
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
Definition: hcache.c:542
+ 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 359 of file util.c.

360{
361 if (!mdata->hcache)
362 return NULL;
363
364 char key[16] = { 0 };
365
366 snprintf(key, sizeof(key), "%u", uid);
367 struct HCacheEntry hce = hcache_fetch_email(mdata->hcache, key, mutt_str_len(key),
368 mdata->uidvalidity);
369 if (!hce.email && hce.uidvalidity)
370 {
371 mutt_debug(LL_DEBUG3, "hcache uidvalidity mismatch: %u\n", hce.uidvalidity);
372 }
373
374 return hce.email;
375}
struct HCacheEntry hcache_fetch_email(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
Definition: hcache.c:562
Wrapper for Email retrieved from the header cache.
Definition: lib.h:99
uint32_t uidvalidity
IMAP-specific UIDVALIDITY.
Definition: lib.h:100
struct Email * email
Retrieved email.
Definition: lib.h:102
uint32_t uidvalidity
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 384 of file util.c.

385{
386 if (!mdata->hcache)
387 return -1;
388
389 char key[16] = { 0 };
390
391 snprintf(key, sizeof(key), "%u", imap_edata_get(e)->uid);
392 return hcache_store_email(mdata->hcache, key, mutt_str_len(key), e, mdata->uidvalidity);
393}
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:670
+ 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 402 of file util.c.

403{
404 if (!mdata->hcache)
405 return -1;
406
407 char key[16] = { 0 };
408
409 snprintf(key, sizeof(key), "%u", uid);
410 return hcache_delete_email(mdata->hcache, key, mutt_str_len(key));
411}
int hcache_delete_email(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:739
+ 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 419 of file util.c.

420{
421 if (!mdata->hcache)
422 return -1;
423
424 struct Buffer *buf = buf_pool_get();
425 buf_alloc(buf, 8192); // The seqset is likely large. Preallocate to reduce reallocs
427
428 int rc = hcache_store_raw(mdata->hcache, "UIDSEQSET", 9, buf->data, buf_len(buf) + 1);
429 mutt_debug(LL_DEBUG3, "Stored UIDSEQSET %s\n", buf_string(buf));
430 buf_pool_release(&buf);
431 return rc;
432}
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:724
static void imap_msn_index_to_uid_seqset(struct Buffer *buf, struct ImapMboxData *mdata)
Convert MSN index of UIDs to Seqset.
Definition: util.c:235
+ 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 440 of file util.c.

441{
442 if (!mdata->hcache)
443 return -1;
444
445 return hcache_delete_raw(mdata->hcache, "UIDSEQSET", 9);
446}
int hcache_delete_raw(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_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 454 of file util.c.

455{
456 if (!mdata->hcache)
457 return NULL;
458
459 char *seqset = hcache_fetch_raw_str(mdata->hcache, "UIDSEQSET", 9);
460 mutt_debug(LL_DEBUG3, "Retrieved UIDSEQSET %s\n", NONULL(seqset));
461
462 return seqset;
463}
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
Definition: hcache.c:652
#define NONULL(x)
Definition: string2.h:37
+ 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 478 of file util.c.

479{
480 static unsigned short ImapPort = 0;
481 static unsigned short ImapsPort = 0;
482
483 if (ImapPort == 0)
484 {
485 struct servent *service = getservbyname("imap", "tcp");
486 if (service)
487 ImapPort = ntohs(service->s_port);
488 else
489 ImapPort = IMAP_PORT;
490 mutt_debug(LL_DEBUG3, "Using default IMAP port %d\n", ImapPort);
491 }
492
493 if (ImapsPort == 0)
494 {
495 struct servent *service = getservbyname("imaps", "tcp");
496 if (service)
497 ImapsPort = ntohs(service->s_port);
498 else
499 ImapsPort = IMAP_SSL_PORT;
500 mutt_debug(LL_DEBUG3, "Using default IMAPS port %d\n", ImapsPort);
501 }
502
503 /* Defaults */
504 cac->port = ImapPort;
506 cac->service = "imap";
508
509 struct Url *url = url_parse(path);
510 if (!url)
511 return -1;
512
513 if ((url->scheme != U_IMAP) && (url->scheme != U_IMAPS))
514 {
515 url_free(&url);
516 return -1;
517 }
518
519 if ((mutt_account_fromurl(cac, url) < 0) || (cac->host[0] == '\0'))
520 {
521 url_free(&url);
522 return -1;
523 }
524
525 if (url->scheme == U_IMAPS)
526 cac->flags |= MUTT_ACCT_SSL;
527
528 mutt_str_copy(mailbox, url->path, mailboxlen);
529
530 url_free(&url);
531
532 if ((cac->flags & MUTT_ACCT_SSL) && !(cac->flags & MUTT_ACCT_PORT))
533 cac->port = ImapsPort;
534
535 return 0;
536}
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
Definition: connaccount.h:47
#define MUTT_ACCT_PORT
Port field has been set.
Definition: connaccount.h:43
static const char * imap_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field() -.
Definition: util.c:208
#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 mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:44
@ MUTT_ACCT_TYPE_IMAP
Imap Account.
Definition: mutt_account.h:38
const char * service
Name of the service, e.g. "imap".
Definition: connaccount.h:61
char host[128]
Server to login to.
Definition: connaccount.h:54
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Definition: connaccount.h:70
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
Definition: connaccount.h:59
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
Definition: connaccount.h:60
unsigned short port
Port to connect to.
Definition: connaccount.h:58
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:239
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 549 of file util.c.

550{
551 char *b1 = NULL;
552 char *b2 = NULL;
553 int rc;
554
555 if (!mx1 || (*mx1 == '\0'))
556 mx1 = "INBOX";
557 if (!mx2 || (*mx2 == '\0'))
558 mx2 = "INBOX";
559 if (mutt_istr_equal(mx1, "INBOX") && mutt_istr_equal(mx2, "INBOX"))
560 {
561 return 0;
562 }
563
564 b1 = mutt_mem_malloc(strlen(mx1) + 1);
565 b2 = mutt_mem_malloc(strlen(mx2) + 1);
566
567 imap_fix_path(mx1, b1, strlen(mx1) + 1);
568 imap_fix_path(mx2, b2, strlen(mx2) + 1);
569
570 rc = mutt_str_cmp(b1, b2);
571 FREE(&b1);
572 FREE(&b2);
573
574 return rc;
575}
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:91
#define FREE(x)
Definition: memory.h:45
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
Definition: string.c:399
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:672
char * imap_fix_path(const char *mailbox, char *path, size_t plen)
Fix up the imap path.
Definition: util.c:682
+ 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 585 of file util.c.

586{
587 struct ConnAccount cac_target = { { 0 } };
588 struct ConnAccount cac_home = { { 0 } };
589 struct Url url = { 0 };
590 const char *delim = NULL;
591 int tlen;
592 int hlen = 0;
593 bool home_match = false;
594 char target_mailbox[1024] = { 0 };
595 char home_mailbox[1024] = { 0 };
596
597 if (imap_parse_path(path, &cac_target, target_mailbox, sizeof(target_mailbox)) < 0)
598 return;
599
600 if (imap_path_probe(folder, NULL) != MUTT_IMAP)
601 goto fallback;
602
603 if (imap_parse_path(folder, &cac_home, home_mailbox, sizeof(home_mailbox)) < 0)
604 goto fallback;
605
606 tlen = mutt_str_len(target_mailbox);
607 hlen = mutt_str_len(home_mailbox);
608
609 /* check whether we can do '+' substitution */
610 if (tlen && imap_account_match(&cac_home, &cac_target) &&
611 mutt_strn_equal(home_mailbox, target_mailbox, hlen))
612 {
613 const char *const c_imap_delim_chars = cs_subset_string(NeoMutt->sub, "imap_delim_chars");
614 if (hlen == 0)
615 {
616 home_match = true;
617 }
618 else if (c_imap_delim_chars)
619 {
620 for (delim = c_imap_delim_chars; *delim != '\0'; delim++)
621 if (target_mailbox[hlen] == *delim)
622 home_match = true;
623 }
624 }
625
626 /* do the '+' substitution */
627 if (home_match)
628 {
629 *path++ = '+';
630 /* copy remaining path, skipping delimiter */
631 if (hlen != 0)
632 hlen++;
633 memcpy(path, target_mailbox + hlen, tlen - hlen);
634 path[tlen - hlen] = '\0';
635 return;
636 }
637
638fallback:
639 mutt_account_tourl(&cac_target, &url);
640 url.path = target_mailbox;
641 url_tostring(&url, path, pathlen, U_NO_FLAGS);
642}
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? - Implements MxOps::path_probe() -.
Definition: imap.c:2345
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:423
#define U_NO_FLAGS
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 650 of file util.c.

651{
652 imap_error(msg, resp);
653 return query_yesorno(_("Continue?"), MUTT_NO);
654}
#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:327
void imap_error(const char *where, const char *msg)
Show an error and abort.
Definition: util.c:661
+ 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 661 of file util.c.

662{
663 mutt_error("%s [%s]", where, msg);
664}
#define mutt_error(...)
Definition: logging2.h:92
+ 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 682 of file util.c.

683{
684 const char *const c_imap_delim_chars = cs_subset_string(NeoMutt->sub, "imap_delim_chars");
685
686 char *out = path;
687 size_t space_left = plen - 1;
688
689 if (mailbox)
690 {
691 for (const char *c = mailbox; *c && space_left; ++c, --space_left)
692 {
693 if (strchr(NONULL(c_imap_delim_chars), *c))
694 {
695 return imap_fix_path_with_delim(*c, mailbox, path, plen);
696 }
697 *out++ = *c;
698 }
699 }
700
701 *out = '\0';
702 return path;
703}
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:714
+ 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 714 of file util.c.

715{
716 char *out = path;
717 size_t space_left = plen - 1;
718
719 if (mailbox)
720 {
721 for (const char *c = mailbox; *c && space_left; ++c, --space_left)
722 {
723 if (*c == delim || *c == '/')
724 {
725 while (*c && *(c + 1) == *c)
726 c++;
727 *out++ = delim;
728 }
729 else
730 {
731 *out++ = *c;
732 }
733 }
734 }
735
736 if (out != path && *(out - 1) == delim)
737 {
738 --out;
739 }
740 *out = '\0';
741 return path;
742}
+ 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 750 of file util.c.

751{
752 const char *p = mailbox;
753 buf_reset(dest);
754 if (!p)
755 return;
756
757 while (*p)
758 {
759 if (p[0] == delim)
760 {
761 buf_addch(dest, '/');
762 /* simple way to avoid collisions with UIDs */
763 if ((p[1] >= '0') && (p[1] <= '9'))
764 buf_addch(dest, '_');
765 }
766 else
767 {
768 buf_addch(dest, *p);
769 }
770 p++;
771 }
772}
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 ( const 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 781 of file util.c.

782{
783 char *pc = NULL;
784 char *pn = NULL;
785
786 if (!buf || !(pc = strchr(buf, '{')))
787 return -1;
788
789 pc++;
790 pn = pc;
791 while (isdigit((unsigned char) *pc))
792 pc++;
793 *pc = '\0';
794 if (!mutt_str_atoui(pn, bytes))
795 return -1;
796
797 return 0;
798}
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: atoi.c:214
+ 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 808 of file util.c.

809{
810 char *s = buf;
811
812 /* skip tag */
813 s = imap_next_word(s);
814 /* skip OK/NO/BAD response */
815 s = imap_next_word(s);
816
817 return s;
818}
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition: util.c:825
+ 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 825 of file util.c.

826{
827 bool quoted = false;
828
829 while (*s)
830 {
831 if (*s == '\\')
832 {
833 s++;
834 if (*s)
835 s++;
836 continue;
837 }
838 if (*s == '\"')
839 quoted = !quoted;
840 if (!quoted && isspace(*s))
841 break;
842 s++;
843 }
844
845 SKIPWS(s);
846 return s;
847}
#define SKIPWS(ch)
Definition: string2.h:45
+ 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 856 of file util.c.

857{
858 struct Url url = { 0 };
859 mutt_account_tourl(cac, &url);
860 url.path = path;
861 url_tostring(&url, buf, buflen, U_NO_FLAGS);
862}
+ 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 870 of file util.c.

871{
872 struct Url url = { 0 };
873 mutt_account_tourl(cac, &url);
874 url.path = path;
875 url_tobuffer(&url, buf, U_NO_FLAGS);
876}
+ 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 887 of file util.c.

888{
889 const char *quote = "`\"\\";
890 if (!quote_backtick)
891 quote++;
892
893 char *pt = dest;
894 const char *s = src;
895
896 *pt++ = '"';
897 /* save room for quote-chars */
898 dlen -= 3;
899
900 for (; *s && dlen; s++)
901 {
902 if (strchr(quote, *s))
903 {
904 if (dlen < 2)
905 break;
906 dlen -= 2;
907 *pt++ = '\\';
908 *pt++ = *s;
909 }
910 else
911 {
912 *pt++ = *s;
913 dlen--;
914 }
915 }
916 *pt++ = '"';
917 *pt = '\0';
918}
+ 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 924 of file util.c.

925{
926 char *d = s;
927
928 if (*s == '\"')
929 s++;
930 else
931 return;
932
933 while (*s)
934 {
935 if (*s == '\"')
936 {
937 *d = '\0';
938 return;
939 }
940 if (*s == '\\')
941 {
942 s++;
943 }
944 if (*s)
945 {
946 *d = *s;
947 d++;
948 s++;
949 }
950 }
951 *d = '\0';
952}
+ 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 961 of file util.c.

962{
963 char *buf = mutt_str_dup(src);
964 imap_utf_encode(unicode, &buf);
965
966 imap_quote_string(dest, dlen, buf, false);
967
968 FREE(&buf);
969}
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:253
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
Quote string according to IMAP rules.
Definition: util.c:887
+ 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 978 of file util.c.

979{
981
982 char *buf = mutt_str_dup(s);
983 if (buf)
984 {
985 imap_utf_decode(unicode, &buf);
986 strncpy(s, buf, strlen(s));
987 }
988
989 FREE(&buf);
990}
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:924
+ 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 995 of file util.c.

996{
997 time_t now = mutt_date_now();
998 struct Account *np = NULL;
999 const short c_imap_keep_alive = cs_subset_number(NeoMutt->sub, "imap_keep_alive");
1000 TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
1001 {
1002 if (np->type != MUTT_IMAP)
1003 continue;
1004
1005 struct ImapAccountData *adata = np->adata;
1006 if (!adata || !adata->mailbox)
1007 continue;
1008
1009 if ((adata->state >= IMAP_AUTHENTICATED) && (now >= (adata->lastread + c_imap_keep_alive)))
1010 imap_check_mailbox(adata->mailbox, true);
1011 }
1012}
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:107
enum MxStatus imap_check_mailbox(struct Mailbox *m, bool force)
Use the NOOP or IDLE command to poll for new mail.
Definition: imap.c:1032
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:456
+ 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 1019 of file util.c.

1020{
1021 struct sigaction oldalrm = { 0 };
1022 struct sigaction act = { 0 };
1023 sigset_t oldmask = { 0 };
1024 int rc;
1025
1026 const bool c_imap_passive = cs_subset_bool(NeoMutt->sub, "imap_passive");
1027 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", true, NULL);
1028 OptKeepQuiet = true;
1029
1030 sigprocmask(SIG_SETMASK, NULL, &oldmask);
1031
1032 sigemptyset(&act.sa_mask);
1033 act.sa_handler = mutt_sig_empty_handler;
1034#ifdef SA_INTERRUPT
1035 act.sa_flags = SA_INTERRUPT;
1036#else
1037 act.sa_flags = 0;
1038#endif
1039
1040 sigaction(SIGALRM, &act, &oldalrm);
1041
1042 const short c_imap_keep_alive = cs_subset_number(NeoMutt->sub, "imap_keep_alive");
1043 alarm(c_imap_keep_alive);
1044 while ((waitpid(pid, &rc, 0) < 0) && (errno == EINTR))
1045 {
1046 alarm(0); /* cancel a possibly pending alarm */
1048 alarm(c_imap_keep_alive);
1049 }
1050
1051 alarm(0); /* cancel a possibly pending alarm */
1052
1053 sigaction(SIGALRM, &oldalrm, NULL);
1054 sigprocmask(SIG_SETMASK, &oldmask, NULL);
1055
1056 OptKeepQuiet = false;
1057 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", c_imap_passive, NULL);
1058
1059 return rc;
1060}
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:63
void mutt_sig_empty_handler(int sig)
Dummy signal handler.
Definition: signal.c:117
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:297
void imap_keep_alive(void)
Poll the current folder to keep the connection alive.
Definition: util.c:995
+ 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 1066 of file util.c.

1067{
1069 struct ImapMboxData *mdata = imap_mdata_get(m);
1070 if (!adata || !adata->mailbox || (adata->mailbox != m) || !mdata)
1071 return;
1072 mdata->reopen |= IMAP_REOPEN_ALLOW;
1073}
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:123
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: mdata.c:61
#define IMAP_REOPEN_ALLOW
Allow re-opening a folder upon expunge.
Definition: private.h:64
struct Mailbox * mailbox
Current selected mailbox.
Definition: adata.h:76
+ 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 1079 of file util.c.

1080{
1082 struct ImapMboxData *mdata = imap_mdata_get(m);
1083 if (!adata || !adata->mailbox || (adata->mailbox != m) || !mdata)
1084 return;
1085 mdata->reopen &= ~IMAP_REOPEN_ALLOW;
1086}
+ 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 1094 of file util.c.

1095{
1096 if (!a1 || !a2)
1097 return false;
1098 if (a1->type != a2->type)
1099 return false;
1100 if (!mutt_istr_equal(a1->host, a2->host))
1101 return false;
1102 if ((a1->port != 0) && (a2->port != 0) && (a1->port != a2->port))
1103 return false;
1104 if (a1->flags & a2->flags & MUTT_ACCT_USER)
1105 return mutt_str_equal(a1->user, a2->user);
1106
1107 const char *user = NONULL(Username);
1108
1109 const char *const c_imap_user = cs_subset_string(NeoMutt->sub, "imap_user");
1110 if ((a1->type == MUTT_ACCT_TYPE_IMAP) && c_imap_user)
1111 user = c_imap_user;
1112
1113 if (a1->flags & MUTT_ACCT_USER)
1114 return mutt_str_equal(a1->user, user);
1115 if (a2->flags & MUTT_ACCT_USER)
1116 return mutt_str_equal(a2->user, user);
1117
1118 return true;
1119}
#define MUTT_ACCT_USER
User field has been set.
Definition: connaccount.h:44
char * Username
User's login name.
Definition: globals.c:40
char user[128]
Username.
Definition: connaccount.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 1126 of file util.c.

1127{
1128 if (!seqset || (*seqset == '\0'))
1129 return NULL;
1130
1131 struct SeqsetIterator *iter = mutt_mem_calloc(1, sizeof(struct SeqsetIterator));
1132 iter->full_seqset = mutt_str_dup(seqset);
1133 iter->eostr = strchr(iter->full_seqset, '\0');
1134 iter->substr_cur = iter->substr_end = iter->full_seqset;
1135
1136 return iter;
1137}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:51
UID Sequence Set Iterator.
Definition: private.h:169
char * eostr
Definition: private.h:171
char * substr_end
Definition: private.h:177
char * substr_cur
Definition: private.h:176
char * full_seqset
Definition: private.h:170
+ 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 1147 of file util.c.

1148{
1149 if (!iter || !next)
1150 return -1;
1151
1152 if (iter->in_range)
1153 {
1154 if ((iter->down && (iter->range_cur == (iter->range_end - 1))) ||
1155 (!iter->down && (iter->range_cur == (iter->range_end + 1))))
1156 {
1157 iter->in_range = 0;
1158 }
1159 }
1160
1161 if (!iter->in_range)
1162 {
1163 iter->substr_cur = iter->substr_end;
1164 if (iter->substr_cur == iter->eostr)
1165 return 1;
1166
1167 iter->substr_end = strchr(iter->substr_cur, ',');
1168 if (!iter->substr_end)
1169 iter->substr_end = iter->eostr;
1170 else
1171 *(iter->substr_end++) = '\0';
1172
1173 char *range_sep = strchr(iter->substr_cur, ':');
1174 if (range_sep)
1175 *range_sep++ = '\0';
1176
1177 if (!mutt_str_atoui_full(iter->substr_cur, &iter->range_cur))
1178 return -1;
1179 if (range_sep)
1180 {
1181 if (!mutt_str_atoui_full(range_sep, &iter->range_end))
1182 return -1;
1183 }
1184 else
1185 {
1186 iter->range_end = iter->range_cur;
1187 }
1188
1189 iter->down = (iter->range_end < iter->range_cur);
1190 iter->in_range = 1;
1191 }
1192
1193 *next = iter->range_cur;
1194 if (iter->down)
1195 iter->range_cur--;
1196 else
1197 iter->range_cur++;
1198
1199 return 0;
1200}
unsigned int range_end
Definition: private.h:175
unsigned int range_cur
Definition: private.h:174
+ 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 1206 of file util.c.

1207{
1208 if (!ptr || !*ptr)
1209 return;
1210
1211 struct SeqsetIterator *iter = *ptr;
1212 FREE(&iter->full_seqset);
1213 FREE(ptr);
1214}
+ Here is the caller graph for this function: