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

Detailed Description

IMAP helper functions.

Authors
  • Michael R. Elkins
  • Brandon Long
  • Brendan Cully
  • Richard Russon

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

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

Definition in file 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 71 of file util.c.

73{
74 struct ConnAccount cac = { { 0 } };
75 struct ImapAccountData *tmp_adata = NULL;
76 char tmp[1024] = { 0 };
77
78 if (imap_parse_path(path, &cac, tmp, sizeof(tmp)) < 0)
79 return -1;
80
81 struct Account *np = NULL;
82 TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
83 {
84 if (np->type != MUTT_IMAP)
85 continue;
86
87 tmp_adata = np->adata;
88 if (!tmp_adata)
89 continue;
90 if (imap_account_match(&tmp_adata->conn->account, &cac))
91 {
92 *mdata = imap_mdata_new(tmp_adata, tmp);
93 *adata = tmp_adata;
94 return 0;
95 }
96 }
97 mutt_debug(LL_DEBUG3, "no ImapAccountData found\n");
98 return -1;
99}
#define mutt_debug(LEVEL,...)
Definition: logging.h:84
struct ImapMboxData * imap_mdata_new(struct ImapAccountData *adata, const char *name)
Allocate and initialise a new ImapMboxData structure.
Definition: mdata.c:73
@ LL_DEBUG3
Log at debug level 3.
Definition: logging.h:42
@ MUTT_IMAP
'IMAP' Mailbox type
Definition: mailbox.h:50
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:725
A group of associated Mailboxes.
Definition: account.h:37
enum MailboxType type
Type of Mailboxes this Account contains.
Definition: account.h:38
void * adata
Private data (for Mailbox backends)
Definition: account.h:43
Login details for a remote server.
Definition: connaccount.h:53
struct ConnAccount account
Account details: username, password, etc.
Definition: connection.h:50
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:37
struct AccountList accounts
List of all Accounts.
Definition: neomutt.h:40
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:474
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
Definition: util.c:1036
+ 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 105 of file util.c.

106{
107 mutt_hash_free(&mdata->uid_hash);
108 imap_msn_free(&mdata->msn);
109 mutt_bcache_close(&mdata->bcache);
110}
void mutt_bcache_close(struct BodyCache **bcache)
Close an Email-Body Cache.
Definition: bcache.c:165
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
Definition: hash.c:457
void imap_msn_free(struct MSN *msn)
Free the cache.
Definition: msn.c:59
struct BodyCache * bcache
Email body cache.
Definition: mdata.h:60
struct HashTable * uid_hash
Definition: mdata.h:58
+ 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 119 of file util.c.

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

161{
162 struct ImapAccountData *adata = NULL;
163 struct ImapMboxData *mdata = NULL;
164 char mbox[1024] = { 0 };
165
166 if (imap_adata_find(path, &adata, &mdata) < 0)
167 {
168 mutt_str_copy(buf, path, buflen);
169 return;
170 }
171
172 /* Gets the parent mbox in mbox */
173 imap_get_parent(mdata->name, adata->delim, mbox, sizeof(mbox));
174
175 /* Returns a fully qualified IMAP url */
176 imap_qualify_path(buf, buflen, &adata->conn->account, mbox);
177 imap_mdata_free((void *) &mdata);
178}
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:39
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:812
void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen)
Get an IMAP folder's parent.
Definition: util.c:119
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
Definition: util.c:71
+ 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 187 of file util.c.

188{
189 struct ImapAccountData *adata = NULL;
190 struct ImapMboxData *mdata = NULL;
191
192 if (imap_adata_find(path, &adata, &mdata) < 0)
193 return;
194
195 /* Returns a fully qualified IMAP url */
196 imap_qualify_path(path, plen, &adata->conn->account, mdata->name);
197 imap_mdata_free((void *) &mdata);
198}
static size_t plen
Length of cached packet.
Definition: pgppacket.c:39
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_get_field()

static const char * imap_get_field ( enum ConnAccountField  field,
void *  gf_data 
)
static

Get connection login credentials - Implements ConnAccount::get_field()

Definition at line 203 of file util.c.

