86 snprintf(path,
sizeof(path),
"%s/.neomutt-%s-%d-%" PRIu64,
mailbox_path(m),
88 fd = open(path, O_WRONLY | O_EXCL | O_CREAT, 0666);
106 *fp = fdopen(fd,
"w");
129 struct stat st = { 0 };
131 if ((snprintf(path,
sizeof(path),
"%s/%d",
mailbox_path(m), msgno) <
sizeof(path)) &&
132 (stat(path, &st) == 0))
153 if (!isdigit((
unsigned char) *s))
168 struct dirent *de = NULL;
174 while ((de = readdir(dir)))
194 struct dirent *de = NULL;
212 bool check_new =
true;
213 for (
int i = mhs.
max; i > 0; i--)
242 while ((de = readdir(dir)))
244 if (*de->d_name ==
'.')
274 if (!mutt_str_atoi_full(p, &i))
295 struct dirent *de = NULL;
296 char *cp = NULL, *dep = NULL;
297 unsigned int n, hi = 0;
299 char tmp[16] = { 0 };
315 while ((de = readdir(dir)))
323 if (!isdigit((
unsigned char) *cp))
343 snprintf(tmp,
sizeof(tmp),
"%u", hi);
344 snprintf(path,
sizeof(path),
"%s/%s",
mailbox_path(m), tmp);
353 else if (errno != EEXIST)
382 long old_hdr_lines = e->
lines;
429 if ((rc == -1) && restore)
433 e->
lines = old_hdr_lines;
472 struct stat st = { 0 };
475 snprintf(buf,
sizeof(buf),
"%s/.mh_sequences",
mailbox_path(m));
476 if (stat(buf, &st) == 0)
481 if (stat(buf, &st) == 0)
496 struct dirent *de = NULL;
499 struct Email *e = NULL;
511 while (((de = readdir(dir))) && !
SigInt)
551 struct MdEmail const *
const *pa = (
struct MdEmail const *
const *) a;
552 struct MdEmail const *
const *pb = (
struct MdEmail const *
const *) b;
553 return mutt_str_cmp((*pa)->email->path, (*pb)->email->path);
567 FILE *fp = fopen(fname,
"r");
606 struct Progress *progress)
629 struct stat st_lastchanged = { 0 };
632 if (c_maildir_header_cache_verify)
634 rc = stat(fn, &st_lastchanged);
638 size_t keylen = strlen(key);
658 keylen = strlen(key);
692 struct Progress *progress = NULL;
697 snprintf(msg,
sizeof(msg),
_(
"Scanning %s..."),
mailbox_path(m));
720 snprintf(msg,
sizeof(msg),
_(
"Reading %s..."),
mailbox_path(m));
765 const char *key = e->
path;
766 size_t keylen = strlen(key);
780 if (rename(path, tmp) != 0)
796 const char *key = e->
path;
797 size_t keylen = strlen(key);
859 snprintf(tmp,
sizeof(tmp),
"%s/.mh_sequences",
mailbox_path(m));
860 const int i = creat(tmp, S_IRWXU);
885 struct stat st = { 0 };
886 struct stat st_cur = { 0 };
887 bool modified =
false, occult =
false, flags_changed =
false;
898 if (stat(buf, &st) == -1)
902 snprintf(buf,
sizeof(buf),
"%s/.mh_sequences",
mailbox_path(m));
903 int rc = stat(buf, &st_cur);
904 if ((rc == -1) && (errno == ENOENT))
918 if ((rc == -1) && (stat(buf, &st_cur) == -1))
984 flags_changed =
true;
1042 struct Progress *progress = NULL;
1046 snprintf(msg,
sizeof(msg),
_(
"Writing %s..."),
mailbox_path(m));
1079 for (
int i = 0, j = 0; i < m->
msg_count; i++)
1118 msg->
fp = fopen(
path,
"r");
1202 if (!st || !S_ISDIR(st->st_mode))
1207 snprintf(tmp,
sizeof(tmp),
"%s/.mh_sequences",
path);
1208 if (access(tmp, F_OK) == 0)
1211 snprintf(tmp,
sizeof(tmp),
"%s/.xmhcache",
path);
1212 if (access(tmp, F_OK) == 0)
1215 snprintf(tmp,
sizeof(tmp),
"%s/.mew_cache",
path);
1216 if (access(tmp, F_OK) == 0)
1219 snprintf(tmp,
sizeof(tmp),
"%s/.mew-cache",
path);
1220 if (access(tmp, F_OK) == 0)
1223 snprintf(tmp,
sizeof(tmp),
"%s/.sylpheed_cache",
path);
1224 if (access(tmp, F_OK) == 0)
1230 snprintf(tmp,
sizeof(tmp),
"%s/.overview",
path);
1231 if (access(tmp, F_OK) == 0)
1257 .msg_padding_size = NULL,
1260 .tags_commit = NULL,
#define ARRAY_SORT(head, fn)
Sort an array.
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
#define ARRAY_SIZE(head)
The number of elements stored.
#define ARRAY_FREE(head)
Release all memory.
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
const char * mutt_str_atoui(const char *str, unsigned int *dst)
Convert ASCII string to an unsigned integer.
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
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.
short cs_subset_sort(const struct ConfigSubset *sub, const char *name)
Get a sort config item by name.
Convenience wrapper for the config headers.
char * HomeDir
User's home directory.
int mutt_copy_message(FILE *fp_out, struct Email *e, struct Message *msg, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
Duplicate the structure of an entire email.
#define MUTT_CM_UPDATE
Update structs on sync.
#define CH_UPDATE
Update the status and x-status fields?
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
Convenience wrapper for the core headers.
void mutt_body_free(struct Body **ptr)
Free a Body.
bool email_cmp_strict(const struct Email *e1, const struct Email *e2)
Strictly compare message emails.
struct Email * email_new(void)
Create a new Email.
void email_free(struct Email **ptr)
Free an Email.
Structs that make up an email.
void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *st, enum MuttStatType type)
Read the stat() time into a time value.
int mutt_file_safe_rename(const char *src, const char *target)
NFS-safe renaming of files.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
long mutt_file_get_size_fp(FILE *fp)
Get the size of a file.
DIR * mutt_file_opendir(const char *path, enum MuttOpenDirMode mode)
Open a directory.
int mutt_file_stat_timespec_compare(struct stat *st, enum MuttStatType type, struct timespec *b)
Compare stat info with a time value.
int mutt_file_fsync_close(FILE **fp)
Flush the data, before closing a file (and NULL the pointer)
@ MUTT_OPENDIR_NONE
Plain opendir()
@ MUTT_STAT_MTIME
File/dir's mtime - last modified time.
char * ShortHostname
Short version of the hostname.
SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
#define mutt_debug(LEVEL,...)
static bool mh_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Implements MxOps::ac_add() -.
static bool mh_ac_owns_path(struct Account *a, const char *path)
Check whether an Account own a Mailbox path - Implements MxOps::ac_owns_path() -.
const struct MxOps MxMhOps
MH Mailbox - Implements MxOps -.
static enum MxStatus mh_mbox_check_stats(struct Mailbox *m, uint8_t flags)
Check the Mailbox statistics - Implements MxOps::mbox_check_stats() -.
static enum MxStatus mh_mbox_check(struct Mailbox *m)
Check for new mail - Implements MxOps::mbox_check() -.
static enum MxStatus mh_mbox_close(struct Mailbox *m)
Close a Mailbox - Implements MxOps::mbox_close() -.
static bool mh_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending - Implements MxOps::mbox_open_append() -.
static enum MxOpenReturns mh_mbox_open(struct Mailbox *m)
Open a Mailbox - Implements MxOps::mbox_open() -.
static enum MxStatus mh_mbox_sync(struct Mailbox *m)
Save changes to the Mailbox - Implements MxOps::mbox_sync() -.
static int mh_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close() -.
static int mh_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit() -.
static bool mh_msg_open_new(struct Mailbox *m, struct Message *msg, const struct Email *e)
Open a new message in a Mailbox - Implements MxOps::msg_open_new() -.
static bool mh_msg_open(struct Mailbox *m, struct Message *msg, struct Email *e)
Open an email message in a Mailbox - Implements MxOps::msg_open() -.
static int mh_msg_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Implements MxOps::msg_save_hcache() -.
static int mh_path_canon(char *buf, size_t buflen)
Canonicalise a Mailbox path - Implements MxOps::path_canon() -.
static int mh_path_parent(char *buf, size_t buflen)
Find the parent of a Mailbox path - Implements MxOps::path_parent() -.
static int mh_path_pretty(char *buf, size_t buflen, const char *folder)
Abbreviate a Mailbox path - Implements MxOps::path_pretty() -.
static enum MailboxType mh_path_probe(const char *path, const struct stat *st)
Is this an mh Mailbox? - Implements MxOps::path_probe() -.
static int mh_sort_path(const void *a, const void *b)
Compare two Maildirs by path - Implements sort_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_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
#define MUTT_HASH_NO_FLAGS
No flags are set.
Header cache multiplexor.
int mutt_hcache_store(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
struct HeaderCache * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
int mutt_hcache_delete_record(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
struct HCacheEntry mutt_hcache_fetch(struct HeaderCache *hc, const char *key, size_t keylen, uint32_t uidvalidity)
Multiplexor for StoreOps::fetch.
@ LL_DEBUG3
Log at debug level 3.
@ LL_DEBUG2
Log at debug level 2.
@ LL_DEBUG1
Log at debug level 1.
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
@ NT_MAILBOX_RESORT
Email list needs resorting.
@ NT_MAILBOX_INVALID
Email list was changed.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
MailboxType
Supported mailbox formats.
@ MUTT_MH
'MH' Mailbox type
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
void maildir_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free()
struct MaildirEmailData * maildir_edata_new(void)
Create a new MaildirEmailData object.
bool maildir_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
Update the mailbox flags.
void maildir_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
struct MaildirMboxData * maildir_mdata_get(struct Mailbox *m)
Get the private data for this Mailbox.
struct MaildirMboxData * maildir_mdata_new(void)
Create a new MaildirMboxData object.
mode_t mh_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
int maildir_move_to_mailbox(struct Mailbox *m, struct MdEmailArray *mda)
Copy the Maildir list to the Mailbox.
struct MdEmail * maildir_entry_new(void)
Create a new Maildir entry.
void maildirarray_clear(struct MdEmailArray *mda)
Free a Maildir array.
int mh_check_empty(const char *path)
Is mailbox empty.
static void mh_update_mtime(struct Mailbox *m)
Update our record of the Maildir modification time.
static void mh_delayed_parsing(struct Mailbox *m, struct MdEmailArray *mda, struct Progress *progress)
This function does the second parsing pass.
static bool mh_valid_message(const char *s)
Is this a valid MH message filename.
static void mh_update_maildir(struct MdEmailArray *mda, struct MhSequences *mhs)
Update our record of flags.
bool mh_mkstemp(struct Mailbox *m, FILE **fp, char **tgt)
Create a temporary file.
static int mh_sync_message(struct Mailbox *m, struct Email *e)
Sync an email to an MH folder.
int mh_sync_mailbox_message(struct Mailbox *m, struct Email *e, struct HeaderCache *hc)
Save changes to the mailbox.
static int mh_parse_dir(struct Mailbox *m, struct MdEmailArray *mda, struct Progress *progress)
Read a Maildir mailbox.
static int mh_commit_msg(struct Mailbox *m, struct Message *msg, struct Email *e, bool updseq)
Commit a message to an MH folder.
static int mh_already_notified(struct Mailbox *m, int msgno)
Has the message changed.
static bool mh_read_dir(struct Mailbox *m)
Read an MH mailbox.
static struct Email * mh_parse_message(const char *fname, struct Email *e)
Actually parse an MH message.
static int mh_rewrite_message(struct Mailbox *m, struct Email *e)
Sync a message in an MH folder.
bool MonitorContextChanged
Set to true when the current mailbox has changed.
Monitor files for changes.
Convenience wrapper for the library headers.
bool mutt_path_abbr_folder(char *buf, const char *folder)
Create a folder abbreviation.
bool mutt_path_pretty(char *buf, size_t buflen, const char *homedir, bool is_dir)
Tidy a filesystem path.
bool mutt_path_canon(char *buf, size_t buflen, const char *homedir, bool is_dir)
Create the canonical version of a path.
bool mutt_path_parent(char *buf)
Find the parent of a path.
int mutt_str_cmp(const char *a, const char *b)
Compare two strings, safely.
char * mutt_str_dup(const char *str)
Copy 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)
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
struct Message * mx_msg_open(struct Mailbox *m, struct Email *e)
Return a stream pointer for a message.
struct Message * mx_msg_open_new(struct Mailbox *m, const struct Email *e, MsgOpenFlags flags)
Open a new message.
#define MUTT_MSG_NO_FLAGS
No flags are set.
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
#define MUTT_NEWFOLDER
Create a new folder - same as MUTT_APPEND, but uses mutt_file_fopen() with mode "w" for mbox-style fo...
MxOpenReturns
Return values for mbox_open()
@ MX_OPEN_ERROR
Open failed with an error.
@ MX_OPEN_OK
Open succeeded.
#define MUTT_APPENDNEW
Set in mx_open_mailbox_append if the mailbox doesn't exist.
MxStatus
Return values from mbox_check(), mbox_check_stats(), mbox_snc(), and mbox_close()
@ MX_STATUS_ERROR
An error occurred.
@ MX_STATUS_OK
No changes.
@ MX_STATUS_FLAGS
Nondestructive flags change (IMAP)
@ MX_STATUS_REOPENED
Mailbox was reopened.
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
Notmuch-specific Mailbox data.
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
Parses an RFC822 header.
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.
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
@ MUTT_PROGRESS_WRITE
Progress tracks elements, according to $write_inc
void progress_free(struct Progress **ptr)
Free a Progress Bar.
bool progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
struct Progress * progress_new(const char *msg, enum ProgressType type, size_t size)
Create a new Progress Bar.
uint64_t mutt_rand64(void)
Create a 64-bit random number.
void mh_seq_add_one(struct Mailbox *m, int n, bool unseen, bool flagged, bool replied)
Update the flags for one sequence.
MhSeqFlags mh_seq_check(struct MhSequences *mhs, int i)
Get the flags for a given sequence.
void mh_seq_free(struct MhSequences *mhs)
Free some sequences.
int mh_seq_changed(struct Mailbox *m)
Has the mailbox changed.
void mh_seq_update(struct Mailbox *m)
Update sequence numbers.
int mh_seq_read(struct MhSequences *mhs, const char *path)
Read a set of MH sequences.
#define MH_SEQ_UNSEEN
Email hasn't been read.
#define MH_SEQ_REPLIED
Email has been replied to.
uint8_t MhSeqFlags
Flags, e.g. MH_SEQ_UNSEEN.
#define MH_SEQ_FLAGGED
Email is flagged.
SortType
Methods for sorting.
@ SORT_ORDER
Sort by the order the messages appear in the mailbox.
A group of associated Mailboxes.
struct Body * parts
parts of a multipart or message/rfc822
LOFF_T offset
offset where the actual data begins
LOFF_T length
length (in bytes) of attachment
String manipulation buffer.
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?
struct Body * body
List of MIME parts.
bool active
Message is not to be removed.
bool old
Email is seen, but unread.
void(* edata_free)(void **ptr)
Free the private data attached to the Email.
bool changed
Email has been edited.
bool attach_del
Has an attachment marked for deletion.
bool flagged
Marked important?
time_t date_sent
Time when the message was sent (UTC)
bool replied
Email has been replied to.
char * path
Path of Email (for local Mailboxes)
bool deleted
Email is deleted.
int index
The absolute (unsorted) message number.
time_t received
Time when the message was placed in the mailbox.
unsigned char changed
Changed fields, e.g. MUTT_ENV_CHANGED_SUBJECT.
Wrapper for Email retrieved from the header cache.
uint32_t uidvalidity
IMAP-specific UIDVALIDITY.
struct Email * email
Retrieved email.
void(* mdata_free)(void **ptr)
Free the private data attached to the Mailbox.
bool changed
Mailbox has been modified.
bool has_new
Mailbox has new mail.
struct timespec mtime
Time Mailbox was last changed.
int msg_count
Total number of messages.
enum MailboxType type
Mailbox type.
void * mdata
Driver specific data.
struct Email ** emails
Array of Emails.
int msg_deleted
Number of deleted messages.
int msg_flagged
Number of flagged messages.
struct timespec last_visited
Time of last exit from this mailbox.
bool verbose
Display status messages?
int msg_unread
Number of unread messages.
Maildir-specific Mailbox data -.
mode_t mh_umask
umask to use when creating files
A local copy of an email.
FILE * fp
pointer to the message data
char * path
path to temp file
bool replied
Message has been replied to.
char * committed_path
the final path generated by mx_msg_commit()
bool flagged
Message is flagged.
bool read
Message has been read.
struct Message::@0 flags
Flags for the Message.
Set of MH sequence numbers.
int max
Number of flags stored.
enum MailboxType type
Mailbox type, e.g. MUTT_IMAP.
Container for Accounts, Notifications.
struct ConfigSubset * sub
Inherited config items.