76 char tmp[1024] = { 0 };
87 tmp_adata = np->
adata;
136 for (n--; (n >= 0) && (buf[n] != delim); n--)
147 buf[0] = (n == 0) ? delim :
'\0';
164 char mbox[1024] = { 0 };
232 int first = 1, state = 0;
233 unsigned int cur_uid = 0, last_uid = 0;
234 unsigned int range_begin = 0, range_end = 0;
237 for (
unsigned int msn = 1; msn <= max_msn + 1; msn++)
244 if (!state || (cur_uid && ((cur_uid - 1) == last_uid)))
262 range_begin = cur_uid;
279 range_begin = cur_uid;
299 if (!adata || !mdata)
320 struct Url url = { 0 };
358 char key[16] = { 0 };
360 snprintf(key,
sizeof(key),
"/%u", uid);
383 char key[16] = { 0 };
401 char key[16] = { 0 };
403 snprintf(key,
sizeof(key),
"/%u", uid);
474 static unsigned short ImapPort = 0;
475 static unsigned short ImapsPort = 0;
479 struct servent *service = getservbyname(
"imap",
"tcp");
481 ImapPort = ntohs(service->s_port);
489 struct servent *service = getservbyname(
"imaps",
"tcp");
491 ImapsPort = ntohs(service->s_port);
498 cac->
port = ImapPort;
527 cac->
port = ImapsPort;
549 if (!mx1 || (*mx1 ==
'\0'))
551 if (!mx2 || (*mx2 ==
'\0'))
583 struct Url url = { 0 };
584 const char *delim = NULL;
587 bool home_match =
false;
588 char target_mailbox[1024] = { 0 };
589 char home_mailbox[1024] = { 0 };
597 if (
imap_parse_path(folder, &cac_home, home_mailbox,
sizeof(home_mailbox)) < 0)
612 else if (c_imap_delim_chars)
614 for (delim = c_imap_delim_chars; *delim !=
'\0'; delim++)
615 if (target_mailbox[hlen] == *delim)
627 memcpy(
path, target_mailbox + hlen, tlen - hlen);
628 path[tlen - hlen] =
'\0';
634 url.
path = target_mailbox;
681 for (; mailbox && *mailbox && (i < (plen - 1)); i++)
683 if ((*mailbox == delim) || (!delim && strchr(
NONULL(c_imap_delim_chars), *mailbox)))
687 while (*mailbox && *(mailbox + 1) == delim)
690 path[i] = *mailbox++;
694 if ((i != 0) && (
path[i - 1] == delim))
710 const char *p = mailbox;
721 if ((p[1] >=
'0') && (p[1] <=
'9'))
744 if (!buf || !(pc = strchr(buf,
'{')))
749 while (isdigit((
unsigned char) *pc))
798 if (!quoted && isspace(*s))
816 struct Url url = { 0 };
830 struct Url url = { 0 };
847 const char *quote =
"`\"\\";
858 for (; *s && dlen; s++)
860 if (strchr(quote, *s))
944 strncpy(s, buf, strlen(s));
979 struct sigaction oldalrm = { 0 };
980 struct sigaction act = { 0 };
981 sigset_t oldmask = { 0 };
988 sigprocmask(SIG_SETMASK, NULL, &oldmask);
990 sigemptyset(&act.sa_mask);
993 act.sa_flags = SA_INTERRUPT;
998 sigaction(SIGALRM, &act, &oldalrm);
1001 alarm(c_imap_keep_alive);
1002 while ((waitpid(pid, &rc, 0) < 0) && (errno == EINTR))
1006 alarm(c_imap_keep_alive);
1011 sigaction(SIGALRM, &oldalrm, NULL);
1012 sigprocmask(SIG_SETMASK, &oldmask, NULL);
1043 mdata->reopen &= ~IMAP_REOPEN_ALLOW;
1086 if (!seqset || (*seqset ==
'\0'))
1131 char *range_sep = strchr(iter->
substr_cur,
':');
1133 *range_sep++ =
'\0';
1139 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_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
void buf_reset(struct Buffer *buf)
Reset an existing Buffer.
struct Buffer buf_make(size_t size)
Make a new buffer on the stack.
size_t buf_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
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.
Structs that make up an email.
bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program
char * Username
User's login name.
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.
Header cache multiplexor.
int hcache_store(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
struct HCacheEntry hcache_fetch(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
char * hcache_fetch_str(struct HeaderCache *hc, const char *key, size_t keylen)
Fetch a string from the cache.
struct HeaderCache * hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
void hcache_close(struct HeaderCache **ptr)
Multiplexor for StoreOps::close.
int hcache_delete_record(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.
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.
@ 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 MSNArray *msn)
Free the cache.
size_t imap_msn_highest(const struct MSNArray *msn)
Return the highest MSN in use.
struct Email * imap_msn_get(const struct MSNArray *msn, size_t idx)
Return the Email associated with an msn.
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)
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.
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.
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.
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.
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.
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_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_keep_alive(void)
Poll the current folder to keep the connection alive.
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.
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.