summaryrefslogtreecommitdiff
path: root/examples/lsf.c
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2005-08-31 09:26:47 +0000
committerSergey Poznyakoff <gray@gnu.org.ua>2005-08-31 09:26:47 +0000
commita00ae31d0ac2144317ded2ccb4805587976679fe (patch)
tree19baf3574a5cdfc928da166a3db283e4a4ed433e /examples/lsf.c
parent11e7b71339537016bbecdaaeb5a6629f4156d6af (diff)
downloadmailutils-a00ae31d0ac2144317ded2ccb4805587976679fe.tar.gz
mailutils-a00ae31d0ac2144317ded2ccb4805587976679fe.tar.bz2
New test program. List folders
Diffstat (limited to 'examples/lsf.c')
-rw-r--r--examples/lsf.c118
1 files changed, 118 insertions, 0 deletions
diff --git a/examples/lsf.c b/examples/lsf.c
new file mode 100644
index 000000000..17737bad2
--- /dev/null
+++ b/examples/lsf.c
@@ -0,0 +1,118 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 2005 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
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ GNU Mailutils is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with GNU Mailutils; if not, write to the Free Software
+ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ MA 02110-1301 USA */
+
+#include <errno.h>
+#include <stdlib.h>
+#include <string.h>
+#include <mailutils/mailutils.h>
+
+#define C(X) do \
+{ \
+ int e; \
+ if ((e = X) != 0) \
+ { \
+ mu_error ("%s failed: %s\n", #X, mu_strerror (e)); \
+ return 1; \
+ } \
+} while (0)
+
+static int
+ls_printer (void *item, void *data)
+{
+ struct mu_list_response *resp = item;
+
+ printf ("%c%c %c %4d %s\n",
+ (resp->type & MU_FOLDER_ATTRIBUTE_DIRECTORY) ? 'd' : '-',
+ (resp->type & MU_FOLDER_ATTRIBUTE_FILE) ? 'f' : '-',
+ resp->separator,
+ resp->level,
+ resp->name);
+ return 0;
+}
+
+int
+ls_folders (char *fname, char *ref, char *pattern, int level)
+{
+ int status;
+ mu_folder_t folder;
+ mu_list_t flist;
+ size_t count;
+
+ status = mu_folder_create (&folder, fname);
+ if (status)
+ {
+ mu_error ("mu_folder_create failed: %s", mu_strerror (status));
+ return 1;
+ }
+
+ status = mu_folder_open (folder, MU_STREAM_READ);
+ if (status)
+ {
+ mu_error ("mu_folder_create failed: %s", mu_strerror (status));
+ return 1;
+ }
+
+ status = mu_folder_list (folder, ref, pattern, level, &flist);
+ switch (status)
+ {
+ case 0:
+ mu_list_count (flist, &count);
+ printf ("Number of folders: %lu\n", (unsigned long) count);
+ mu_list_do (flist, ls_printer, NULL);
+ mu_list_destroy (&flist);
+ break;
+ case MU_ERR_NOENT:
+ printf ("No folders matching %s %s in %s\n", ref, pattern, fname);
+ return 0;
+
+ default:
+ mu_error ("mu_folder_list failed: %s", mu_strerror (status));
+ }
+ return 0;
+}
+
+int
+main (int argc, char *argv[])
+{
+ char *folder;
+ char *ref = NULL;
+ char *pattern = "*";
+ int level = 0;
+
+ switch (argc)
+ {
+ case 5:
+ level = atoi (argv[4]);
+ case 4:
+ pattern = argv[3];
+ case 3:
+ ref = argv[2];
+ case 2:
+ folder = argv[1];
+ break;
+ default:
+ mu_error ("usage: lsf folder [ref] [pattern] [recursion-level]\n");
+ return 1;
+ }
+
+ mu_register_all_mbox_formats ();
+
+ if (!ref)
+ ref = folder;
+ return ls_folders (folder, ref, pattern, level);
+}

Return to:

Send suggestions and report system problems to the System administrator.