# vi: ft=diff This is the maildir mtime patch by Dale Woolridge. The home page for this patch is: http://www.mutt.ca/maildir-mtime.html * Patch last synced with upstream: - Date: 2004-08-10 - File: http://www.mutt.ca/patches/patch-1.5.6.dw.maildir-mtime.1 * Changes made: - removed a spurious const in add_folder() definition. - added a $maildir_mtime option to allow this patch to be disabled at runtime (see Bug#253261, comments from Zephaniah E. Hull). - 2007-04-03 myon: resolved conflict in browser.c == END PATCH --- a/buffy.c +++ b/buffy.c @@ -226,6 +226,7 @@ int mutt_parse_mailboxes (BUFFER *path, (*tmp)->new = 0; (*tmp)->notified = 1; (*tmp)->newly_created = 0; + (*tmp)->mtime = 0; /* for check_mbox_size, it is important that if the folder is new (tested by * reading it), the size is set to 0 so that later when we check we see @@ -254,6 +255,7 @@ int mutt_buffy_check (int force) { BUFFY *tmp; struct stat sb; + struct stat smd; struct dirent *de; DIR *dirp; char path[_POSIX_PATH_MAX]; @@ -298,6 +300,7 @@ int mutt_buffy_check (int force) if (tmp->magic != M_IMAP) #endif tmp->new = 0; + tmp->mtime = 0; #ifdef USE_IMAP if (tmp->magic != M_IMAP) @@ -380,10 +383,20 @@ int mutt_buffy_check (int force) if (*de->d_name != '.' && (!(p = strstr (de->d_name, ":2,")) || !strchr (p + 3, 'T'))) { - /* one new and undeleted message is enough */ - BuffyCount++; - tmp->new = 1; - break; + if (!tmp->new) + { + /* one new and undeleted message is enough */ + BuffyCount++; + tmp->new = 1; + + if (! option (OPTMAILDIRMTIME)) /* prevent stat calls */ + break; + } + snprintf (path, sizeof (path), "%s/new/%s", tmp->path, de->d_name); + if (!stat (path, &smd) && smd.st_mtime > tmp->mtime) + { + tmp->mtime = smd.st_mtime; + } } } closedir (dirp); --- a/init.h +++ b/init.h @@ -1086,6 +1086,16 @@ struct option_t MuttVars[] = { ** \fBDON'T CHANGE THIS SETTING UNLESS YOU ARE REALLY SURE WHAT YOU ARE ** DOING!\fP */ + { "maildir_mtime", DT_BOOL, R_NONE, OPTMAILDIRMTIME, 0 }, + /* + ** .pp + ** If set, the sort-by-date option in the browser will sort maildirs + ** smartly, not using the mtime of the maildir itself but that of the + ** newest message in the new subdirectory, making the sorting by + ** reverse date much more useful. People with maildirs over NFS may + ** wish to leave this option unset. + ** + */ #ifdef USE_HCACHE { "header_cache", DT_PATH, R_NONE, UL &HeaderCache, 0 }, /* --- a/mutt.h +++ b/mutt.h @@ -395,6 +395,7 @@ enum OPTINCLUDEONLYFIRST, OPTKEEPFLAGGED, OPTMAILCAPSANITIZE, + OPTMAILDIRMTIME, OPTMAILDIRTRASH, OPTMARKERS, OPTMARKOLD, --- a/browser.c +++ b/browser.c @@ -32,6 +32,7 @@ #ifdef USE_IMAP #include "imap.h" #endif +#include "mx.h" #include #include @@ -307,8 +308,10 @@ folder_format_str (char *dest, size_t de } static void add_folder (MUTTMENU *m, struct browser_state *state, - const char *name, const struct stat *s, int new) + const char *name, /*DEB const IAN*/ struct stat *s, BUFFY *mbuf) { + int new = (mbuf) ? mbuf->new : 0; + if (state->entrylen == state->entrymax) { /* need to allocate more space */ @@ -320,6 +323,9 @@ static void add_folder (MUTTMENU *m, str m->data = state->entry; } + if (mbuf && mbuf->magic == M_MAILDIR && mbuf->mtime) + s->st_mtime = mbuf->mtime; + if (s != NULL) { (state->entry)[state->entrylen].mode = s->st_mode; @@ -414,7 +420,7 @@ static int examine_directory (MUTTMENU * tmp = Incoming; while (tmp && mutt_strcmp (buffer, tmp->path)) tmp = tmp->next; - add_folder (menu, state, de->d_name, &s, (tmp) ? tmp->new : 0); + add_folder (menu, state, de->d_name, &s, tmp); } closedir (dp); browser_sort (state); @@ -438,14 +444,15 @@ static int examine_mailboxes (MUTTMENU * if (mx_is_imap (tmp->path)) { imap_mailbox_state (tmp->path, &mbox); - add_folder (menu, state, tmp->path, NULL, mbox.new); + tmp->new = mbox.new; + add_folder (menu, state, tmp->path, NULL, tmp); continue; } #endif #ifdef USE_POP if (mx_is_pop (tmp->path)) { - add_folder (menu, state, tmp->path, NULL, tmp->new); + add_folder (menu, state, tmp->path, NULL, tmp); continue; } #endif @@ -459,7 +466,7 @@ static int examine_mailboxes (MUTTMENU * strfcpy (buffer, NONULL(tmp->path), sizeof (buffer)); mutt_pretty_mailbox (buffer); - add_folder (menu, state, buffer, &s, tmp->new); + add_folder (menu, state, buffer, &s, tmp); } while ((tmp = tmp->next)); browser_sort (state); --- a/buffy.h +++ b/buffy.h @@ -25,6 +25,7 @@ typedef struct buffy_t char *path; long size; struct buffy_t *next; + time_t mtime; /* for maildirs...time of newest entry */ short new; /* mailbox has new mail */ short notified; /* user has been notified */ short magic; /* mailbox type */ --- a/PATCHES +++ b/PATCHES @@ -0,0 +1 @@ +patch-1.5.6.dw.maildir-mtime.1