summaryrefslogtreecommitdiff
path: root/mail/folders.c
diff options
context:
space:
mode:
Diffstat (limited to 'mail/folders.c')
-rw-r--r--mail/folders.c102
1 files changed, 86 insertions, 16 deletions
diff --git a/mail/folders.c b/mail/folders.c
index 271eb5676..ea2d10249 100644
--- a/mail/folders.c
+++ b/mail/folders.c
@@ -1,5 +1,5 @@
/* GNU Mailutils -- a suite of utilities for electronic mail
- Copyright (C) 1999-2019 Free Software Foundation, Inc.
+ Copyright (C) 1999-2024 Free Software Foundation, Inc.
GNU Mailutils is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -15,33 +15,103 @@
along with GNU Mailutils. If not, see <http://www.gnu.org/licenses/>. */
#include "mail.h"
+#include <mailutils/folder.h>
-/*
- * folders
- */
+static int
+list_response_printer (void *item, void *data)
+{
+ struct mu_list_response *resp = item;
+
+ mu_printf ("%s", resp->name);
+ if (resp->type & MU_FOLDER_ATTRIBUTE_DIRECTORY)
+ mu_printf ("%c", resp->separator);
+ mu_printf ("\n");
+ return 0;
+}
+
+static int
+show_folders (mu_folder_t folder)
+{
+ mu_list_t list;
+
+ if (mu_folder_is_local (folder))
+ {
+ char *lister = getenv ("LISTER");
+ if (lister && *lister)
+ {
+ char const *path;
+ mu_url_t url;
+ int rc;
+
+ mu_folder_get_url (folder, &url);
+ if ((rc = mu_url_sget_path (url, &path)) == 0)
+ {
+ util_do_command("! %s '%s'", getenv ("LISTER"), path);
+ return 0;
+ }
+ else
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_url_sget_path", NULL, rc);
+ /* Retry using standard folder lister */
+ }
+ }
+ }
+
+ if (mu_folder_list (folder, "", "%", 1, &list) == 0)
+ {
+ mu_list_foreach (list, list_response_printer, NULL);
+ mu_list_destroy (&list);
+ }
+
+ return 0;
+}
int
mail_folders (int argc MU_ARG_UNUSED, char **argv MU_ARG_UNUSED)
{
- char *path;
-
- if (mailvar_get (&path, mailvar_name_folder, mailvar_type_string, 1))
+ int rc;
+ mu_folder_t folder;
+ mu_url_t url;
+ char *folder_path, *temp_folder_path = NULL;
+
+ if (mailvar_get (&folder_path, mailvar_name_folder, mailvar_type_string, 1))
return 1;
- if (path[0] != '/' && path[0] != '~')
+ if (!mu_is_proto (folder_path) && folder_path[0] != '/' &&
+ folder_path[0] != '~')
{
- char *tmp = mu_alloc (strlen (path) + 3);
+ char *tmp = mu_alloc (strlen (folder_path) + 3);
tmp[0] = '~';
tmp[1] = '/';
- strcpy (tmp + 2, path);
- path = util_fullpath (tmp);
+ strcpy (tmp + 2, folder_path);
+ temp_folder_path = util_fullpath (tmp);
+ folder_path = temp_folder_path;
free (tmp);
}
- else
- path = util_fullpath (path);
- util_do_command("! %s '%s'", getenv ("LISTER"), path);
- free (path);
+ rc = mu_url_create (&url, folder_path);
+ if (rc == 0)
+ {
+ rc = util_get_folder (&folder, url, any_folder);
+ if (rc == 0)
+ {
+ url = NULL; /* Prevent double free: folder steals url */
+ rc = show_folders (folder);
+ mu_folder_destroy (&folder);
+ }
+ else
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_get_folder",
+ folder_path, rc);
+ }
+ }
+ else
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_url_create", folder_path, rc);
+ }
- return 0;
+ free (temp_folder_path);
+ mu_url_destroy (&url);
+ return rc;
}
+

Return to:

Send suggestions and report system problems to the System administrator.