Go to the documentation of this file.
67 #define MMC_NEW_DIR (1 << 0)
68 #define MMC_CUR_DIR (1 << 1)
80 bool check_new,
bool check_stats)
83 struct dirent *de = NULL;
102 if (!(check_new || check_stats))
112 while ((de = readdir(dirp)))
114 if (*de->d_name ==
'.')
117 p = strstr(de->d_name,
":2,");
118 if (p && strchr(p + 3,
'T'))
124 if (p && strchr(p + 3,
'F'))
127 if (!p || !strchr(p + 3,
'S'))
169 return (
int) (*((
const char *) a) - *((
const char *) b));
182 const char *flags = NULL;
186 flags =
edata->maildir_flags;
197 snprintf(tmp,
sizeof(tmp),
"%s%s%s%s%s", e->
flagged ?
"F" :
"", e->
replied ?
"R" :
"",
201 snprintf(dest, destlen,
":2,%s", tmp);
242 char *s = strrchr(msg->
path,
'/') + 1;
280 }
while ((rc_utime == -1) && (errno == EINTR));
284 _(
"maildir_commit_message(): unable to set time on file"));
301 else if (errno != EEXIST)
336 long old_hdr_lines = e->
lines;
366 e->
lines = old_hdr_lines;
389 struct Buffer *newpath = NULL;
390 struct Buffer *partpath = NULL;
391 struct Buffer *fullpath = NULL;
392 struct Buffer *oldpath = NULL;
410 char *p = strrchr(e->
path,
'/');
425 p = strchr(newpath->
data,
':');
476 snprintf(buf,
sizeof(buf),
"%s/%s",
mailbox_path(m),
"cur");
477 if (stat(buf, &st) == 0)
479 snprintf(buf,
sizeof(buf),
"%s/%s",
mailbox_path(m),
"new");
481 if (stat(buf, &st) == 0)
507 const char *subdir,
struct Progress *progress)
509 struct dirent *de = NULL;
513 struct Email *e = NULL;
527 while (((de = readdir(dirp))) && (
SigInt != 1))
529 if (*de->d_name ==
'.')
550 entry->
inode = de->d_ino;
579 const char *p = strrchr(fn,
':');
612 struct stat lastchanged = { 0 };
616 rc = stat(fn, &lastchanged);
690 snprintf(msg,
sizeof(msg),
_(
"Reading %s..."),
mailbox_path(m));
717 char *t = strrchr(src,
'/');
722 char *u = strpbrk(dest->
data,
",:");
743 const char *subfolder,
char **newname)
749 struct dirent *de = NULL;
763 while ((de = readdir(dp)))
806 char *p = strrchr(
path,
':');
812 q =
edata->maildir_flags;
846 if (q ==
edata->maildir_flags)
865 const char *fname,
bool is_old,
struct Email *e)
876 fstat(fileno(fp), &st);
909 bool is_old,
struct Email *e)
911 FILE *fp = fopen(fname,
"r");
941 const char *key = e->
path + 3;
958 const char *key = e->
path + 3;
976 static unsigned int new_hits = 0, cur_hits = 0;
982 (new_hits > cur_hits) ?
"new" :
"cur", newname);
983 if (fp || (errno != ENOENT))
985 if ((new_hits < UINT_MAX) && (cur_hits < UINT_MAX))
987 new_hits += ((new_hits > cur_hits) ? 1 : 0);
988 cur_hits += ((new_hits > cur_hits) ? 0 : 1);
994 (new_hits > cur_hits) ?
"cur" :
"new", newname);
995 if (fp || (errno != ENOENT))
997 if ((new_hits < UINT_MAX) && (cur_hits < UINT_MAX))
999 new_hits += ((new_hits > cur_hits) ? 0 : 1);
1000 cur_hits += ((new_hits > cur_hits) ? 1 : 0);
1024 struct dirent *de = NULL;
1035 snprintf(realpath,
sizeof(realpath),
"%s/%s", path, (iter == 0) ?
"cur" :
"new");
1036 dp = opendir(realpath);
1039 while ((de = readdir(dp)))
1041 if (*de->d_name !=
'.')
1049 }
while (rc && iter < 2);
1103 if ((mkdir(tmp, S_IRWXU) != 0) && (errno != EEXIST))
1112 if ((mkdir(tmp, S_IRWXU) != 0) && (errno != EEXIST))
1123 if ((mkdir(tmp, S_IRWXU) != 0) && (errno != EEXIST))
1152 bool occult =
false;
1154 bool flags_changed =
false;
1239 if (md && md->
email)
1253 flags_changed =
true;
1260 flags_changed =
true;
1325 bool check_stats = flags;
1326 bool check_new =
true;
1339 if (check_new || check_stats)
1393 for (
int i = 0, j = 0; i < m->
msg_count; i++)
1436 msg->
fp = fopen(
path,
"r");
1437 if (!msg->
fp && (errno == ENOENT))
1467 struct Email tmp = *e;
1483 snprintf(
path,
sizeof(
path),
"%s/tmp/%s.%lld.R%" PRIu64
".%s%s",
1489 fd = open(
path, O_WRONLY | O_EXCL | O_CREAT, 0666);
1492 if (errno != EEXIST)
1508 msg->
fp = fdopen(fd,
"w");
1546 char *key = e->
path + 3;
1599 if (!st || !S_ISDIR(st->st_mode))
1603 snprintf(cur,
sizeof(cur),
"%s/cur", path);
1606 if ((stat(cur, &stc) == 0) && S_ISDIR(stc.st_mode))
1632 .msg_padding_size = NULL,
1635 .tags_commit = NULL,
void(* mdata_free)(void **ptr)
Free the private data attached to the Mailbox.
time_t date_sent
Time when the message was sent (UTC)
int msgno
Number displayed to the user.
static bool maildir_mbox_open_append(struct Mailbox *m, OpenMailboxFlags flags)
Open a Mailbox for appending - Implements MxOps::mbox_open_append()
enum MxStatus maildir_mbox_close(struct Mailbox *m)
Close a Mailbox - Implements MxOps::mbox_close()
struct HeaderCache * mutt_hcache_open(const char *path, const char *folder, hcache_namer_t namer)
Multiplexor for StoreOps::open.
WHERE SIG_ATOMIC_VOLATILE_T SigInt
true after SIGINT is received
#define MUTT_MSG_NO_FLAGS
No flags are set.
void maildir_parse_flags(struct Email *e, const char *path)
Parse Maildir file flags.
struct HashTable * mutt_hash_new(size_t num_elems, HashFlags flags)
Create a new Hash Table (with string keys)
MxStatus
Return values from mx_mbox_check(), mx_mbox_sync(), and mx_mbox_close()
enum MailboxType type
Mailbox type, e.g. MUTT_IMAP.
struct Email * maildir_parse_stream(enum MailboxType type, FILE *fp, const char *fname, bool is_old, struct Email *e)
Parse a Maildir message.
int maildir_path_canon(char *buf, size_t buflen)
Canonicalise a Mailbox path - Implements MxOps::path_canon()
int lines
How many lines in the body of this message?
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
static struct Email * restore(const unsigned char *d)
Restore an Email from data retrieved from the cache.
struct Email ** emails
Array of Emails.
bool mutt_strn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings (to a maximum), safely.
#define MMC_NEW_DIR
'new' directory changed
@ NT_MAILBOX_INVALID
Email list was changed.
String manipulation buffer.
bool mutt_path_abbr_folder(char *buf, size_t buflen, const char *folder)
Create a folder abbreviation.
LOFF_T offset
offset where the actual data begins
int msg_deleted
Number of deleted messages.
size_t maildir_hcache_keylen(const char *fn)
Calculate the length of the Maildir path.
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
@ MUTT_STAT_MTIME
File/dir's mtime - last modified time.
MxOpenReturns
Return values for mbox_open()
@ MUTT_PROGRESS_WRITE
Progress tracks elements, according to $write_inc
int maildir_commit_message(struct Mailbox *m, struct Message *msg, struct Email *e)
Commit a message to a maildir folder.
Maildir-specific Mailbox data -.
struct MaildirMboxData * maildir_mdata_get(struct Mailbox *m)
Get the private data for this Mailbox.
FILE * maildir_open_find_message(const char *folder, const char *msg, char **newname)
Find a new.
bool maildir_ac_owns_path(struct Account *a, const char *path)
Check whether an Account own a Mailbox path - Implements MxOps::ac_owns_path()
struct timespec mtime_cur
#define MUTT_NEWFOLDER
Create a new folder - same as MUTT_APPEND,.
char * mutt_str_dup(const char *str)
Copy a string, safely.
time_t received
the time at which this message was received
@ LL_DEBUG1
Log at debug level 1.
#define ARRAY_SORT(head, fn)
Sort an array.
bool has_new
Mailbox has new mail.
void maildir_mdata_free(void **ptr)
Free the private Mailbox data - Implements Mailbox::mdata_free()
@ MX_OPEN_OK
Open succeeded.
bool mutt_path_canon(char *buf, size_t buflen, const char *homedir, bool is_dir)
Create the canonical version of a path.
void maildir_update_mtime(struct Mailbox *m)
Update our record of the Maildir modification time.
char * dptr
Current read/write position.
struct MaildirMboxData * maildir_mdata_new(void)
Create a new MaildirMboxData object.
char * path
Path of Email (for local Mailboxes)
void(* edata_free)(void **ptr)
Free the private data attached to the Email.
bool maildir_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()
#define ARRAY_SIZE(head)
The number of elements stored.
void mutt_buffer_pool_release(struct Buffer **pbuf)
Free a Buffer from the pool.
bool C_MaildirHeaderCacheVerify
Config: (hcache) Check for maildir changes when opening mailbox.
struct Email * email_new(void)
Create a new Email.
void mutt_body_free(struct Body **ptr)
Free a Body.
@ MUTT_STAT_CTIME
File/dir's ctime - creation time.
@ MX_STATUS_REOPENED
Mailbox was reopened.
int maildir_path_pretty(char *buf, size_t buflen, const char *folder)
Abbreviate a Mailbox path - Implements MxOps::path_pretty()
void * mutt_hash_find(const struct HashTable *table, const char *strkey)
Find the HashElem data in a Hash Table element using a key.
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
@ MX_STATUS_NEW_MAIL
New mail received in Mailbox.
bool old
Email is seen, but unread.
time_t received
Time when the message was placed in the mailbox.
char * committed_path
the final path generated by mx_msg_commit()
void mutt_progress_init(struct Progress *progress, const char *msg, enum ProgressType type, size_t size)
Set up a progress bar.
int maildir_rewrite_message(struct Mailbox *m, int msgno)
Sync a message in an MH folder.
bool active
Message is not to be removed.
struct Buffer * mutt_buffer_pool_get(void)
Get a Buffer from the pool.
int maildir_read_dir(struct Mailbox *m, const char *subdir)
Read a Maildir style mailbox.
bool maildir_update_flags(struct Mailbox *m, struct Email *e_old, struct Email *e_new)
Update the mailbox flags.
enum MailboxType type
Mailbox type.
void * mdata
Driver specific data.
unsigned char changed
Changed fields, e.g. MUTT_ENV_CHANGED_SUBJECT.
#define ARRAY_FOREACH(elem, head)
Iterate over all elements of the array.
int maildir_msg_close(struct Mailbox *m, struct Message *msg)
Close an email - Implements MxOps::msg_close()
A group of associated Mailboxes.
enum MxStatus maildir_mbox_check(struct Mailbox *m)
Check for new mail - Implements MxOps::mbox_check()
Maildir-specific Email data -.
char * path
path to temp file
#define ARRAY_HEAD_INITIALIZER
Static initializer for arrays.
static int maildir_msg_commit(struct Mailbox *m, struct Message *msg)
Save changes to an email - Implements MxOps::msg_commit()
LOFF_T length
length (in bytes) of attachment
bool changed
Mailbox has been modified.
int maildir_sync_message(struct Mailbox *m, int msgno)
Sync an email to a Maildir folder.
int msg_count
Total number of messages.
static bool maildir_msg_open(struct Mailbox *m, struct Message *msg, int msgno)
Open an email message in a Mailbox - Implements MxOps::msg_open()
struct timespec mtime
Time Mailbox was last changed.
@ MUTT_UNKNOWN
Mailbox wasn't recognised.
bool C_CheckNew
Config: (maildir,mh) Check for new mail while the mailbox is open.
struct HashElem * mutt_hash_insert(struct HashTable *table, const char *strkey, void *data)
Add a new element to the Hash Table (with string keys)
#define MUTT_APPENDNEW
Set in mx_open_mailbox_append if the mailbox doesn't exist.
void maildir_delayed_parsing(struct Mailbox *m, struct MdEmailArray *mda, struct Progress *progress)
This function does the second parsing pass.
@ MUTT_NOTMUCH
'Notmuch' (virtual) Mailbox type
#define ARRAY_FREE(head)
Release all memory.
struct Body * parts
parts of a multipart or message/rfc822
@ MUTT_PROGRESS_READ
Progress tracks elements, according to $read_inc
static int maildir_cmp_inode(const void *a, const void *b)
Compare two Maildirs by inode number - Implements sort_t.
struct Email * email
Retrieved email.
struct Envelope * env
Envelope information.
int maildir_check_empty(const char *path)
Is the mailbox empty.
enum MxStatus maildir_mbox_sync(struct Mailbox *m)
Save changes to the Mailbox - Implements MxOps::mbox_sync()
uint64_t mutt_rand64(void)
Create a 64-bit random number.
static void maildir_check_dir(struct Mailbox *m, const char *dir_name, bool check_new, bool check_stats)
Check for new mail / mail counts.
#define mutt_debug(LEVEL,...)
bool purge
Skip trash folder when deleting.
WHERE bool C_FlagSafe
Config: Protect flagged messages from deletion.
#define CH_UPDATE
Update the status and x-status fields?
Wrapper for Email retrieved from the header cache.
int msg_flagged
Number of flagged messages.
@ MX_STATUS_ERROR
An error occurred.
FILE * fp
pointer to the message data
bool flagged
Marked important?
size_t mutt_str_len(const char *a)
Calculate the length of a string, safely.
static const char * mutt_buffer_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
int nm_update_filename(struct Mailbox *m, const char *old_file, const char *new_file, struct Email *e)
Change the filename.
bool verbose
Display status messages?
struct MdEmail * maildir_entry_new(void)
Create a new Maildir entry.
void maildir_gen_flags(char *dest, size_t destlen, struct Email *e)
Generate the Maildir flags for an email.
struct MxOps MxMaildirOps
Maildir Mailbox - Implements MxOps.
time_t mutt_date_epoch(void)
Return the number of seconds since the Unix epoch.
bool trash
Message is marked as trashed on disk (used by the maildir_trash option)
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
struct Email * maildir_parse_message(enum MailboxType type, const char *fname, bool is_old, struct Email *e)
Actually parse a maildir message.
static int maildir_msg_save_hcache(struct Mailbox *m, struct Email *e)
Save message to the header cache - Implements MxOps::msg_save_hcache()
int mutt_hcache_store(struct HeaderCache *hc, const char *key, size_t keylen, struct Email *e, uint32_t uidvalidity)
Multiplexor for StoreOps::store.
bool deleted
Email is deleted.
int mutt_file_mkdir(const char *path, mode_t mode)
Recursively create directories.
#define MUTT_HASH_NO_FLAGS
No flags are set.
bool mutt_path_parent(char *buf, size_t buflen)
Find the parent of a path.
uint8_t OpenMailboxFlags
Flags for mutt_open_mailbox(), e.g. MUTT_NOSORT.
char * HomeDir
User's home directory.
WHERE bool C_MailCheckRecent
Config: Notify the user about new mail since the last time the mailbox was opened.
void * edata
Driver-specific data.
WHERE char * ShortHostname
Short version of the hostname.
struct timespec last_visited
Time of last exit from this mailbox.
int mutt_file_safe_rename(const char *src, const char *target)
NFS-safe renaming of files.
#define MMC_CUR_DIR
'cur' directory changed
static enum MxOpenReturns maildir_mbox_open(struct Mailbox *m)
Open a Mailbox - Implements MxOps::mbox_open()
int mutt_hcache_delete_record(struct HeaderCache *hc, const char *key, size_t keylen)
Multiplexor for StoreOps::delete_record.
static enum MailboxType maildir_path_probe(const char *path, const struct stat *st)
Is this a Maildir Mailbox? - Implements MxOps::path_probe()
#define MUTT_CM_UPDATE
Update structs on sync.
char * C_HeaderCache
Config: (hcache) Directory/file for the header cache database.
void mailbox_changed(struct Mailbox *m, enum NotifyMailbox action)
Notify observers of a change to a Mailbox.
bool C_MaildirTrash
Config: Use the maildir 'trashed' flag, rather than deleting.
static int ch_compare(const void *a, const void *b)
qsort callback to sort characters
void mutt_file_get_stat_timespec(struct timespec *dest, struct stat *sb, enum MuttStatType type)
Read the stat() time into a time value.
MailboxType
Supported mailbox formats.
#define MMC_NO_DIRS
No directories changed.
bool C_MarkOld
Config: Mark new emails as old when leaving the mailbox.
int index
The absolute (unsorted) message number.
struct Envelope * mutt_rfc822_read_header(FILE *fp, struct Email *e, bool user_hdrs, bool weed)
parses an RFC822 header
void email_free(struct Email **ptr)
Free an Email.
void mutt_progress_update(struct Progress *progress, size_t pos, int percent)
Update the state of the progress bar.
int msg_unread
Number of unread messages.
struct MaildirEmailData * maildir_edata_get(struct Email *e)
Get the private data for this Email.
static FILE * maildir_open_find_message_dir(const char *folder, const char *unique, const char *subfolder, char **newname)
Find a message in a maildir folder.
int maildir_parse_dir(struct Mailbox *m, struct MdEmailArray *mda, const char *subdir, struct Progress *progress)
Read a Maildir mailbox.
@ MUTT_MAILDIR
'Maildir' Mailbox type
char * mutt_buffer_strdup(const struct Buffer *buf)
Copy a Buffer's string.
@ MX_STATUS_FLAGS
Nondestructive flags change (IMAP)
bool attach_del
Has an attachment marked for deletion.
#define MUTT_APPEND
Open mailbox for appending messages.
static const char * mailbox_path(const struct Mailbox *m)
Get the Mailbox's path string.
bool mutt_path_pretty(char *buf, size_t buflen, const char *homedir, bool is_dir)
Tidy a filesystem path.
uint32_t uidvalidity
IMAP-specific UIDVALIDITY.
int mx_msg_close(struct Mailbox *m, struct Message **msg)
Close a message.
bool maildir_ac_add(struct Account *a, struct Mailbox *m)
Add a Mailbox to an Account - Implements MxOps::ac_add()
void mutt_hcache_close(struct HeaderCache *hc)
Multiplexor for StoreOps::close.
bool replied
Email has been replied to.
char * data
Pointer to data.
The envelope/body of an email.
size_t mutt_str_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix.
struct Message * mx_msg_open_new(struct Mailbox *m, const struct Email *e, MsgOpenFlags flags)
Open a new message.
int msg_new
Number of new messages.
@ MX_OPEN_ERROR
Open failed with an error.
int mutt_buffer_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
int mutt_file_stat_timespec_compare(struct stat *sba, enum MuttStatType type, struct timespec *b)
Compare stat info with a time value.
int mutt_copy_message(FILE *fp_out, struct Mailbox *m, struct Email *e, CopyMessageFlags cmflags, CopyHeaderFlags chflags, int wraplen)
Copy a message from a Mailbox.
mode_t mh_umask(struct Mailbox *m)
Create a umask from the mailbox directory.
int mutt_file_fsync_close(FILE **fp)
Flush the data, before closing a file (and NULL the pointer)
bool MonitorContextChanged
true after the current mailbox has changed
@ NT_MAILBOX_RESORT
Email list needs resorting.
#define CH_UPDATE_LEN
Update Lines: and Content-Length:
static enum MxStatus maildir_mbox_check_stats(struct Mailbox *m, uint8_t flags)
Check the Mailbox statistics - Implements MxOps::mbox_check_stats()
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
void maildir_edata_free(void **ptr)
Free the private Email data - Implements Email::edata_free()
bool C_MaildirCheckCur
Config: Check both 'new' and 'cur' directories for new mail.
@ LL_DEBUG2
Log at debug level 2.
struct MaildirEmailData * maildir_edata_new(void)
Create a new MaildirEmailData object.
void mutt_hash_free(struct HashTable **ptr)
Free a hash table.
bool changed
Email has been edited.
A local copy of an email.
bool maildir_sync_mailbox_message(struct Mailbox *m, int msgno, struct HeaderCache *hc)
Save changes to the mailbox.
@ MX_STATUS_OK
No changes.
struct Body * body
List of MIME parts.
int maildir_move_to_mailbox(struct Mailbox *m, struct MdEmailArray *mda)
Copy the Maildir list to the Mailbox.
void maildir_canon_filename(struct Buffer *dest, const char *src)
Generate the canonical filename for a Maildir folder.
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)
int maildir_path_parent(char *buf, size_t buflen)
Find the parent of a Mailbox path - Implements MxOps::path_parent()