77 char tmp[1024] = { 0 };
88 tmp_adata = np->
adata;
137 for (n--; (n >= 0) && (buf[n] != delim); n--)
148 buf[0] = (n == 0) ? delim :
'\0';
165 char mbox[1024] = { 0 };
233 int first = 1, state = 0;
234 unsigned int cur_uid = 0, last_uid = 0;
235 unsigned int range_begin = 0, range_end = 0;
238 for (
unsigned int msn = 1; msn <= max_msn + 1; msn++)
245 if (!state || (cur_uid && ((cur_uid - 1) == last_uid)))
262 range_begin = cur_uid;
279 range_begin = cur_uid;
299 if (!adata || !mdata)
321 struct Url url = { 0 };
360 char key[16] = { 0 };
362 sprintf(key,
"/%u", uid);
385 char key[16] = { 0 };
403 char key[16] = { 0 };
405 sprintf(key,
"/%u", uid);
484 static unsigned short ImapPort = 0;
485 static unsigned short ImapsPort = 0;
489 struct servent *service = getservbyname(
"imap",
"tcp");
491 ImapPort = ntohs(service->s_port);
499 struct servent *service = getservbyname(
"imaps",
"tcp");
501 ImapsPort = ntohs(service->s_port);
508 cac->
port = ImapPort;
537 cac->
port = ImapsPort;
559 if (!mx1 || (*mx1 ==
'\0'))
561 if (!mx2 || (*mx2 ==
'\0'))
593 struct Url url = { 0 };
594 const char *delim = NULL;
597 bool home_match =
false;
598 char target_mailbox[1024] = { 0 };
599 char home_mailbox[1024] = { 0 };
607 if (
imap_parse_path(folder, &cac_home, home_mailbox,
sizeof(home_mailbox)) < 0)
620 else if (c_imap_delim_chars)
622 for (delim = c_imap_delim_chars; *delim !=
'\0'; delim++)
623 if (target_mailbox[hlen] == *delim)
635 memcpy(
path, target_mailbox + hlen, tlen - hlen);
636 path[tlen - hlen] =
'\0';
642 url.
path = target_mailbox;
688 for (; mailbox && *mailbox && (i <
plen - 1); i++)
691 if (*mailbox == delim || (!delim && strchr(
NONULL(c_imap_delim_chars), *mailbox)))
695 while (*mailbox && *(mailbox + 1) == delim)
698 path[i] = *mailbox++;
702 if (i &&
path[i - 1] == delim)
718 const char *p = mailbox;
729 if ((p[1] >=
'0') && (p[1] <=
'9'))
750 if (!buf || !(pc = strchr(buf,
'{')))
755 while (isdigit((
unsigned char) *pc))
822 struct Url url = { 0 };
839 const char *quote =
"`\"\\";
850 for (; *s && dlen; s++)
852 if (strchr(quote, *s))
936 strncpy(s, buf, strlen(s));
971 struct sigaction oldalrm;
972 struct sigaction act;
980 sigprocmask(SIG_SETMASK, NULL, &oldmask);
982 sigemptyset(&act.sa_mask);
985 act.sa_flags = SA_INTERRUPT;
990 sigaction(SIGALRM, &act, &oldalrm);
993 alarm(c_imap_keepalive);
994 while ((waitpid(pid, &rc, 0) < 0) && (errno == EINTR))
998 alarm(c_imap_keepalive);
1003 sigaction(SIGALRM, &oldalrm, NULL);
1004 sigprocmask(SIG_SETMASK, &oldmask, NULL);
1035 mdata->reopen &= ~IMAP_REOPEN_ALLOW;
1055 return strcmp(a1->
user, a2->
user) == 0;
1064 return strcmp(a1->
user, user) == 0;
1066 return strcmp(a2->
user, user) == 0;
1078 if (!seqset || (*seqset ==
'\0'))
1123 char *range_sep = strchr(iter->
substr_cur,
':');
1125 *range_sep++ =
'\0';
1131 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 **bcache)
Close an Email-Body Cache.
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
static const char * mutt_buffer_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.
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
Structs that make up an email.
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,...)
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.
Header cache multiplexor.
int mutt_hcache_store(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
void * mutt_hcache_fetch_raw(struct HeaderCache *hc, const char *key, size_t keylen, size_t *dlen)
Fetch a message's header from the cache.
struct HeaderCache * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
int mutt_hcache_delete_record(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
int mutt_hcache_store_raw(struct HeaderCache *hc, const char *key, size_t keylen, void *data, size_t dlen)
Store a key / data pair.
struct HCacheEntry mutt_hcache_fetch(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
void mutt_hcache_free_raw(struct HeaderCache *hc, void **data)
Multiplexor for StoreOps::free.
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.
void imap_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
#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.
@ MUTT_IMAP
'IMAP' Mailbox type
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
void imap_msn_free(struct MSN *msn)
Free the cache.
size_t imap_msn_highest(const struct MSN *msn)
Return the highest MSN in use.
struct Email * imap_msn_get(const struct MSN *msn, size_t idx)
Return the Email associated with an msn.
IMAP MSN helper functions.
Convenience wrapper for the library headers.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
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)
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
ConnAccount object used by POP and IMAP.
@ MUTT_ACCT_TYPE_IMAP
Imap Account.
Hundreds of global variables to back the user variables.
char * Username
User's login name.
Notmuch-specific Mailbox data.
Handling of global boolean variables.
bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program
static size_t plen
Length of cached packet.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
Pop-specific Account data.
QuadOption
Possible values for a quad-option.
@ MUTT_NO
User answered 'No', or assume 'No'.
enum QuadOption mutt_yesorno(const char *msg, 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)
Function to get some login credentials.
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
void * mdata
Driver specific data.
Container for Accounts, Notifications.
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.
int url_tostring(struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
int url_tobuffer(struct Url *url, struct Buffer *buf, uint8_t flags)
Output the URL string for a given Url object.
void url_free(struct Url **ptr)
Free the contents of a URL.
@ 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.
static const char * imap_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field()
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.
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.
int imap_wait_keepalive(pid_t pid)
Wait for a process to change state.
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.
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.
char * imap_fix_path(char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
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.
void imap_keepalive(void)
Poll the current folder to keep the connection alive.
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.
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_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata)
Open a header cache.
static void imap_msn_index_to_uid_seqset(struct Buffer *buf, struct ImapMboxData *mdata)
Convert MSN index of UIDs to Seqset.
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.