Maildir local mailbox type. More...
#include "config.h"
#include <dirent.h>
#include <errno.h>
#include <fcntl.h>
#include <inttypes.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include <utime.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "lib.h"
#include "progress/lib.h"
#include "copy.h"
#include "edata.h"
#include "globals.h"
#include "mdata.h"
#include "mdemail.h"
#include "mx.h"
#include "sort.h"
#include "monitor.h"
#include "hcache/lib.h"
#include "notmuch/lib.h"
Go to the source code of this file.
Macros | |
#define | MMC_NO_DIRS 0 |
No directories changed. | |
#define | MMC_NEW_DIR (1 << 0) |
'new' directory changed | |
#define | MMC_CUR_DIR (1 << 1) |
'cur' directory changed | |
Functions | |
struct Email * | maildir_email_new (void) |
Create a Maildir Email. | |
static void | maildir_check_dir (struct Mailbox *m, const char *dir_name, bool check_new, bool check_stats) |
Check for new mail / mail counts. | |
static int | maildir_sort_flags (const void *a, const void *b, void *sdata) |
Compare two flag characters - Implements sort_t -. | |
void | maildir_gen_flags (char *dest, size_t destlen, struct Email *e) |
Generate the Maildir flags for an email. | |
static int | maildir_commit_message (struct Mailbox *m, struct Message *msg, struct Email *e) |
Commit a message to a maildir folder. | |
static int | maildir_rewrite_message (struct Mailbox *m, struct Email *e) |
Sync a message in an MH folder. | |
static int | maildir_sync_message (struct Mailbox *m, struct Email *e) |
Sync an email to a Maildir folder. | |
static void | maildir_update_mtime (struct Mailbox *m) |
Update our record of the Maildir modification time. | |
static int | maildir_sort_inode (const void *a, const void *b, void *sdata) |
Compare two Maildirs by inode number - Implements sort_t -. | |
static int | maildir_parse_dir (struct Mailbox *m, struct MdEmailArray *mda, const char *subdir, struct Progress *progress) |
Read a Maildir mailbox. | |
static size_t | maildir_hcache_keylen (const char *fn) |
Calculate the length of the Maildir path. | |
static void | maildir_delayed_parsing (struct Mailbox *m, struct MdEmailArray *mda, struct Progress *progress) |
This function does the second parsing pass. | |
static int | maildir_read_dir (struct Mailbox *m, const char *subdir) |
Read a Maildir style mailbox. | |
static void | maildir_canon_filename (struct Buffer *dest, const char *src) |
Generate the canonical filename for a Maildir folder. | |
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. | |
void | maildir_parse_flags (struct Email *e, const char *path) |
Parse Maildir file flags. | |
bool | maildir_parse_stream (enum MailboxType type, FILE *fp, const char *fname, bool is_old, struct Email *e) |
Parse a Maildir message. | |
bool | maildir_parse_message (enum MailboxType type, const char *fname, bool is_old, struct Email *e) |
Actually parse a maildir message. | |
bool | maildir_sync_mailbox_message (struct Mailbox *m, struct Email *e, struct HeaderCache *hc) |
Save changes to the mailbox. | |
FILE * | maildir_open_find_message (const char *folder, const char *msg, char **newname) |
Find a message by name. | |
int | maildir_check_empty (struct Buffer *path) |
Is the mailbox empty. | |
static bool | maildir_ac_owns_path (struct Account *a, const char *path) |
Check whether an Account own a Mailbox path - Implements MxOps::ac_owns_path() -. | |
static bool | maildir_ac_add (struct Account *a, struct Mailbox *m) |
Add a Mailbox to an Account - Implements MxOps::ac_add() -. | |
static enum MxOpenReturns | maildir_mbox_open (struct Mailbox *m) |
Open a Mailbox - Implements MxOps::mbox_open() -. | |
static bool | maildir_mbox_open_append (struct Mailbox *m, OpenMailboxFlags flags) |
Open a Mailbox for appending - Implements MxOps::mbox_open_append() -. | |
static enum MxStatus | maildir_check (struct Mailbox *m) |
Check for new mail. | |
static enum MxStatus | maildir_mbox_check (struct Mailbox *m) |
Check for new mail - Implements MxOps::mbox_check() -. | |
static enum MxStatus | maildir_mbox_check_stats (struct Mailbox *m, uint8_t flags) |
Check the Mailbox statistics - Implements MxOps::mbox_check_stats() -. | |
static enum MxStatus | maildir_mbox_sync (struct Mailbox *m) |
Save changes to the Mailbox - Implements MxOps::mbox_sync() -. | |
static enum MxStatus | maildir_mbox_close (struct Mailbox *m) |
Close a Mailbox - Implements MxOps::mbox_close() -. | |
static bool | maildir_msg_open (struct Mailbox *m, struct Message *msg, struct Email *e) |
Open an email message in a Mailbox - Implements MxOps::msg_open() -. | |
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() -. | |
static int | maildir_msg_commit (struct Mailbox *m, struct Message *msg) |
Save changes to an email - Implements MxOps::msg_commit() -. | |
static int | maildir_msg_close (struct Mailbox *m, struct Message *msg) |
Close an email - Implements MxOps::msg_close() -. | |
static int | maildir_msg_save_hcache (struct Mailbox *m, struct Email *e) |
Save message to the header cache - Implements MxOps::msg_save_hcache() -. | |
static int | maildir_path_canon (struct Buffer *path) |
Canonicalise a Mailbox path - Implements MxOps::path_canon() -. | |
static int | maildir_path_parent (struct Buffer *path) |
Find the parent of a Mailbox path - Implements MxOps::path_parent() -. | |
static int | maildir_path_pretty (struct Buffer *path, const char *folder) |
Abbreviate a Mailbox path - Implements MxOps::path_pretty() -. | |
static enum MailboxType | maildir_path_probe (const char *path, const struct stat *st) |
Is this a Maildir Mailbox? - Implements MxOps::path_probe() -. | |
Variables | |
const struct MxOps | MxMaildirOps |
Maildir Mailbox - Implements MxOps -. | |
Maildir local mailbox type.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.
Definition in file maildir.c.
struct Email * maildir_email_new | ( | void | ) |
Create a Maildir Email.
ptr | Newly created Email |
Create a new Email and attach MaildirEmailData.
Definition at line 85 of file maildir.c.
|
static |
Check for new mail / mail counts.
m | Mailbox to check |
dir_name | Path to Mailbox |
check_new | if true, check for new mail |
check_stats | if true, count total, new, and flagged messages |
Checks the specified maildir subdir (cur or new) for new mail or mail counts.
Definition at line 103 of file maildir.c.
void maildir_gen_flags | ( | char * | dest, |
size_t | destlen, | ||
struct Email * | e | ||
) |
Generate the Maildir flags for an email.
Definition at line 206 of file maildir.c.
|
static |
Commit a message to a maildir folder.
0 | Success |
-1 | Failure |
msg->path contains the file name of a file in tmp/. We take the flags from this file's name.
m is the mail folder we commit to.
e is a header structure to which we write the message's new file name. This is used in the mh and maildir folder sync routines. When this routine is invoked from mx_msg_commit(), e is NULL.
msg->path looks like this:
tmp/{cur,new}.neomutt-HOSTNAME-PID-COUNTER:flags
See also maildir_msg_open_new().
Definition at line 259 of file maildir.c.
Sync a message in an MH folder.
0 | Success |
-1 | Error |
Definition at line 352 of file maildir.c.
Sync an email to a Maildir folder.
0 | Success |
-1 | Error |
Definition at line 405 of file maildir.c.
|
static |
Update our record of the Maildir modification time.
m | Mailbox |
Definition at line 496 of file maildir.c.
|
static |
Read a Maildir mailbox.
[in] | m | Mailbox |
[out] | mda | Array for results |
[in] | subdir | Subdirectory, e.g. 'new' |
[in] | progress | Progress bar |
0 | Success |
-1 | Error |
-2 | Aborted |
Definition at line 532 of file maildir.c.
|
static |
Calculate the length of the Maildir path.
fn | File name |
num | Length in bytes |
Definition at line 599 of file maildir.c.
|
static |
This function does the second parsing pass.
[in] | m | Mailbox |
[out] | mda | Maildir array to parse |
[in] | progress | Progress bar |
Definition at line 613 of file maildir.c.
|
static |
Read a Maildir style mailbox.
m | Mailbox |
subdir | Subdir of the maildir mailbox to read from |
0 | Success |
-1 | Failure |
Definition at line 694 of file maildir.c.
|
static |
Generate the canonical filename for a Maildir folder.
:
may be replaced as the field delimiter by a user defined alternative. Definition at line 750 of file maildir.c.
|
static |
Find a message in a maildir folder.
[in] | folder | Base folder |
[in] | unique | Unique part of filename |
[in] | subfolder | Subfolder to search, e.g. 'cur' |
[out] | newname | File's new name |
ptr | File handle |
These functions try to find a message in a maildir folder when it has moved under our feet. Note that this code is rather expensive, but then again, it's called rarely.
Definition at line 786 of file maildir.c.
void maildir_parse_flags | ( | struct Email * | e, |
const char * | path | ||
) |
Parse Maildir file flags.
e | |
path | Path to email file |
Definition at line 840 of file maildir.c.
bool maildir_parse_stream | ( | enum MailboxType | type, |
FILE * | fp, | ||
const char * | fname, | ||
bool | is_old, | ||
struct Email * | e | ||
) |
Parse a Maildir message.
type | Mailbox type, e.g. MUTT_MAILDIR |
fp | Message file handle |
fname | Message filename |
is_old | true, if the email is old (read) |
e |
true | Success |
Actually parse a maildir message. This may also be used to fill out a fake header structure generated by lazy maildir parsing.
Definition at line 912 of file maildir.c.
bool maildir_parse_message | ( | enum MailboxType | type, |
const char * | fname, | ||
bool | is_old, | ||
struct Email * | e | ||
) |
Actually parse a maildir message.
type | Mailbox type, e.g. MUTT_MAILDIR |
fname | Message filename |
is_old | true, if the email is old (read) |
e | Email to populate |
true | Success |
This may also be used to fill out a fake header structure generated by lazy maildir parsing.
Definition at line 954 of file maildir.c.
bool maildir_sync_mailbox_message | ( | struct Mailbox * | m, |
struct Email * | e, | ||
struct HeaderCache * | hc | ||
) |
Save changes to the mailbox.
true | Success |
false | Error |
Definition at line 977 of file maildir.c.
FILE * maildir_open_find_message | ( | const char * | folder, |
const char * | msg, | ||
char ** | newname | ||
) |
Find a message by name.
[in] | folder | Maildir path |
[in] | msg | Email path |
[out] | newname | New name, if it has moved |
ptr | File handle |
Definition at line 1023 of file maildir.c.
int maildir_check_empty | ( | struct Buffer * | path | ) |
Is the mailbox empty.
path | Mailbox to check |
Definition at line 1070 of file maildir.c.
Check for new mail.
m | Mailbox |
enum | MxStatus |
This function handles arrival of new mail and reopening of maildir folders. The basic idea here is we check to see if either the new or cur subdirectories have changed, and if so, we scan them for the list of files. We check for newly added messages, and then merge the flags messages we already knew about. We don't treat either subdirectory differently, as mail could be copied directly into the cur directory from another agent.
Definition at line 1199 of file maildir.c.