summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org>2019-05-29 12:25:51 +0300
committerSergey Poznyakoff <gray@gnu.org>2019-05-29 12:25:51 +0300
commite7397c8fad6835f0af76840074729f6c2cb33e7e (patch)
treebdaa41fac3bfc1a8dee9aecd086a7e10d1a911bd
parent491151b751c965cbb1158588a09aa28cc19921f6 (diff)
downloadmailutils-e7397c8fad6835f0af76840074729f6c2cb33e7e.tar.gz
mailutils-e7397c8fad6835f0af76840074729f6c2cb33e7e.tar.bz2
mh: fix folder +/absolute/name
* mh/folder.c (name_prefix_len): Remove global. (install_folder_info,_scan): Take additional argument: length of the name prefix to skip. (folder_scan): New function. (action_print): Don't impose name prefix unconditionally. Call folder_scan to set it up as necessary.
-rw-r--r--mh/folder.c41
1 files changed, 25 insertions, 16 deletions
diff --git a/mh/folder.c b/mh/folder.c
index 356c3785b..3c0285c0c 100644
--- a/mh/folder.c
+++ b/mh/folder.c
@@ -172,20 +172,19 @@ struct folder_info
};
mu_list_t folder_info_list; /* Memory storage for folder info */
size_t message_count; /* Total number of messages */
-int name_prefix_len; /* Length of the mu_path_folder_dir */
-
void
-install_folder_info (const char *name, struct folder_info const *info)
+install_folder_info (const char *name, struct folder_info const *info,
+ size_t skip_prefix_len)
{
struct folder_info *new_info = mu_alloc (sizeof (*new_info));
*new_info = *info;
- new_info->name = mu_strdup (new_info->name + name_prefix_len);
+ new_info->name = mu_strdup (new_info->name + skip_prefix_len);
mu_list_append (folder_info_list, new_info);
message_count += info->message_count;
}
static int
folder_info_comp (const void *a, const void *b)
@@ -207,13 +206,13 @@ read_seq_file (struct folder_info *info, const char *prefix, const char *name)
if (mu_property_sget_value (prop, "cur", &p) == 0)
info->cur = strtoul (p, NULL, 0);
mu_property_destroy (&prop);
}
static void
-_scan (const char *name, size_t depth)
+_scan (const char *name, size_t depth, size_t skip_prefix_len)
{
DIR *dir;
struct dirent *entry;
struct folder_info info;
char *p;
struct stat st;
@@ -245,13 +244,13 @@ _scan (const char *name, size_t depth)
if (max_depth == 1)
{
if (fast_mode && depth > 0)
{
memset (&info, 0, sizeof (info));
info.name = (char*) name;
- install_folder_info (name, &info);
+ install_folder_info (name, &info, skip_prefix_len);
closedir (dir);
return;
}
}
if (max_depth && depth > max_depth)
@@ -274,13 +273,13 @@ _scan (const char *name, size_t depth)
p = mh_safe_make_file_name (name, entry->d_name);
if (stat (p, &st) < 0)
mu_diag_funcall (MU_DIAG_ERROR, "stat", p, errno);
else if (S_ISDIR (st.st_mode))
{
info.others++;
- _scan (p, depth+1);
+ _scan (p, depth+1, skip_prefix_len);
}
else
{
char *endp;
uid = strtoul (entry->d_name, &endp, 10);
if (*endp)
@@ -303,13 +302,29 @@ _scan (const char *name, size_t depth)
if (stat (p, &st) < 0 || !S_ISREG (st.st_mode))
info.cur = 0;
free (p);
}
closedir (dir);
if (depth > 0)
- install_folder_info (name, &info);
+ install_folder_info (name, &info, skip_prefix_len);
+}
+
+static void
+folder_scan (const char *name, size_t depth)
+{
+ const char *folder_dir = mu_folder_directory ();
+ size_t skip_prefix_len;
+
+ skip_prefix_len = strlen (folder_dir);
+ if (folder_dir[skip_prefix_len - 1] == '/')
+ skip_prefix_len++;
+ if (strncmp (name, folder_dir, skip_prefix_len) == 0)
+ skip_prefix_len++; /* skip past the slash */
+ else
+ skip_prefix_len = 0;
+ _scan (name, depth, skip_prefix_len);
}
static int
_folder_info_printer (void *item, void *data)
{
struct folder_info *info = item;
@@ -373,30 +388,24 @@ print_fast (void)
mu_list_foreach (folder_info_list, _folder_name_printer, NULL);
}
static int
action_print (void)
{
- const char *folder_dir = mu_folder_directory ();
mh_seq_name = mh_global_profile_get ("mh-sequences", MH_SEQUENCES_FILE);
- name_prefix_len = strlen (folder_dir);
- if (folder_dir[name_prefix_len - 1] == '/')
- name_prefix_len++;
- name_prefix_len++; /* skip past the slash */
-
mu_list_create (&folder_info_list);
if (show_all)
{
- _scan (folder_dir, 0);
+ folder_scan (mu_folder_directory (), 0);
}
else
{
char *p = mh_expand_name (NULL, mh_current_folder (), NAME_ANY);
- _scan (p, 1);
+ folder_scan (p, 1);
free (p);
}
mu_list_sort (folder_info_list, folder_info_comp);
if (fast_mode)

Return to:

Send suggestions and report system problems to the System administrator.