<<< Date Index >>>     <<< Thread Index >>>

Re: mutt/2421: mutt does not show number of or indicator for new mails for Maildir mailboxes



The following reply was made to PR mutt/2421; it has been noted by GNATS.

From: Olaf Hering <olaf@xxxxxxxxx>
To: bug-any@xxxxxxxxxxxxx
Cc: 
Subject: Re: mutt/2421: mutt does not show number of or indicator for new mails 
for Maildir mailboxes
Date: Mon, 20 Nov 2006 21:42:25 +0100 (MET)

 --W/nzBZO5zC0uMSeA
 Content-Type: text/plain; charset=utf-8
 Content-Disposition: inline
 
 
 new patch, no malloc, sizeof(array).
 
 
 --W/nzBZO5zC0uMSeA
 Content-Type: text/plain; charset=utf-8
 Content-Disposition: attachment; filename="mutt-maildir.patch"
 
 ---
  browser.c |   73 
++++++++++++++++++++++++++++++++++++++++++++++----------------
  mailbox.h |    1 
  mx.c      |    7 +++++
  3 files changed, 63 insertions(+), 18 deletions(-)
 
 Index: mutt/browser.c
 ===================================================================
 --- mutt.orig/browser.c
 +++ mutt/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];
 +  char md_path[_POSIX_PATH_MAX];
 +  unsigned short new;
    BUFFY *tmp;
  
    while (stat (d, &s) == -1)
 @@ -404,17 +422,27 @@ 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)) {
 +              snprintf (md_path, sizeof(md_path), "%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);  
    browser_sort (state);
 @@ -425,6 +453,8 @@ static int examine_mailboxes (MUTTMENU *
  {
    struct stat s;
    char buffer[LONG_STRING];
 +  char md_path[_POSIX_PATH_MAX];
 +  unsigned short new;
    BUFFY *tmp = Incoming;
  
    if (!Incoming)
 @@ -449,17 +479,24 @@ static int examine_mailboxes (MUTTMENU *
        continue;
      }
  #endif
 -    if (lstat (tmp->path, &s) == -1)
 -      continue;
 +    if (mx_is_maildir (tmp->path)) {
 +      snprintf (md_path, sizeof(md_path), "%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));
    browser_sort (state);
 Index: mutt/mx.c
 ===================================================================
 --- mutt.orig/mx.c
 +++ mutt/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)
 Index: mutt/mailbox.h
 ===================================================================
 --- mutt.orig/mailbox.h
 +++ mutt/mailbox.h
 @@ -74,6 +74,7 @@ int mx_is_imap (const char *);
  #ifdef USE_POP
  int mx_is_pop (const char *);
  #endif
 +int mx_is_maildir (const char *s);
  
  int mx_access (const char*, int);
  int mx_check_empty (const char *);
 
 --W/nzBZO5zC0uMSeA--