204{
205 switch (field)
206 {
207 case MUTT_CA_LOGIN:
208 return cs_subset_string(NeoMutt->sub, "imap_login");
209 case MUTT_CA_USER:
210 return cs_subset_string(NeoMutt->sub, "imap_user");
211 case MUTT_CA_PASS:
212 return cs_subset_string(NeoMutt->sub, "imap_pass");
214 return cs_subset_string(NeoMutt->sub, "imap_oauth_refresh_command");
215 case MUTT_CA_HOST:
216 default:
217 return NULL;
218 }
219}
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
Definition: helpers.c:317
@ MUTT_CA_OAUTH_CMD
OAuth refresh command.
Definition: connaccount.h:38
@ MUTT_CA_USER
User name.
Definition: connaccount.h:36
@ MUTT_CA_LOGIN
Login name.
Definition: connaccount.h:35
@ MUTT_CA_HOST
Server name.
Definition: connaccount.h:34
@ MUTT_CA_PASS
Password.
Definition: connaccount.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
+ 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 230 of file util.c.

231{
232 int first = 1, state = 0;
233 unsigned int cur_uid = 0, last_uid = 0;
234 unsigned int range_begin = 0, range_end = 0;
235 const size_t max_msn = imap_msn_highest(&mdata->msn);
236
237 for (unsigned int msn = 1; msn <= max_msn + 1; msn++)
238 {
239 bool match = false;
240 if (msn <= max_msn)
241 {
242 struct Email *e_cur = imap_msn_get(&mdata->msn, msn - 1);
243 cur_uid = e_cur ? imap_edata_get(e_cur)->uid : 0;
244 if (!state || (cur_uid && ((cur_uid - 1) == last_uid)))
245 match = true;
246 last_uid = cur_uid;
247 }
248
249 if (match)
250 {
251 switch (state)
252 {
253 case 1: /* single: convert to a range */
254 state = 2;
255 /* fall through */
256 case 2: /* extend range ending */
257 range_end = cur_uid;
258 break;
259 default:
260 state = 1;
261 range_begin = cur_uid;
262 break;
263 }
264 }
265 else if (state)
266 {
267 if (first)
268 first = 0;
269 else
270 mutt_buffer_addch(buf, ',');
271
272 if (state == 1)
273 mutt_buffer_add_printf(buf, "%u", range_begin);
274 else if (state == 2)
275 mutt_buffer_add_printf(buf, "%u:%u", range_begin, range_end);
276
277 state = 1;
278 range_begin = cur_uid;
279 }
280 }
281}
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
Definition: buffer.c:248
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
Definition: buffer.c:211
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Definition: edata.c:65
size_t imap_msn_highest(const struct MSN *msn)
Return the highest MSN in use.
Definition: msn.c:69
struct Email * imap_msn_get(const struct MSN *msn, size_t idx)
Return the Email associated with an msn.
Definition: msn.c:80
The envelope/body of an email.
Definition: email.h:37
unsigned int uid
32-bit Message UID
Definition: edata.h:44
+ 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 
)

Open a header cache.

Parameters
adataImap Account data
mdataImap Mailbox data

Definition at line 296 of file util.c.

297{
298 if (!adata || !mdata)
299 return;
300
301 if (mdata->hcache)
302 return;
303
304 struct HeaderCache *hc = NULL;
305 struct Buffer *mbox = mutt_buffer_pool_get();
306 struct Buffer *cachepath = mutt_buffer_pool_get();
307
308 imap_cachepath(adata->delim, mdata->name, mbox);
309
310 if (strstr(mutt_buffer_string(mbox), "/../") ||
311 mutt_str_equal(mutt_buffer_string(mbox), "..") ||
312 mutt_strn_equal(mutt_buffer_string(mbox), "../", 3))
313 {
314 goto cleanup;
315 }
316 size_t len = mutt_buffer_len(mbox);
317 if ((len > 3) && (strcmp(mutt_buffer_string(mbox) + len - 3, "/..") == 0))
318 goto cleanup;
319
320 struct Url url = { 0 };
321 mutt_account_tourl(&adata->conn->account, &url);
322 url.path = mbox->data;
323 url_tobuffer(&url, cachepath, U_PATH);
324
325 const char *const c_header_cache = cs_subset_path(NeoMutt->sub, "header_cache");
326 hc = mutt_hcache_open(c_header_cache, mutt_buffer_string(cachepath), imap_hcache_namer);
327
328cleanup:
330 mutt_buffer_pool_release(&cachepath);
331 mdata->hcache = hc;
332}
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
Definition: buffer.c:409
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:78
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
Definition: helpers.c:194
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:286
struct HeaderCache * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
Definition: hcache.c:373
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:807
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:496
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
Definition: mutt_account.c:79
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
Definition: pool.c:112
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:101
String manipulation buffer.
Definition: buffer.h:34
char * data
Pointer to data.
Definition: buffer.h:35
Header cache structure.
Definition: lib.h:88
struct HeaderCache * hcache
Email header cache.
Definition: mdata.h:62
char * name
Mailbox name.
Definition: mdata.h:40
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(struct Url *url, struct Buffer *buf, uint8_t flags)
Output the URL string for a given Url object.
Definition: url.c:353
#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:708
+ 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 338 of file util.c.

