77 char tmp[1024] = { 0 };
141 for (n--; (n >= 0) && (buf[n] != delim); n--)
152 buf[0] = (n == 0) ? delim :
'\0';
169 char mbox[1024] = { 0 };
237 int first = 1, state = 0;
238 unsigned int cur_uid = 0, last_uid = 0;
239 unsigned int range_begin = 0, range_end = 0;
242 for (
unsigned int msn = 1; msn <= max_msn + 1; msn++)
249 if (!state || (cur_uid && ((cur_uid - 1) == last_uid)))
267 range_begin = cur_uid;
284 range_begin = cur_uid;
306 if (!adata || !mdata)
327 struct Url url = { 0 };
365 char key[16] = { 0 };
367 snprintf(key,
sizeof(key),
"%u", uid);
390 char key[16] = { 0 };
408 char key[16] = { 0 };
410 snprintf(key,
sizeof(key),
"%u", uid);
481 static unsigned short ImapPort = 0;
482 static unsigned short ImapsPort = 0;
486 struct servent *service = getservbyname(
"imap",
"tcp");
488 ImapPort = ntohs(service->s_port);
496 struct servent *service = getservbyname(
"imaps",
"tcp");
498 ImapsPort = ntohs(service->s_port);
505 cac->
port = ImapPort;
534 cac->
port = ImapsPort;
556 if (!mx1 || (*mx1 ==
'\0'))
558 if (!mx2 || (*mx2 ==
'\0'))
590 struct Url url = { 0 };
591 const char *delim = NULL;
594 bool home_match =
false;
595 char target_mailbox[1024] = { 0 };
596 char home_mailbox[1024] = { 0 };
604 if (
imap_parse_path(folder, &cac_home, home_mailbox,
sizeof(home_mailbox)) < 0)
619 else if (c_imap_delim_chars)
621 for (delim = c_imap_delim_chars; *delim !=
'\0'; delim++)
622 if (target_mailbox[hlen] == *delim)
634 memcpy(
path, target_mailbox + hlen, tlen - hlen);
635 path[tlen - hlen] =
'\0';
641 url.
path = target_mailbox;
688 size_t space_left = plen - 1;
692 for (
const char *c = mailbox; *c && space_left; c++, space_left--)
694 if (strchr(
NONULL(c_imap_delim_chars), *c))
718 size_t space_left = plen - 1;
722 for (
const char *c = mailbox; *c && space_left; c++, space_left--)
724 if (*c == delim || *c ==
'/')
726 while (*c && *(c + 1) == *c)
737 if (out !=
path && *(out - 1) == delim)
753 const char *p = mailbox;
764 if ((p[1] >=
'0') && (p[1] <=
'9'))
787 if (!buf || !(pc = strchr(buf,
'{')))
859 struct Url url = { 0 };
873 struct Url url = { 0 };
890 const char *quote =
"`\"\\";
907 for (; *s && dlen; s++)
909 if (strchr(quote, *s))
993 strncpy(s, buf, strlen(s));
1030 struct sigaction oldalrm = { 0 };
1031 struct sigaction act = { 0 };
1032 sigset_t oldmask = { 0 };
1039 sigprocmask(SIG_SETMASK, NULL, &oldmask);
1041 sigemptyset(&act.sa_mask);
1044 act.sa_flags = SA_INTERRUPT;
1049 sigaction(SIGALRM, &act, &oldalrm);
1052 alarm(c_imap_keep_alive);
1053 while ((waitpid(pid, &rc, 0) < 0) && (errno == EINTR))
1057 alarm(c_imap_keep_alive);
1062 sigaction(SIGALRM, &oldalrm, NULL);
1063 sigprocmask(SIG_SETMASK, &oldmask, NULL);
1137 if (!seqset || (*seqset ==
'\0'))
1182 char *range_sep = strchr(iter->
substr_cur,
':');
1184 *range_sep++ =
'\0';
1190 if (!mutt_str_atoui_full(range_sep, &iter->
range_end))
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
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 struct StoreOps *store_ops, 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?
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.
Imap-specific Account data.
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
Imap-specific Email data.
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.
Imap-specific Mailbox data.
Shared constants/structs that are private to IMAP.
#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 FREE(x)
Free memory and set the pointer to NULL.
#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.
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.
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.
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.
uint32_t uidvalidity
UID validity.
void * mdata
Driver specific data.
Container for Accounts, Notifications.
struct AccountArray accounts
All Accounts.
char * username
User's login name.
struct ConfigSubset * sub
Inherited config items.
UID Sequence Set Iterator.
char * eostr
End of string.
char * substr_end
End of substring.
unsigned int range_end
End of range.
char * substr_cur
Current position in substring.
int in_range
Currently in a range.
char * full_seqset
Full sequence set string.
unsigned int range_cur
Current range value.
const char * name
Store name.
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.
#define U_NO_FLAGS
No flags are set for URL parsing.
@ U_IMAPS
Url is imaps://.
#define U_PATH
Path is included in URL.
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_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_get_literal_count(char *buf, unsigned int *bytes)
Write number of bytes in an IMAP literal into bytes.
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.