76 char tmp[1024] = { 0 };
87 tmp_adata = np->
adata;
139 for (n--; (n >= 0) && (buf[n] != delim); n--)
150 buf[0] = (n == 0) ? delim :
'\0';
167 char mbox[1024] = { 0 };
235 int first = 1, state = 0;
236 unsigned int cur_uid = 0, last_uid = 0;
237 unsigned int range_begin = 0, range_end = 0;
240 for (
unsigned int msn = 1; msn <= max_msn + 1; msn++)
247 if (!state || (cur_uid && ((cur_uid - 1) == last_uid)))
265 range_begin = cur_uid;
282 range_begin = cur_uid;
303 if (!adata || !mdata)
324 struct Url url = { 0 };
362 char key[16] = { 0 };
364 snprintf(key,
sizeof(key),
"%u", uid);
387 char key[16] = { 0 };
405 char key[16] = { 0 };
407 snprintf(key,
sizeof(key),
"%u", uid);
478 static unsigned short ImapPort = 0;
479 static unsigned short ImapsPort = 0;
483 struct servent *service = getservbyname(
"imap",
"tcp");
485 ImapPort = ntohs(service->s_port);
493 struct servent *service = getservbyname(
"imaps",
"tcp");
495 ImapsPort = ntohs(service->s_port);
502 cac->
port = ImapPort;
531 cac->
port = ImapsPort;
553 if (!mx1 || (*mx1 ==
'\0'))
555 if (!mx2 || (*mx2 ==
'\0'))
587 struct Url url = { 0 };
588 const char *delim = NULL;
591 bool home_match =
false;
592 char target_mailbox[1024] = { 0 };
593 char home_mailbox[1024] = { 0 };
601 if (
imap_parse_path(folder, &cac_home, home_mailbox,
sizeof(home_mailbox)) < 0)
616 else if (c_imap_delim_chars)
618 for (delim = c_imap_delim_chars; *delim !=
'\0'; delim++)
619 if (target_mailbox[hlen] == *delim)
631 memcpy(
path, target_mailbox + hlen, tlen - hlen);
632 path[tlen - hlen] =
'\0';
638 url.
path = target_mailbox;
685 size_t space_left = plen - 1;
689 for (
const char *c = mailbox; *c && space_left; c++, space_left--)
691 if (strchr(
NONULL(c_imap_delim_chars), *c))
715 size_t space_left = plen - 1;
719 for (
const char *c = mailbox; *c && space_left; c++, space_left--)
721 if (*c == delim || *c ==
'/')
723 while (*c && *(c + 1) == *c)
734 if (out !=
path && *(out - 1) == delim)
750 const char *p = mailbox;
761 if ((p[1] >=
'0') && (p[1] <=
'9'))
784 if (!buf || !(pc = strchr(buf,
'{')))
856 struct Url url = { 0 };
870 struct Url url = { 0 };
887 const char *quote =
"`\"\\";
898 for (; *s && dlen; s++)
900 if (strchr(quote, *s))
984 strncpy(s, buf, strlen(s));
1019 struct sigaction oldalrm = { 0 };
1020 struct sigaction act = { 0 };
1021 sigset_t oldmask = { 0 };
1028 sigprocmask(SIG_SETMASK, NULL, &oldmask);
1030 sigemptyset(&act.sa_mask);
1033 act.sa_flags = SA_INTERRUPT;
1038 sigaction(SIGALRM, &act, &oldalrm);
1041 alarm(c_imap_keep_alive);
1042 while ((waitpid(pid, &rc, 0) < 0) && (errno == EINTR))
1046 alarm(c_imap_keep_alive);
1051 sigaction(SIGALRM, &oldalrm, NULL);
1052 sigprocmask(SIG_SETMASK, &oldmask, NULL);
1083 mdata->reopen &= ~IMAP_REOPEN_ALLOW;
1126 if (!seqset || (*seqset ==
'\0'))
1171 char *range_sep = strchr(iter->
substr_cur,
':');
1173 *range_sep++ =
'\0';
1179 if (!mutt_str_atoui_full(range_sep, &iter->
range_end))
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
Body Caching (local copies of email bodies)
void mutt_bcache_close(struct BodyCache **ptr)
Close an Email-Body Cache.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
int buf_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
size_t buf_len(const struct Buffer *buf)
Calculate the length of a Buffer.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
void buf_alloc(struct Buffer *buf, size_t new_size)
Make sure a buffer can store at least new_size bytes.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
const char * cs_subset_string(const struct ConfigSubset *sub, const char *name)
Get a string config item by name.
short cs_subset_number(const struct ConfigSubset *sub, const char *name)
Get a number config item by name.
const char * cs_subset_path(const struct ConfigSubset *sub, const char *name)
Get a path config item by name.
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Convenience wrapper for the config headers.
ConnAccountField
Login credentials.
@ MUTT_CA_OAUTH_CMD
OAuth refresh command.
@ MUTT_CA_LOGIN
Login name.
@ MUTT_CA_HOST
Server name.
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
#define MUTT_ACCT_USER
User field has been set.
#define MUTT_ACCT_PORT
Port field has been set.
Convenience wrapper for the core headers.
@ MUTT_IMAP
'IMAP' Mailbox type
bool mutt_isspace(int arg)
Wrapper for isspace(3)
bool mutt_isdigit(int arg)
Wrapper for isdigit(3)
Structs that make up an email.
bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program
static const char * imap_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field() -.
static void imap_hcache_namer(const char *path, struct Buffer *dest)
Generate a filename for the header cache - Implements hcache_namer_t -.
#define mutt_debug(LEVEL,...)
void imap_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free() -.
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe() -.
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer, bool create)
Multiplexor for StoreOps::open.
int hcache_delete_email(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
struct HCacheEntry hcache_fetch_email(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
int hcache_store_email(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
char * hcache_fetch_raw_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
int hcache_delete_raw(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
int hcache_store_raw(struct HeaderCache *hc, const char *key, size_t keylen, void *data, size_t dlen)
Store a key / data pair.
Header cache multiplexor.
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
struct ImapMboxData * imap_mdata_new(struct ImapAccountData *adata, const char *name)
Allocate and initialise a new ImapMboxData structure.
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
#define IMAP_PORT
Default port for IMAP.
@ IMAP_AUTHENTICATED
Connection is authenticated.
#define IMAP_REOPEN_ALLOW
Allow re-opening a folder upon expunge.
void imap_utf_encode(bool unicode, char **s)
Encode email from local charset to UTF-8.
#define IMAP_SSL_PORT
Port for IMAP over SSL/TLS.
void imap_utf_decode(bool unicode, char **s)
Decode email from UTF-8 to local charset.
enum MxStatus imap_check_mailbox(struct Mailbox *m, bool force)
Use the NOOP or IDLE command to poll for new mail.
@ LL_DEBUG3
Log at debug level 3.
#define MUTT_MEM_CALLOC(n, type)
#define MUTT_MEM_MALLOC(n, type)
void imap_msn_free(struct MSNArray *msn)
Free the cache.
struct Email * imap_msn_get(const struct MSNArray *msn, int idx)
Return the Email associated with an msn.
size_t imap_msn_highest(const struct MSNArray *msn)
Return the highest MSN in use.
IMAP MSN helper functions.
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Convenience wrapper for the library headers.
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
char * mutt_str_dup(const char *str)
Copy a string, safely.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
void account_to_url(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
int account_from_url(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
@ MUTT_ACCT_TYPE_IMAP
Imap Account.
Notmuch-specific Mailbox data.
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Pop-specific Account data.
QuadOption
Possible values for a quad-option.
@ MUTT_NO
User answered 'No', or assume 'No'.
enum QuadOption query_yesorno(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question.
#define TAILQ_FOREACH(var, head, field)
void mutt_sig_empty_handler(int sig)
Dummy signal handler.
A group of associated Mailboxes.
enum MailboxType type
Type of Mailboxes this Account contains.
void * adata
Private data (for Mailbox backends)
String manipulation buffer.
char * data
Pointer to data.
Login details for a remote server.
const char * service
Name of the service, e.g. "imap".
char host[128]
Server to login to.
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
unsigned short port
Port to connect to.
struct ConnAccount account
Account details: username, password, etc.
The envelope/body of an email.
char * path
Path of Email (for local Mailboxes)
Wrapper for Email retrieved from the header cache.
uint32_t uidvalidity
IMAP-specific UIDVALIDITY.
struct Email * email
Retrieved email.
IMAP-specific Account data -.
char delim
Path delimiter.
struct Mailbox * mailbox
Current selected mailbox.
struct Connection * conn
Connection to IMAP server.
unsigned int uid
32-bit Message UID
IMAP-specific Mailbox data -.
struct HeaderCache * hcache
Email header cache.
struct BodyCache * bcache
Email body cache.
struct HashTable * uid_hash
Hash Table: "uid" -> Email.
void * mdata
Driver specific data.
Container for Accounts, Notifications.
char * username
User's login name.
struct AccountList accounts
List of all Accounts.
struct ConfigSubset * sub
Inherited config items.
UID Sequence Set Iterator.
A parsed URL proto://user:password@host:port/path?a=1&b=2
char * src
Raw URL string.
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
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.
struct Url * url_parse(const char *src)
Fill in Url.
void url_free(struct Url **ptr)
Free the contents of a URL.
int url_tostring(const struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
int url_tobuffer(const struct Url *url, struct Buffer *buf, uint8_t flags)
Output the URL string for a given Url object.
@ U_IMAPS
Url is imaps://.
void imap_unmunge_mbox_name(bool unicode, char *s)
Remove quoting from a mailbox name.
int imap_parse_path(const char *path, struct ConnAccount *cac, char *mailbox, size_t mailboxlen)
Parse an IMAP mailbox name into ConnAccount, name.
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *cac, char *path)
Make an absolute IMAP folder target.
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.
void imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata, bool create)
Open a header cache.
int imap_get_literal_count(const char *buf, unsigned int *bytes)
Write number of bytes in an IMAP literal into bytes.
int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata)
Store a UID Sequence Set in the header cache.
int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e)
Add an entry to the header cache.
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.
struct SeqsetIterator * mutt_seqset_iterator_new(const char *seqset)
Create a new Sequence Set Iterator.
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
Quote string according to IMAP rules.
char * imap_hcache_get_uid_seqset(struct ImapMboxData *mdata)
Get a UID Sequence Set from the header cache.
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_unquote_string(char *s)
Equally stupid unquoting routine.
struct Email * imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid)
Get a header cache entry by its UID.
int imap_wait_keep_alive(pid_t pid)
Wait for a process to change state.
void imap_get_parent_path(const char *path, char *buf, size_t buflen)
Get the path of the parent folder.
int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next)
Get the next UID from a Sequence Set.
void imap_clean_path(char *path, size_t plen)
Cleans an IMAP path using imap_fix_path.
void mutt_seqset_iterator_free(struct SeqsetIterator **ptr)
Free a Sequence Set Iterator.
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.
void imap_cachepath(char delim, const char *mailbox, struct Buffer *dest)
Generate a cache path for a mailbox.
char * imap_fix_path(const char *mailbox, char *path, size_t plen)
Fix up the imap path.
void imap_error(const char *where, const char *msg)
Show an error and abort.
void imap_hcache_close(struct ImapMboxData *mdata)
Close the header cache.
char * imap_fix_path_with_delim(const char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid)
Delete an item from the header cache.
int imap_hcache_clear_uid_seqset(struct ImapMboxData *mdata)
Delete a UID Sequence Set from the header cache.
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src)
Quote awkward characters in a mailbox name.
void imap_keep_alive(void)
Poll the current folder to keep the connection alive.
static void imap_msn_index_to_uid_seqset(struct Buffer *buf, struct ImapMboxData *mdata)
Convert MSN index of UIDs to Seqset.
void imap_buf_qualify_path(struct Buffer *buf, struct ConnAccount *cac, char *path)
Make an absolute IMAP folder target to a buffer.
char * imap_next_word(char *s)
Find where the next IMAP word begins.
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.