339{
340 if (!mdata->hcache)
341 return;
342
344 mdata->hcache = NULL;
345}
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
Definition: hcache.c:483
+ 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 354 of file util.c.

355{
356 if (!mdata->hcache)
357 return NULL;
358
359 char key[16] = { 0 };
360
361 sprintf(key, "/%u", uid);
362 struct HCacheEntry hce = mutt_hcache_fetch(mdata->hcache, key, mutt_str_len(key),
363 mdata->uidvalidity);
364 if (!hce.email && hce.uidvalidity)
365 {
366 mutt_debug(LL_DEBUG3, "hcache uidvalidity mismatch: %u\n", hce.uidvalidity);
367 }
368
369 return hce.email;
370}
struct HCacheEntry mutt_hcache_fetch(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
Definition: hcache.c:507
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:50
+ 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 379 of file util.c.

380{
381 if (!mdata->hcache)
382 return -1;
383
384 char key[16] = { 0 };
385
386 sprintf(key, "/%u", imap_edata_get(e)->uid);
387 return mutt_hcache_store(mdata->hcache, key, mutt_str_len(key), e, mdata->uidvalidity);
388}
int mutt_hcache_store(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
Definition: hcache.c:610
+ 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 397 of file util.c.

398{
399 if (!mdata->hcache)
400 return -1;
401
402 char key[16] = { 0 };
403
404 sprintf(key, "/%u", uid);
405 return mutt_hcache_delete_record(mdata->hcache, key, mutt_str_len(key));
406}
int mutt_hcache_delete_record(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
Definition: hcache.c:689
+ 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 414 of file util.c.

415{
416 if (!mdata->hcache)
417 return -1;
418
419 /* The seqset is likely large. Preallocate to reduce reallocs */
420 struct Buffer buf = mutt_buffer_make(8192);
421 imap_msn_index_to_uid_seqset(&buf, mdata);
422
423 int rc = mutt_hcache_store_raw(mdata->hcache, "/UIDSEQSET", 10, buf.data,
424 mutt_buffer_len(&buf) + 1);
425 mutt_debug(LL_DEBUG3, "Stored /UIDSEQSET %s\n", buf.data);
427 return rc;
428}
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
Definition: buffer.c:67
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
Definition: buffer.c:347
int mutt_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:668
static void imap_msn_index_to_uid_seqset(struct Buffer *buf, struct ImapMboxData *mdata)
Convert MSN index of UIDs to Seqset.
Definition: util.c:230
+ 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 436 of file util.c.

437{
438 if (!mdata->hcache)
439 return -1;
440
441 return mutt_hcache_delete_record(mdata->hcache, "/UIDSEQSET", 10);
442}
+ 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 450 of file util.c.

451{
452 if (!mdata->hcache)
453 return NULL;
454
455 char *seqset = mutt_hcache_fetch_str(mdata->hcache, "/UIDSEQSET", 10);
456 mutt_debug(LL_DEBUG3, "Retrieved /UIDSEQSET %s\n", NONULL(seqset));
457
458 return seqset;
459}
char * mutt_hcache_fetch_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
Definition: hcache.c:594
#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 474 of file util.c.

475{
476 static unsigned short ImapPort = 0;
477 static unsigned short ImapsPort = 0;
478
479 if (ImapPort == 0)
480 {
481 struct servent *service = getservbyname("imap", "tcp");
482 if (service)
483 ImapPort = ntohs(service->s_port);
484 else
485 ImapPort = IMAP_PORT;
486 mutt_debug(LL_DEBUG3, "Using default IMAP port %d\n", ImapPort);
487 }
488
489 if (ImapsPort == 0)
490 {
491 struct servent *service = getservbyname("imaps", "tcp");
492 if (service)
493 ImapsPort = ntohs(service->s_port);
494 else
495 ImapsPort = IMAP_SSL_PORT;
496 mutt_debug(LL_DEBUG3, "Using default IMAPS port %d\n", ImapsPort);
497 }
498
499 /* Defaults */
500 cac->port = ImapPort;
502 cac->service = "imap";
504
505 struct Url *url = url_parse(path);
506 if (!url)
507 return -1;
508
509 if ((url->scheme != U_IMAP) && (url->scheme != U_IMAPS))
510 {
511 url_free(&url);
512 return -1;
513 }
514
515 if ((mutt_account_fromurl(cac, url) < 0) || (cac->host[0] == '\0'))
516 {
517 url_free(&url);
518 return -1;
519 }
520
521 if (url->scheme == U_IMAPS)
522 cac->flags |= MUTT_ACCT_SSL;
523
524 mutt_str_copy(mailbox, url->path, mailboxlen);
525
526 url_free(&url);
527
528 if ((cac->flags & MUTT_ACCT_SSL) && !(cac->flags & MUTT_ACCT_PORT))
529 cac->port = ImapsPort;
530
531 return 0;
532}
#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
#define IMAP_PORT
Default port for IMAP.
Definition: private.h:45
#define IMAP_SSL_PORT
Port for IMAP over SSL/TLS.
Definition: private.h:46
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
Definition: mutt_account.c:43
@ MUTT_ACCT_TYPE_IMAP
Imap Account.
Definition: mutt_account.h:37
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)
Function to get some login credentials.
Definition: connaccount.h:68
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:234
void url_free(struct Url **ptr)
Free the contents of a URL.
Definition: url.c:123
@ U_IMAP
Url is imap://.
Definition: url.h:39
@ U_IMAPS
Url is imaps://.
Definition: url.h:40
static const char * imap_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field()
Definition: util.c:203
+ 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 545 of file util.c.

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

582{
583 struct ConnAccount cac_target = { { 0 } };
584 struct ConnAccount cac_home = { { 0 } };
585 struct Url url = { 0 };
586 const char *delim = NULL;
587 int tlen;
588 int hlen = 0;
589 bool home_match = false;
590 char target_mailbox[1024] = { 0 };
591 char home_mailbox[1024] = { 0 };
592
593 if (imap_parse_path(path, &cac_target, target_mailbox, sizeof(target_mailbox)) < 0)
594 return;
595
596 if (imap_path_probe(folder, NULL) != MUTT_IMAP)
597 goto fallback;
598
599 if (imap_parse_path(folder, &cac_home, home_mailbox, sizeof(home_mailbox)) < 0)
600 goto fallback;
601
602 tlen = mutt_str_len(target_mailbox);
603 hlen = mutt_str_len(home_mailbox);
604
605 /* check whether we can do '+' substitution */
606 if (tlen && imap_account_match(&cac_home, &cac_target) &&
607 mutt_strn_equal(home_mailbox, target_mailbox, hlen))
608 {
609 const char *const c_imap_delim_chars = cs_subset_string(NeoMutt->sub, "imap_delim_chars");
610 if (hlen == 0)
611 home_match = true;
612 else if (c_imap_delim_chars)
613 {
614 for (delim = c_imap_delim_chars; *delim != '\0'; delim++)
615 if (target_mailbox[hlen] == *delim)
616 home_match = true;
617 }
618 }
619
620 /* do the '+' substitution */
621 if (home_match)
622 {
623 *path++ = '+';
624 /* copy remaining path, skipping delimiter */
625 if (hlen != 0)
626 ++hlen;
627 memcpy(path, target_mailbox + hlen, tlen - hlen);
628 path[tlen - hlen] = '\0';
629 return;
630 }
631
632fallback:
633 mutt_account_tourl(&cac_target, &url);
634 url.path = target_mailbox;
635 url_tostring(&url, path, pathlen, U_NO_FLAGS);
636}
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
Definition: imap.c:2401
int url_tostring(struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
Definition: url.c:418
#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 644 of file util.c.

645{
646 imap_error(msg, resp);
647 return mutt_yesorno(_("Continue?"), MUTT_NO);
648}
#define _(a)
Definition: message.h:28
@ MUTT_NO
User answered 'No', or assume 'No'.
Definition: quad.h:38
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:194
void imap_error(const char *where, const char *msg)
Show an error and abort.
Definition: util.c:655
+ 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 655 of file util.c.

656{
657 mutt_error("%s [%s]", where, msg);
658}
#define mutt_error(...)
Definition: logging.h:87
+ Here is the caller graph for this function:

◆ imap_fix_path()

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

Fix up the imap path.

Parameters
delimDelimiter specified by the server, '\0' for $imap_delim_chars
mailboxMailbox path
pathBuffer for the result
plenLength of buffer
Return values
ptrFixed-up path
Note
if delim is '\0', 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 677 of file util.c.

678{
679 int i = 0;
680 for (; mailbox && *mailbox && (i < plen - 1); i++)
681 {
682 const char *const c_imap_delim_chars = cs_subset_string(NeoMutt->sub, "imap_delim_chars");
683 if (*mailbox == delim || (!delim && strchr(NONULL(c_imap_delim_chars), *mailbox)))
684 {
685 delim = *mailbox;
686 /* Skip multiple occurrences of delim */
687 while (*mailbox && *(mailbox + 1) == delim)
688 mailbox++;
689 }
690 path[i] = *mailbox++;
691 }
692
693 /* Do not terminate with a delimiter */
694 if (i && path[i - 1] == delim)
695 i--;
696
697 /* Ensure null termination */
698 path[i] = '\0';
699 return path;
700}
+ Here is the call graph for this function:
+ 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 708 of file util.c.

709{
710 const char *p = mailbox;
711 mutt_buffer_reset(dest);
712 if (!p)
713 return;
714
715 while (*p)
716 {
717 if (p[0] == delim)
718 {
719 mutt_buffer_addch(dest, '/');
720 /* simple way to avoid collisions with UIDs */
721 if ((p[1] >= '0') && (p[1] <= '9'))
722 mutt_buffer_addch(dest, '_');
723 }
724 else
725 mutt_buffer_addch(dest, *p);
726 p++;
727 }
728}
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
Definition: buffer.c:85
+ 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 737 of file util.c.

738{
739 char *pc = NULL;
740 char *pn = NULL;
741
742 if (!buf || !(pc = strchr(buf, '{')))
743 return -1;
744
745 pc++;
746 pn = pc;
747 while (isdigit((unsigned char) *pc))
748 pc++;
749 *pc = '\0';
750 if (!mutt_str_atoui(pn, bytes))
751 return -1;
752
753 return 0;
754}
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Definition: atoi.c:203
+ 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 764 of file util.c.

765{
766 char *s = buf;
767
768 /* skip tag */
769 s = imap_next_word(s);
770 /* skip OK/NO/BAD response */
771 s = imap_next_word(s);
772
773 return s;
774}
char * imap_next_word(char *s)
Find where the next IMAP word begins.
Definition: util.c:781
+ 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 781 of file util.c.

782{
783 bool quoted = false;
784
785 while (*s)
786 {
787 if (*s == '\\')
788 {
789 s++;
790 if (*s)
791 s++;
792 continue;
793 }
794 if (*s == '\"')
795 quoted = !quoted;
796 if (!quoted && IS_SPACE(*s))
797 break;
798 s++;
799 }
800
801 SKIPWS(s);
802 return s;
803}
#define IS_SPACE(ch)
Definition: string2.h:38
#define SKIPWS(ch)
Definition: string2.h:46
+ 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 812 of file util.c.

813{
814 struct Url url = { 0 };
815 mutt_account_tourl(cac, &url);
816 url.path = path;
817 url_tostring(&url, buf, buflen, U_NO_FLAGS);
818}
+ 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 829 of file util.c.

830{
831 const char *quote = "`\"\\";
832 if (!quote_backtick)
833 quote++;
834
835 char *pt = dest;
836 const char *s = src;
837
838 *pt++ = '"';
839 /* save room for quote-chars */
840 dlen -= 3;
841
842 for (; *s && dlen; s++)
843 {
844 if (strchr(quote, *s))
845 {
846 if (dlen < 2)
847 break;
848 dlen -= 2;
849 *pt++ = '\\';
850 *pt++ = *s;
851 }
852 else
853 {
854 *pt++ = *s;
855 dlen--;
856 }
857 }
858 *pt++ = '"';
859 *pt = '\0';
860}
+ 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 866 of file util.c.

867{
868 char *d = s;
869
870 if (*s == '\"')
871 s++;
872 else
873 return;
874
875 while (*s)
876 {
877 if (*s == '\"')
878 {
879 *d = '\0';
880 return;
881 }
882 if (*s == '\\')
883 {
884 s++;
885 }
886 if (*s)
887 {
888 *d = *s;
889 d++;
890 s++;
891 }
892 }
893 *d = '\0';
894}
+ 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 903 of file util.c.

904{
905 char *buf = mutt_str_dup(src);
906 imap_utf_encode(unicode, &buf);
907
908 imap_quote_string(dest, dlen, buf, false);
909
910 FREE(&buf);
911}
void imap_utf_encode(bool unicode, char **s)
Encode email from local charset to UTF-8.
Definition: utf7.c:390
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:250
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
Quote string according to IMAP rules.
Definition: util.c:829
+ 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 920 of file util.c.

921{
923
924 char *buf = mutt_str_dup(s);
925 if (buf)
926 {
927 imap_utf_decode(unicode, &buf);
928 strncpy(s, buf, strlen(s));
929 }
930
931 FREE(&buf);
932}
void imap_utf_decode(bool unicode, char **s)
Decode email from UTF-8 to local charset.
Definition: utf7.c:420
void imap_unquote_string(char *s)
Equally stupid unquoting routine.
Definition: util.c:866
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_keepalive()

void imap_keepalive ( void  )

Poll the current folder to keep the connection alive.

Definition at line 937 of file util.c.

938{
939 time_t now = mutt_date_now();
940 struct Account *np = NULL;
941 TAILQ_FOREACH(np, &NeoMutt->accounts, entries)
942 {
943 if (np->type != MUTT_IMAP)
944 continue;
945
946 struct ImapAccountData *adata = np->adata;
947 if (!adata || !adata->mailbox)
948 continue;
949
950 const short c_imap_keepalive = cs_subset_number(NeoMutt->sub, "imap_keepalive");
951 if ((adata->state >= IMAP_AUTHENTICATED) && (now >= (adata->lastread + c_imap_keepalive)))
952 imap_check_mailbox(adata->mailbox, true);
953 }
954}
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
Definition: helpers.c:169
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Definition: date.c:428
@ IMAP_AUTHENTICATED
Connection is authenticated.
Definition: private.h:109
enum MxStatus imap_check_mailbox(struct Mailbox *m, bool force)
Use the NOOP or IDLE command to poll for new mail.
Definition: imap.c:1108
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ imap_wait_keepalive()

int imap_wait_keepalive ( 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 961 of file util.c.

962{
963 struct sigaction oldalrm;
964 struct sigaction act;
965 sigset_t oldmask;
966 int rc;
967
968 const bool c_imap_passive = cs_subset_bool(NeoMutt->sub, "imap_passive");
969 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", true, NULL);
970 OptKeepQuiet = true;
971
972 sigprocmask(SIG_SETMASK, NULL, &oldmask);
973
974 sigemptyset(&act.sa_mask);
975 act.sa_handler = mutt_sig_empty_handler;
976#ifdef SA_INTERRUPT
977 act.sa_flags = SA_INTERRUPT;
978#else
979 act.sa_flags = 0;
980#endif
981
982 sigaction(SIGALRM, &act, &oldalrm);
983
984 const short c_imap_keepalive = cs_subset_number(NeoMutt->sub, "imap_keepalive");
985 alarm(c_imap_keepalive);
986 while ((waitpid(pid, &rc, 0) < 0) && (errno == EINTR))
987 {
988 alarm(0); /* cancel a possibly pending alarm */
990 alarm(c_imap_keepalive);
991 }
992
993 alarm(0); /* cancel a possibly pending alarm */
994
995 sigaction(SIGALRM, &oldalrm, NULL);
996 sigprocmask(SIG_SETMASK, &oldmask, NULL);
997
998 OptKeepQuiet = false;
999 cs_subset_str_native_set(NeoMutt->sub, "imap_passive", c_imap_passive, NULL);
1000
1001 return rc;
1002}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program
Definition: globals.c:72
void mutt_sig_empty_handler(int sig)
Dummy signal handler.
Definition: signal.c:57
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:305
void imap_keepalive(void)
Poll the current folder to keep the connection alive.
Definition: util.c:937
+ 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 1008 of file util.c.

1009{
1011 struct ImapMboxData *mdata = imap_mdata_get(m);
1012 if (!adata || !adata->mailbox || (adata->mailbox != m) || !mdata)
1013 return;
1014 mdata->reopen |= IMAP_REOPEN_ALLOW;
1015}
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
Definition: adata.c:89
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
Definition: mdata.c:60
#define IMAP_REOPEN_ALLOW
Allow re-opening a folder upon expunge.
Definition: private.h:66
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 1021 of file util.c.

1022{
1024 struct ImapMboxData *mdata = imap_mdata_get(m);
1025 if (!adata || !adata->mailbox || (adata->mailbox != m) || !mdata)
1026 return;
1027 mdata->reopen &= ~IMAP_REOPEN_ALLOW;
1028}
+ 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 1036 of file util.c.

1037{
1038 if (!a1 || !a2)
1039 return false;
1040 if (a1->type != a2->type)
1041 return false;
1042 if (!mutt_istr_equal(a1->host, a2->host))
1043 return false;
1044 if ((a1->port != 0) && (a2->port != 0) && (a1->port != a2->port))
1045 return false;
1046 if (a1->flags & a2->flags & MUTT_ACCT_USER)
1047 return strcmp(a1->user, a2->user) == 0;
1048
1049 const char *user = NONULL(Username);
1050
1051 const char *const c_imap_user = cs_subset_string(NeoMutt->sub, "imap_user");
1052 if ((a1->type == MUTT_ACCT_TYPE_IMAP) && c_imap_user)
1053 user = c_imap_user;
1054
1055 if (a1->flags & MUTT_ACCT_USER)
1056 return strcmp(a1->user, user) == 0;
1057 if (a2->flags & MUTT_ACCT_USER)
1058 return strcmp(a2->user, user) == 0;
1059
1060 return true;
1061}
#define MUTT_ACCT_USER
User field has been set.
Definition: connaccount.h:44
char * Username
User's login name.
Definition: globals.c:41
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 1068 of file util.c.

1069{
1070 if (!seqset || (*seqset == '\0'))
1071 return NULL;
1072
1073 struct SeqsetIterator *iter = mutt_mem_calloc(1, sizeof(struct SeqsetIterator));
1074 iter->full_seqset = mutt_str_dup(seqset);
1075 iter->eostr = strchr(iter->full_seqset, '\0');
1076 iter->substr_cur = iter->substr_end = iter->full_seqset;
1077
1078 return iter;
1079}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
UID Sequence Set Iterator.
Definition: private.h:170
char * eostr
Definition: private.h:172
char * substr_end
Definition: private.h:178
char * substr_cur
Definition: private.h:177
char * full_seqset
Definition: private.h:171
+ 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 1089 of file util.c.

1090{
1091 if (!iter || !next)
1092 return -1;
1093
1094 if (iter->in_range)
1095 {
1096 if ((iter->down && (iter->range_cur == (iter->range_end - 1))) ||
1097 (!iter->down && (iter->range_cur == (iter->range_end + 1))))
1098 {
1099 iter->in_range = 0;
1100 }
1101 }
1102
1103 if (!iter->in_range)
1104 {
1105 iter->substr_cur = iter->substr_end;
1106 if (iter->substr_cur == iter->eostr)
1107 return 1;
1108
1109 iter->substr_end = strchr(iter->substr_cur, ',');
1110 if (!iter->substr_end)
1111 iter->substr_end = iter->eostr;
1112 else
1113 *(iter->substr_end++) = '\0';
1114
1115 char *range_sep = strchr(iter->substr_cur, ':');
1116 if (range_sep)
1117 *range_sep++ = '\0';
1118
1119 if (!mutt_str_atoui_full(iter->substr_cur, &iter->range_cur))
1120 return -1;
1121 if (range_sep)
1122 {
1123 if (!mutt_str_atoui_full(range_sep, &iter->range_end))
1124 return -1;
1125 }
1126 else
1127 iter->range_end = iter->range_cur;
1128
1129 iter->down = (iter->range_end < iter->range_cur);
1130 iter->in_range = 1;
1131 }
1132
1133 *next = iter->range_cur;
1134 if (iter->down)
1135 iter->range_cur--;
1136 else
1137 iter->range_cur++;
1138
1139 return 0;
1140}
unsigned int range_end
Definition: private.h:176
unsigned int range_cur
Definition: private.h:175
+ 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 1146 of file util.c.

1147{
1148 if (!ptr || !*ptr)
1149 return;
1150
1151 struct SeqsetIterator *iter = *ptr;
1152 FREE(&iter->full_seqset);
1153 FREE(ptr);
1154}
+ Here is the caller graph for this function: