Go to the documentation of this file.
36 #include <netinet/in.h>
90 tmp_adata = np->
adata;
139 for (n--; (n >= 0) && (buf[n] != delim); n--)
150 buf[0] = (n == 0) ? delim :
'\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)))
264 range_begin = cur_uid;
281 range_begin = cur_uid;
301 if (!adata || !mdata)
323 struct Url url = { 0 };
363 sprintf(key,
"/%u", uid);
406 sprintf(key,
"/%u", uid);
485 static unsigned short ImapPort = 0;
486 static unsigned short ImapsPort = 0;
490 struct servent *service = getservbyname(
"imap",
"tcp");
492 ImapPort = ntohs(service->s_port);
500 struct servent *service = getservbyname(
"imaps",
"tcp");
502 ImapsPort = ntohs(service->s_port);
509 cac->
port = ImapPort;
538 cac->
port = ImapsPort;
560 if (!mx1 || (*mx1 ==
'\0'))
562 if (!mx2 || (*mx2 ==
'\0'))
594 struct Url url = { 0 };
598 bool home_match =
false;
599 char target_mailbox[1024];
600 char home_mailbox[1024];
608 if (
imap_parse_path(folder, &cac_home, home_mailbox,
sizeof(home_mailbox)) < 0)
623 if (target_mailbox[hlen] == *delim)
635 memcpy(
path, target_mailbox + hlen + 1, tlen - hlen - 1);
636 path[tlen - hlen - 1] =
'\0';
642 url.
path = target_mailbox;
688 for (; mailbox && *mailbox && (i <
plen - 1); i++)
694 while (*mailbox && *(mailbox + 1) == delim)
697 path[i] = *mailbox++;
701 if (i &&
path[i - 1] == delim)
717 const char *p = mailbox;
728 if ((p[1] >=
'0') && (p[1] <=
'9'))
749 if (!buf || !(pc = strchr(buf,
'{')))
754 while (isdigit((
unsigned char) *pc))
821 struct Url url = { 0 };
838 const char *quote =
"`\"\\";
849 for (; *s && dlen; s++)
851 if (strchr(quote, *s))
935 strncpy(s, buf, strlen(s));
969 struct sigaction oldalrm;
970 struct sigaction act;
979 sigprocmask(SIG_SETMASK, NULL, &oldmask);
981 sigemptyset(&act.sa_mask);
984 act.sa_flags = SA_INTERRUPT;
989 sigaction(SIGALRM, &act, &oldalrm);
992 while ((waitpid(pid, &rc, 0) < 0) && (errno == EINTR))
1001 sigaction(SIGALRM, &oldalrm, NULL);
1002 sigprocmask(SIG_SETMASK, &oldmask, NULL);
1054 return strcmp(a1->
user, a2->
user) == 0;
1062 return strcmp(a1->
user, user) == 0;
1064 return strcmp(a2->
user, user) == 0;
1076 if (!seqset || (*seqset ==
'\0'))
1123 char *range_sep = strchr(iter->
substr_cur,
':');
1125 *range_sep++ =
'\0';
char * src
Raw URL string.
struct HeaderCache * hcache
void imap_utf_decode(bool unicode, char **s)
Decode email from UTF-8 to local charset.
char * C_ImapDelimChars
Config: (imap) Characters that denote separators in IMAP folders.
Login details for a remote server.
char * imap_hcache_get_uid_seqset(struct ImapMboxData *mdata)
Get a UID Sequence Set from the header cache.
short C_ImapKeepalive
Config: (imap) Time to wait before polling an open IMAP connection.
struct HeaderCache * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
void imap_mdata_cache_reset(struct ImapMboxData *mdata)
Release and clear cache data of ImapMboxData structure.
void imap_unmunge_mbox_name(bool unicode, char *s)
Remove quoting from a mailbox name.
QuadOption
Possible values for a quad-option.
char host[128]
Server to login to.
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
struct AccountList accounts
List of all Accounts.
int mutt_account_fromurl(struct ConnAccount *cac, const struct Url *url)
Fill ConnAccount with information from url.
int mutt_hcache_store_raw(struct HeaderCache *hc, const char *key, size_t keylen, void *data, size_t dlen)
store a key / data pair
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
void imap_hcache_open(struct ImapAccountData *adata, struct ImapMboxData *mdata)
Open a header cache.
int imap_hcache_del(struct ImapMboxData *mdata, unsigned int uid)
Delete an item from the header cache.
#define MUTT_ACCT_PORT
Port field has been set.
void imap_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
struct HashTable * uid_hash
String manipulation buffer.
enum MailboxType type
Type of Mailboxes this Account contains.
@ LL_DEBUG3
Log at debug level 3.
struct ConnAccount account
Account details: username, password, etc.
const char *(* get_field)(enum ConnAccountField field, void *gf_data)
Function to get some login credentials.
enum QuadOption imap_continue(const char *msg, const char *resp)
display a message and ask the user if they want to go on
void mutt_buffer_dealloc(struct Buffer *buf)
Release the memory allocated by a buffer.
static void imap_msn_index_to_uid_seqset(struct Buffer *buf, struct ImapMboxData *mdata)
Convert MSN index of UIDs to Seqset.
int imap_hcache_clear_uid_seqset(struct ImapMboxData *mdata)
Delete a UID Sequence Set from the header cache.
#define IMAP_SSL_PORT
Port for IMAP over SSL/TLS.
int mutt_buffer_add_printf(struct Buffer *buf, const char *fmt,...)
Format a string appending a Buffer.
int imap_wait_keepalive(pid_t pid)
Wait for a process to change state.
void mutt_account_tourl(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
struct ImapMboxData * imap_mdata_new(struct ImapAccountData *adata, const char *name)
Allocate and initialise a new ImapMboxData structure.
#define IMAP_PORT
Default port for IMAP.
#define TAILQ_FOREACH(var, head, field)
enum UrlScheme scheme
Scheme, e.g. U_SMTPS.
char * mutt_str_dup(const char *str)
Copy a string, safely.
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.
char * imap_next_word(char *s)
Find where the next IMAP word begins.
char * path
Path of Email (for local Mailboxes)
char * C_ImapPass
Config: (imap) Password for the IMAP server.
void mutt_buffer_reset(struct Buffer *buf)
Reset an existing Buffer.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
WHERE char * Username
User's login name.
struct ImapAccountData * imap_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
void mutt_sig_empty_handler(int sig)
Dummy signal handler.
char * C_ImapLogin
Config: (imap) Login name for the IMAP server (defaults to $imap_user)
struct Url * url_parse(const char *src)
Fill in Url.
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
struct SeqsetIterator * mutt_seqset_iterator_new(const char *seqset)
Create a new Sequence Set Iterator.
size_t mutt_buffer_addch(struct Buffer *buf, char c)
Add a single character to a Buffer.
struct Email * imap_hcache_get(struct ImapMboxData *mdata, unsigned int uid)
Get a header cache entry by its UID.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
int imap_adata_find(const char *path, struct ImapAccountData **adata, struct ImapMboxData **mdata)
Find the Account data for this path.
void * mdata
Driver specific data.
int url_tostring(struct Url *url, char *dest, size_t len, uint8_t flags)
Output the URL string for a given Url object.
struct Email * imap_msn_get(const struct MSN *msn, size_t idx)
Return the Email associated with an msn.
void imap_utf_encode(bool unicode, char **s)
Encode email from local charset to UTF-8.
ConnAccountField
Login credentials.
A group of associated Mailboxes.
void imap_error(const char *where, const char *msg)
show an error and abort
int imap_get_literal_count(const char *buf, unsigned int *bytes)
write number of bytes in an IMAP literal into bytes
@ MUTT_CA_HOST
Server name.
A parsed URL proto://user:password@host:port/path?a=1&b=2
@ MUTT_ACCT_TYPE_IMAP
Imap Account.
void url_free(struct Url **ptr)
Free the contents of a URL.
void imap_clean_path(char *path, size_t plen)
Cleans an IMAP path using imap_fix_path.
unsigned int uid
32-bit Message UID
struct BodyCache * bcache
@ U_IMAPS
Url is imaps://.
void mutt_hcache_free_raw(struct HeaderCache *hc, void **data)
Multiplexor for StoreOps::free.
@ MUTT_IMAP
'IMAP' Mailbox type
int url_tobuffer(struct Url *url, struct Buffer *buf, uint8_t flags)
Output the URL string for a given Url object.
struct Email * email
Retrieved email.
unsigned char type
Connection type, e.g. MUTT_ACCT_TYPE_IMAP.
#define mutt_debug(LEVEL,...)
void mutt_bcache_close(struct BodyCache **bcache)
Close an Email-Body Cache.
@ MUTT_NO
User answered 'No', or assume 'No'.
void imap_msn_free(struct MSN *msn)
Free the cache.
Wrapper for Email retrieved from the header cache.
char * C_ImapOauthRefreshCommand
Config: (imap) External command to generate OAUTH refresh token.
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
#define MUTT_ACCT_USER
User field has been set.
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
MuttAccountFlags flags
Which fields are initialised, e.g. MUTT_ACCT_USER.
char * C_ImapUser
Config: (imap) Username for the IMAP server.
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
IMAP-specific Account data -.
void imap_get_parent(const char *mbox, char delim, char *buf, size_t buflen)
Get an IMAP folder's parent.
void mutt_seqset_iterator_free(struct SeqsetIterator **ptr)
Free a Sequence Set Iterator.
IMAP-specific Mailbox data -.
int mutt_hcache_store(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
size_t imap_msn_highest(const struct MSN *msn)
Return the highest MSN in use.
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
void imap_pretty_mailbox(char *path, size_t pathlen, const char *folder)
Prettify an IMAP mailbox name.
@ MUTT_CA_LOGIN
Login name.
#define MUTT_ACCT_SSL
Account uses SSL/TLS.
void imap_keepalive(void)
poll the current folder to keep the connection alive
bool C_ImapPassive
Config: (imap) Reuse an existing IMAP connection to check for new mail.
int mutt_seqset_iterator_next(struct SeqsetIterator *iter, unsigned int *next)
Get the next UID from a Sequence Set.
void imap_qualify_path(char *buf, size_t buflen, struct ConnAccount *cac, char *path)
Make an absolute IMAP folder target.
int imap_hcache_store_uid_seqset(struct ImapMboxData *mdata)
Store a UID Sequence Set in the header cache.
unsigned short port
Port to connect to.
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
char * mutt_strn_dup(const char *begin, size_t len)
Duplicate a sub-string.
void imap_quote_string(char *dest, size_t dlen, const char *src, bool quote_backtick)
quote string according to IMAP rules
Container for Accounts, Notifications.
int mutt_hcache_delete_record(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
struct Mailbox * mailbox
Current selected mailbox.
void imap_unquote_string(char *s)
equally stupid unquoting routine
void imap_cachepath(char delim, const char *mailbox, struct Buffer *dest)
Generate a cache path for a mailbox.
char * C_HeaderCache
Config: (hcache) Directory/file for the header cache database.
enum MailboxType imap_path_probe(const char *path, const struct stat *st)
Is this an IMAP Mailbox? - Implements MxOps::path_probe()
struct ImapMboxData * imap_mdata_get(struct Mailbox *m)
Get the Mailbox data for this mailbox.
size_t mutt_buffer_len(const struct Buffer *buf)
Calculate the length of a Buffer.
void * adata
Private data (for Mailbox backends)
bool imap_account_match(const struct ConnAccount *a1, const struct ConnAccount *a2)
Compare two Accounts.
static size_t plen
Length of cached packet.
WHERE bool OptKeepQuiet
(pseudo) shut up the message and refresh functions while we are executing an external program
@ IMAP_AUTHENTICATED
Connection is authenticated.
const char * service
Name of the service, e.g. "imap".
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.
uint32_t uidvalidity
IMAP-specific UIDVALIDITY.
char * imap_fix_path(char delim, const char *mailbox, char *path, size_t plen)
Fix up the imap path.
int mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
int imap_hcache_put(struct ImapMboxData *mdata, struct Email *e)
Add an entry to the header cache.
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
void imap_hcache_close(struct ImapMboxData *mdata)
Close the header cache.
enum QuadOption mutt_yesorno(const char *msg, enum QuadOption def)
Ask the user a Yes/No question.
char * data
Pointer to data.
The envelope/body of an email.
UID Sequence Set Iterator.
int imap_mxcmp(const char *mx1, const char *mx2)
Compare mailbox names, giving priority to INBOX.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
struct ImapEmailData * imap_edata_get(struct Email *e)
Get the private data for this Email.
static void imap_hcache_namer(const char *path, struct Buffer *dest)
Generate a filename for the header cache - Implements hcache_namer_t.
struct Buffer mutt_buffer_make(size_t size)
Make a new buffer on the stack.
char * imap_get_qualifier(char *buf)
Get the qualifier from a tagged response.
@ MUTT_CA_OAUTH_CMD
OAuth refresh command.
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
enum MxStatus imap_check_mailbox(struct Mailbox *m, bool force)
use the NOOP or IDLE command to poll for new mail
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_get_parent_path(const char *path, char *buf, size_t buflen)
Get the path of the parent folder.
#define IMAP_REOPEN_ALLOW
Allow re-opening a folder upon expunge.
static const char * imap_get_field(enum ConnAccountField field, void *gf_data)
Get connection login credentials - Implements ConnAccount::get_field()
struct HCacheEntry mutt_hcache_fetch(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
void imap_munge_mbox_name(bool unicode, char *dest, size_t dlen, const char *src)
Quote awkward characters in a mailbox name.