69#define HC_FNAME "neomutt"
70#define HC_FEXT "hcache"
83 static char clean[128];
103 if (fputc(
'\n', fp) == EOF)
129 char buf[1024] = { 0 };
133 snprintf(buf,
sizeof(buf),
"LIST %d\r\n",
edata->refno);
134 int rc =
pop_query(adata, buf,
sizeof(buf));
137 sscanf(buf,
"+OK %d %zu", &
index, &length);
139 snprintf(buf,
sizeof(buf),
"TOP %d 0\r\n",
edata->refno);
157 _(
"Command TOP is not supported by server"));
173 if (!fgets(buf,
sizeof(buf), fp))
185 mutt_error(
_(
"Can't write header to temporary file"));
208 int index = strtol(line, &endp, 10);
216 if (strlen(line) == 0)
302 if (!adata || !adata->
conn)
303 return hcache_open(c_header_cache, path, NULL,
true);
305 struct Url url = { 0 };
306 char p[1024] = { 0 };
329 struct Progress *progress = NULL;
358 if ((rc == -2) && (adata->
cmd_uidl == 2))
364 _(
"Command UIDL is not supported by server"));
377 for (i = 0,
deleted = 0; i < old_count; i++)
380 if (
edata->refno == -1)
388 mutt_error(ngettext(
"%d message has been lost. Try reopening the mailbox.",
389 "%d messages have been lost. Try reopening the mailbox.",
deleted),
393 bool hcached =
false;
394 for (i = old_count; i < new_count; i++)
472 for (
int i = m->
msg_count; i < new_count; i++)
481 if (c_message_cache_clean)
485 return new_count - old_count;
521 char buf[1024] = { 0 };
522 char msgbuf[128] = { 0 };
523 int last = 0, msgs = 0, bytes = 0, rset = 0, rc;
530 strcpy(url,
"pop://");
531 p = strchr(url,
'\0');
533 strcpy(p, c_pop_host);
539 mutt_error(
_(
"%s is an invalid POP path"), c_pop_host);
569 sscanf(buf,
"+OK %d %d", &msgs, &bytes);
573 if ((msgs > 0) && c_pop_last)
580 sscanf(buf,
"+OK %d", &last);
597 bool old_append = m_spool->
append;
603 snprintf(msgbuf,
sizeof(msgbuf),
604 ngettext(
"Reading new messages (%d byte)...",
605 "Reading new messages (%d bytes)...", bytes),
609 for (
int i = last + 1; i <= msgs; i++)
614 snprintf(buf,
sizeof(buf),
"RETR %d\r\n", i);
632 if ((rc == 0) && (delanswer ==
MUTT_YES))
635 snprintf(buf,
sizeof(buf),
"DELE %d\r\n", i);
641 m_spool->
append = old_append;
659 "%s [%d of %d messages read]", msgs - last),
660 msgbuf, i - last, msgs - last);
663 m_spool->
append = old_append;
670 if (
pop_query(adata, buf,
sizeof(buf)) == -1)
677 if (
pop_query(adata, buf,
sizeof(buf)) == -1)
747 struct Url url = { 0 };
862 char buf[1024] = { 0 };
886 struct Progress *progress = NULL;
893 for (i = 0, j = 0, rc = 0; (rc == 0) && (i < m->msg_count); i++)
900 snprintf(buf,
sizeof(buf),
"DELE %d\r\n",
edata->refno);
964 adata->clear_cache =
true;
977 char buf[1024] = { 0 };
981 bool success =
false;
982 struct Buffer *path = NULL;
1008 unlink(cache->
path);
1021 if (edata->
refno < 0)
1023 mutt_error(
_(
"The message index is incorrect. Try reopening the mailbox."));
1042 snprintf(buf,
sizeof(buf),
"RETR %d\r\n", edata->
refno);
1069 mutt_error(
_(
"Can't write message to temporary file"));
1105 while (fgets(buf,
sizeof(buf), msg->
fp) && !feof(msg->
fp))
1186 .mbox_open_append = NULL,
1188 .mbox_check_stats = NULL,
1192 .msg_open_new = NULL,
1195 .msg_padding_size = NULL,
1198 .tags_commit = NULL,
1201 .path_is_empty = NULL,
Body Caching (local copies of email bodies)
int mutt_bcache_exists(struct BodyCache *bcache, const char *id)
Check if a file exists in the Body Cache.
int mutt_bcache_commit(struct BodyCache *bcache, const char *id)
Move a temporary file into the Body Cache.
struct BodyCache * mutt_bcache_open(struct ConnAccount *account, const char *mailbox)
Open an Email-Body Cache.
int mutt_bcache_list(struct BodyCache *bcache, bcache_list_t want_id, void *data)
Find matching entries in the Body Cache.
FILE * mutt_bcache_get(struct BodyCache *bcache, const char *id)
Open a file in the Body Cache.
void mutt_bcache_close(struct BodyCache **ptr)
Close an Email-Body Cache.
int mutt_bcache_del(struct BodyCache *bcache, const char *id)
Delete a file from the Body Cache.
FILE * mutt_bcache_put(struct BodyCache *bcache, const char *id)
Create a file in the Body Cache.
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
char * buf_strdup(const struct Buffer *buf)
Copy a Buffer's string.
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.
Convenience wrapper for the core headers.
void mailbox_free(struct Mailbox **ptr)
Free a Mailbox.
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
@ NT_MAILBOX_INVALID
Email list was changed.
#define MUTT_ACL_DELETE
Delete a message.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
#define MUTT_ACL_WRITE
Write to a message (for flagging or linking threads)
MailboxType
Supported mailbox formats.
@ MUTT_POP
'POP3' Mailbox type
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
#define MUTT_ACL_SEEN
Change the 'seen' status of a message.
SecurityFlags crypt_query(struct Body *b)
Check out the type of encryption used.
struct Email * email_new(void)
Create a new Email.
void email_free(struct Email **ptr)
Free an Email.
Structs that make up an email.
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
Parses an RFC822 header.
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
void mutt_file_sanitize_filename(char *path, bool slash)
Replace unsafe characters in a filename.
#define mutt_file_fclose(FP)
#define mutt_file_fopen(PATH, MODE)
void pop_adata_free(void **ptr)
Free the private Account data - Implements Account::adata_free() -.
static int pop_bcache_delete(const char *id, struct BodyCache *bcache, void *data)
Delete an entry from the message cache - Implements bcache_list_t -.
void pop_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free() -.
static void pop_hcache_namer(const char *path, struct Buffer *dest)
Create a header cache filename for a POP mailbox - Implements hcache_namer_t -.
#define mutt_message(...)
#define mutt_debug(LEVEL,...)
static bool pop_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Implements MxOps::ac_add() -.
static bool pop_ac_owns_path(struct Account *a, const char *path)
Check whether an Account owns a Mailbox path - Implements MxOps::ac_owns_path() -.
const struct MxOps MxPopOps
POP Mailbox - Implements MxOps -.
static enum MxStatus pop_mbox_check(struct Mailbox *m)
Check for new mail - Implements MxOps::mbox_check() -.
static enum MxStatus pop_mbox_close(struct Mailbox *m)
Close a Mailbox - Implements MxOps::mbox_close() -.
static enum MxOpenReturns pop_mbox_open(struct Mailbox *m)
Open a Mailbox - Implements MxOps::mbox_open() -.
static enum MxStatus pop_mbox_sync(struct Mailbox *m)
Save changes to the Mailbox - Implements MxOps::mbox_sync() -.
static int pop_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close() -.
static bool pop_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e)
Open an email message in a Mailbox - Implements MxOps::msg_open() -.
static int pop_msg_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Implements MxOps::msg_save_hcache() -.
static int pop_path_canon(struct Buffer *path)
Canonicalise a Mailbox path - Implements MxOps::path_canon() -.
enum MailboxType pop_path_probe(const char *path, const struct stat *st)
Is this a POP Mailbox? - Implements MxOps::path_probe() -.
static int fetch_message(const char *line, void *data)
Parse a Message response - Implements pop_fetch_t -.
static int fetch_uidl(const char *line, void *data)
Parse UIDL response - Implements pop_fetch_t -.
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
void mutt_hash_delete(struct HashTable *table, const char *strkey, const void *data)
Remove an element from 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.
Header cache multiplexor.
void mutt_account_hook(const char *url)
Perform an account hook.
Parse and execute user-defined hooks.
@ LL_DEBUG1
Log at debug level 1.
#define MUTT_MEM_CALLOC(n, type)
time_t mutt_date_now(void)
Return the number of seconds since the Unix epoch.
Convenience wrapper for the library headers.
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.
size_t mutt_str_copy(char *dest, const char *src, size_t dsize)
Copy a string into a buffer (guaranteeing NUL-termination)
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
void account_to_url(struct ConnAccount *cac, struct Url *url)
Fill URL with info from account.
void mutt_clear_error(void)
Clear the message line (bottom line of screen)
struct Connection * mutt_conn_new(const struct ConnAccount *cac)
Create a new Connection.
struct Connection * mutt_conn_find(const struct ConnAccount *cac)
Find a connection from a list.
void mx_alloc_memory(struct Mailbox *m, int req_size)
Create storage for the emails.
int mx_msg_close(struct Mailbox *m, struct Message **ptr)
Close a message.
bool mx_mbox_open(struct Mailbox *m, OpenMailboxFlags flags)
Open a mailbox and parse it.
struct Message * mx_msg_open_new(struct Mailbox *m, const struct Email *e, MsgOpenFlags flags)
Open a new message.
int mx_msg_commit(struct Mailbox *m, struct Message *msg)
Commit a message to a folder - Wrapper for MxOps::msg_commit()
struct Mailbox * mx_path_resolve(const char *path)
Get a Mailbox for a path.
enum MxStatus mx_mbox_close(struct Mailbox *m)
Save changes and close mailbox.
#define MUTT_ADD_FROM
add a From_ line
MxOpenReturns
Return values for mbox_open()
@ MX_OPEN_ERROR
Open failed with an error.
@ MX_OPEN_OK
Open succeeded.
#define MUTT_OPEN_NO_FLAGS
No flags are set.
MxStatus
Return values from mbox_check(), mbox_check_stats(), mbox_sync(), and mbox_close()
@ MX_STATUS_ERROR
An error occurred.
@ MX_STATUS_OK
No changes.
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
API for encryption/signing of emails.
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.
struct PopAccountData * pop_adata_get(struct Mailbox *m)
Get the Account data for this mailbox.
struct PopAccountData * pop_adata_new(void)
Create a new PopAccountData object.
Pop-specific Account data.
struct PopEmailData * pop_edata_new(const char *uid)
Create a new PopEmailData for an email.
struct PopEmailData * pop_edata_get(struct Email *e)
Get the private data for this Email.
int pop_open_connection(struct PopAccountData *adata)
Open connection and authenticate.
int pop_parse_path(const char *path, struct ConnAccount *cac)
Parse a POP mailbox name.
int pop_fetch_data(struct PopAccountData *adata, const char *query, struct Progress *progress, pop_fetch_t callback, void *data)
Read Headers with callback function.
void pop_logout(struct Mailbox *m)
Logout from a POP server.
int pop_reconnect(struct Mailbox *m)
Reconnect and verify indexes if connection was lost.
#define pop_query(adata, buf, buflen)
@ POP_DISCONNECTED
Disconnected from server.
@ POP_NONE
No connected to server.
static void pop_clear_cache(struct PopAccountData *adata)
Delete all cached messages.
static const char * cache_id(const char *id)
Make a message-cache-compatible id.
static struct HeaderCache * pop_hcache_open(struct PopAccountData *adata, const char *path)
Open the header cache.
static int pop_read_header(struct PopAccountData *adata, struct Email *e)
Read header.
void pop_fetch_mail(void)
Fetch messages and save them in $spool_file.
static int pop_fetch_headers(struct Mailbox *m)
Read headers.
@ MUTT_PROGRESS_NET
Progress tracks bytes, according to $net_inc
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
@ MUTT_PROGRESS_WRITE
Progress tracks elements, according to $write_inc
struct Progress * progress_new(enum ProgressType type, size_t size)
Create a new Progress Bar.
void progress_free(struct Progress **ptr)
Free a Progress Bar.
void progress_set_message(struct Progress *progress, const char *fmt,...) __attribute__((__format__(__printf__
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
QuadOption
Possible values for a quad-option.
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
enum QuadOption query_quadoption(const char *prompt, struct ConfigSubset *sub, const char *name)
Ask the user a quad-question.
int mutt_socket_close(struct Connection *conn)
Close a socket.
A group of associated Mailboxes.
void(* adata_free)(void **ptr)
void * adata
Private data (for Mailbox backends)
Local cache of email bodies.
LOFF_T offset
offset where the actual data begins
LOFF_T length
length (in bytes) of attachment
String manipulation buffer.
Login details for a remote server.
char host[128]
Server to login to.
struct ConnAccount account
Account details: username, password, etc.
int fd
Socket file descriptor.
The envelope/body of an email.
struct Envelope * env
Envelope information.
void * edata
Driver-specific data.
int lines
How many lines in the body of this message?
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
struct Body * body
List of MIME parts.
bool old
Email is seen, but unread.
void(* edata_free)(void **ptr)
bool changed
Email has been edited.
char * path
Path of Email (for local Mailboxes)
bool deleted
Email is deleted.
int index
The absolute (unsorted) message number.
char *const real_subj
Offset of the real subject.
Wrapper for Email retrieved from the header cache.
struct Email * email
Retrieved email.
char * realpath
Used for duplicate detection, context comparison, and the sidebar.
bool append
Mailbox is opened in append mode.
int msg_count
Total number of messages.
AclFlags rights
ACL bits, see AclFlags.
struct HashTable * subj_hash
Hash Table: "subject" -> Email.
struct Email ** emails
Array of Emails.
struct Buffer pathbuf
Path of the Mailbox.
struct Account * account
Account that owns this Mailbox.
off_t size
Size of the Mailbox.
bool verbose
Display status messages?
A local copy of an email.
FILE * fp
pointer to the message data
char * path
path to temp file
enum MailboxType type
Mailbox type, e.g. MUTT_IMAP.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.
POP-specific Account data -.
unsigned int cmd_top
optional command TOP
char err_msg[POP_CMD_RESPONSE]
struct Connection * conn
Connection to POP server.
struct PopCache cache[POP_CACHE_LEN]
struct BodyCache * bcache
body cache
unsigned int cmd_uidl
optional command UIDL
POP-specific email cache.
POP-specific Email data -.
int refno
Message number on server.
const char * uid
UID of email.
A parsed URL proto://user:password@host:port/path?a=1&b=2
#define mutt_file_mkstemp()
struct Url * url_parse(const char *src)
Fill in Url.
void url_free(struct Url **ptr)
Free the contents of a URL.
enum UrlScheme url_check_scheme(const char *str)
Check the protocol 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.
@ U_UNKNOWN
Url wasn't recognised.