77 char tmp[1024] = { 0 };
88 tmp_adata = np->
adata;
140 for (n--; (n >= 0) && (buf[n] != delim); n--)
151 buf[0] = (n == 0) ? delim :
'\0';
168 char mbox[1024] = { 0 };
236 int first = 1, state = 0;
237 unsigned int cur_uid = 0, last_uid = 0;
238 unsigned int range_begin = 0, range_end = 0;
241 for (
unsigned int msn = 1; msn <= max_msn + 1; msn++)
248 if (!state || (cur_uid && ((cur_uid - 1) == last_uid)))
266 range_begin = cur_uid;
283 range_begin = cur_uid;
304 if (!adata || !mdata)
325 struct Url url = { 0 };
363 char key[16] = { 0 };
365 snprintf(key,
sizeof(key),
"%u", uid);
388 char key[16] = { 0 };
406 char key[16] = { 0 };
408 snprintf(key,
sizeof(key),
"%u", uid);
479 static unsigned short ImapPort = 0;
480 static unsigned short ImapsPort = 0;
484 struct servent *service = getservbyname(
"imap",
"tcp");
486 ImapPort = ntohs(service->s_port);
494 struct servent *service = getservbyname(
"imaps",
"tcp");
496 ImapsPort = ntohs(service->s_port);
503 cac->
port = ImapPort;
532 cac->
port = ImapsPort;
554 if (!mx1 || (*mx1 ==
'\0'))
556 if (!mx2 || (*mx2 ==
'\0'))
588 struct Url url = { 0 };
589 const char *delim = NULL;
592 bool home_match =
false;
593 char target_mailbox[1024] = { 0 };
594 char home_mailbox[1024] = { 0 };
602 if (
imap_parse_path(folder, &cac_home, home_mailbox,
sizeof(home_mailbox)) < 0)
617 else if (c_imap_delim_chars)
619 for (delim = c_imap_delim_chars; *delim !=
'\0'; delim++)
620 if (target_mailbox[hlen] == *delim)
632 memcpy(
path, target_mailbox + hlen, tlen - hlen);
633 path[tlen - hlen] =
'\0';
639 url.
path = target_mailbox;
686 size_t space_left = plen - 1;
690 for (
const char *c = mailbox; *c && space_left; ++c, --space_left)
692 if (strchr(
NONULL(c_imap_delim_chars), *c))
716 size_t space_left = plen - 1;
720 for (
const char *c = mailbox; *c && space_left; ++c, --space_left)
722 if (*c == delim || *c ==
'/')
724 while (*c && *(c + 1) == *c)
735 if (out !=
path && *(out - 1) == delim)
751 const char *p = mailbox;
762 if ((p[1] >=
'0') && (p[1] <=
'9'))
785 if (!buf || !(pc = strchr(buf,
'{')))
790 while (isdigit((
unsigned char) *pc))
839 if (!quoted && isspace(*s))
857 struct Url url = { 0 };
871 struct Url url = { 0 };
888 const char *quote =
"`\"\\";
899 for (; *s && dlen; s++)
901 if (strchr(quote, *s))
985 strncpy(s, buf, strlen(s));
1020 struct sigaction oldalrm = { 0 };
1021 struct sigaction act = { 0 };
1022 sigset_t oldmask = { 0 };
1029 sigprocmask(SIG_SETMASK, NULL, &oldmask);
1031 sigemptyset(&act.sa_mask);
1034 act.sa_flags = SA_INTERRUPT;
1039 sigaction(SIGALRM, &act, &oldalrm);
1042 alarm(c_imap_keep_alive);
1043 while ((waitpid(pid, &rc, 0) < 0) && (errno == EINTR))
1047 alarm(c_imap_keep_alive);
1052 sigaction(SIGALRM, &oldalrm, NULL);
1053 sigprocmask(SIG_SETMASK, &oldmask, NULL);
1084 mdata->reopen &= ~IMAP_REOPEN_ALLOW;
1127 if (!seqset || (*seqset ==
'\0'))
1172 char *range_sep = strchr(iter->
substr_cur,
':');
1174 *range_sep++ =
'\0';
1180 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
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.
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.
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)
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.
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.