Re: mutt/2421: mutt does not show number of or indicator for new mails for Maildir mailboxes
This patch works better than the one attached to the bug.
It uses the struct stat->st_size as indicator for the number of new mails.
I'm using nfs and did not realize that a local filesystem returns
different values for st_size.
It is appearently impossible to attach a new patch to the bug.
---
browser.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++-------------
mx.c | 7 ++++
2 files changed, 76 insertions(+), 18 deletions(-)
Index: mutt-1.5.13/browser.c
===================================================================
--- mutt-1.5.13.orig/browser.c
+++ mutt-1.5.13/browser.c
@@ -351,6 +351,22 @@ static void init_state (struct browser_s
menu->data = state->entry;
}
+static unsigned short walk_maildir_new(const char *path)
+{
+ struct dirent *de;
+ DIR *d = opendir(path);
+ unsigned short count = 0;
+ if (d) {
+ while ((de = readdir(d))) {
+ if (de->d_name[0] == '.' && (!de->d_name[1] ||
(de->d_name[1] == '.' && !de->d_name[2])))
+ continue;
+ count++;
+ }
+ closedir(d);
+ }
+ return count;
+}
+
static int examine_directory (MUTTMENU *menu, struct browser_state *state,
char *d, const char *prefix)
{
@@ -358,6 +374,8 @@ static int examine_directory (MUTTMENU *
DIR *dp;
struct dirent *de;
char buffer[_POSIX_PATH_MAX + SHORT_STRING];
+ void *md_path;
+ unsigned short new;
BUFFY *tmp;
while (stat (d, &s) == -1)
@@ -393,6 +411,8 @@ static int examine_directory (MUTTMENU *
init_state (state, menu);
+ md_path = malloc(_POSIX_PATH_MAX);
+
while ((de = readdir (dp)) != NULL)
{
if (mutt_strcmp (de->d_name, ".") == 0)
@@ -404,19 +424,33 @@ static int examine_directory (MUTTMENU *
continue;
mutt_concat_path (buffer, d, de->d_name, sizeof (buffer));
- if (lstat (buffer, &s) == -1)
- continue;
-
- if ((! S_ISREG (s.st_mode)) && (! S_ISDIR (s.st_mode)) &&
- (! S_ISLNK (s.st_mode)))
- continue;
-
- tmp = Incoming;
- while (tmp && mutt_strcmp (buffer, tmp->path))
- tmp = tmp->next;
- add_folder (menu, state, de->d_name, &s, (tmp) ? tmp->new : 0);
+ if (mx_is_maildir (buffer)) {
+ if (!md_path)
+ continue;
+ snprintf (md_path, _POSIX_PATH_MAX, "%s/new", buffer);
+ if (lstat (md_path, &s) == -1)
+ continue;
+ s.st_size = new = walk_maildir_new(md_path);
+ } else {
+ if (lstat (buffer, &s) == -1)
+ continue;
+
+ if ((! S_ISREG (s.st_mode)) && (! S_ISDIR (s.st_mode)) &&
+ (! S_ISLNK (s.st_mode)))
+ continue;
+ tmp = Incoming;
+ while (tmp && mutt_strcmp (buffer, tmp->path))
+ tmp = tmp->next;
+ if (tmp)
+ new = tmp->new;
+ else
+ new = 0;
+ }
+ add_folder (menu, state, de->d_name, &s, new);
}
closedir (dp);
+ if (md_path)
+ free (md_path);
browser_sort (state);
return 0;
}
@@ -425,6 +459,8 @@ static int examine_mailboxes (MUTTMENU *
{
struct stat s;
char buffer[LONG_STRING];
+ void *md_path;
+ unsigned short new;
BUFFY *tmp = Incoming;
if (!Incoming)
@@ -433,6 +469,8 @@ static int examine_mailboxes (MUTTMENU *
init_state (state, menu);
+ md_path = malloc(_POSIX_PATH_MAX);
+
do
{
#ifdef USE_IMAP
@@ -449,19 +487,32 @@ static int examine_mailboxes (MUTTMENU *
continue;
}
#endif
- if (lstat (tmp->path, &s) == -1)
- continue;
+ if (mx_is_maildir (tmp->path)) {
+ if (!md_path)
+ continue;
+ snprintf (md_path, _POSIX_PATH_MAX, "%s/new", tmp->path);
+ if (lstat (md_path, &s) == -1)
+ continue;
+ s.st_size = new = walk_maildir_new(md_path);
+ } else {
+ new = tmp->new;
+ if (lstat (tmp->path, &s) == -1)
+ continue;
+ if ((! S_ISREG (s.st_mode)) && (! S_ISDIR (s.st_mode)) &&
+ (! S_ISLNK (s.st_mode)))
+ continue;
+ }
- if ((! S_ISREG (s.st_mode)) && (! S_ISDIR (s.st_mode)) &&
- (! S_ISLNK (s.st_mode)))
- continue;
-
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, new);
}
while ((tmp = tmp->next));
+
+ if (md_path)
+ free(md_path);
+
browser_sort (state);
return 0;
}
Index: mutt-1.5.13/mx.c
===================================================================
--- mutt-1.5.13.orig/mx.c
+++ mutt-1.5.13/mx.c
@@ -458,6 +458,13 @@ int mx_get_magic (const char *path)
}
/*
+ *
+ */
+int mx_is_maildir (const char *s)
+{
+ return mx_get_magic(s) == M_MAILDIR;
+}
+/*
* set DefaultMagic to the given value
*/
int mx_set_magic (const char *s)