summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2019-01-21 05:17:56 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-01-21 08:31:37 (GMT)
commitdb7165424199a473265eda5d35f2399e8816e92d (patch) (side-by-side diff)
treec55a57f21f540c45b93f60543bca8bbb24b9bc3a
parent29a837b1126c701191affceb092afbb8de5d5ffc (diff)
downloadmailutils-db7165424199a473265eda5d35f2399e8816e92d.tar.gz
mailutils-db7165424199a473265eda5d35f2399e8816e92d.tar.bz2
Improve folder handling and expansion in mail. Add convenience functions to the library.
* configure.ac: Build libmailutils/wicket * libmailutils/Makefile.am: Likewise. * libmailutils/base/wicket.c: Move file wicket stuff to ... * libmailutils/wicket/file.c: ... here * libmailutils/wicket/noauth.c: New file. * libmailutils/wicket/Makefile.am: New file. * include/mailutils/auth.h (mu_noauth_ticket_create) (mu_noauth_wicket_create): New protos. * include/mailutils/folder.h (mu_folder_attach_ticket) (mu_folder_is_local): New protos. * include/mailutils/mailbox.h (mu_mailbox_attach_ticket): New proto. * include/mailutils/sys/folder.h (_mu_folder): Remove flags. Add new member: is_local. * libmailutils/mailbox/folder.c (mu_folder_create_from_record): Set is_local. (mu_folder_attach_ticket): New function. (mu_folder_is_local): New function. * libmailutils/mailbox/mbx_default.c (mu_mailbox_attach_ticket): New function. * libmailutils/url/create.c: Allow for trailing / in url. * libproto/imap/mbox.c (_imap_mbx_open): Do initial scan. (__imap_msg_get_stream): Initialize clos.size. * libproto/imap/tests/imapfolder.c: Attach ticket to the folder. * mail/cd.c (mail_cd): Expand directory name (~, %, + notations) prior to use. * mail/file.c (mail_file): Attach ticket to the mailbox. * mail/copy.c (append_to_mailbox): Likewise. * mail/mailline.c: Rewrite directory expansion. Implement fully functional folder expansion. * mail/util.c (util_folder_path) (util_outfolder_name): Rewrite using mu_mailbox_expand_name.
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--configure.ac1
-rw-r--r--include/mailutils/auth.h3
-rw-r--r--include/mailutils/folder.h3
-rw-r--r--include/mailutils/mailbox.h2
-rw-r--r--include/mailutils/sys/folder.h5
-rw-r--r--libmailutils/Makefile.am5
-rw-r--r--libmailutils/base/wicket.c253
-rw-r--r--libmailutils/mailbox/folder.c49
-rw-r--r--libmailutils/mailbox/mbx_default.c43
-rw-r--r--libmailutils/url/create.c11
-rw-r--r--libmailutils/wicket/Makefile.am28
-rw-r--r--libmailutils/wicket/file.c266
-rw-r--r--libmailutils/wicket/noauth.c65
-rw-r--r--libproto/imap/mbox.c7
-rw-r--r--libproto/imap/tests/imapfolder.c1
-rw-r--r--mail/cd.c15
-rw-r--r--mail/copy.c1
-rw-r--r--mail/file.c24
-rw-r--r--mail/mailline.c353
-rw-r--r--mail/mailvar.c2
-rw-r--r--mail/util.c133
21 files changed, 771 insertions, 499 deletions
diff --git a/configure.ac b/configure.ac
index 8f44007..0ef4a23 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1522,2 +1522,3 @@ AC_CONFIG_FILES([
libmailutils/url/Makefile
+ libmailutils/wicket/Makefile
libmailutils/Makefile
diff --git a/include/mailutils/auth.h b/include/mailutils/auth.h
index b4a650e..73fa98e 100644
--- a/include/mailutils/auth.h
+++ b/include/mailutils/auth.h
@@ -76,2 +76,5 @@ int mu_wicket_set_get_ticket (mu_wicket_t wicket,
const char *, mu_ticket_t *));
+
+int mu_noauth_ticket_create (mu_ticket_t *pticket);
+int mu_noauth_wicket_create (mu_wicket_t *pwicket);
int mu_file_wicket_create (mu_wicket_t *pwicket, const char *filename);
diff --git a/include/mailutils/folder.h b/include/mailutils/folder.h
index 2d71a0e..1232798 100644
--- a/include/mailutils/folder.h
+++ b/include/mailutils/folder.h
@@ -62,2 +62,5 @@ extern int mu_folder_lsub (mu_folder_t, const char *, const char *,
+extern int mu_folder_attach_ticket (mu_folder_t folder);
+extern int mu_folder_is_local (mu_folder_t folder);
+
/* Match function */
diff --git a/include/mailutils/mailbox.h b/include/mailutils/mailbox.h
index 5c5f4c6..e54ae88 100644
--- a/include/mailutils/mailbox.h
+++ b/include/mailutils/mailbox.h
@@ -74,2 +74,4 @@ extern int mu_mailbox_save_attributes (mu_mailbox_t) MU_DEPRECATED;
+extern int mu_mailbox_attach_ticket (mu_mailbox_t mbox);
+
#define MU_UIDL_LENGTH 70
diff --git a/include/mailutils/sys/folder.h b/include/mailutils/sys/folder.h
index c32835e..050a18f 100644
--- a/include/mailutils/sys/folder.h
+++ b/include/mailutils/sys/folder.h
@@ -30,5 +30,2 @@ extern "C" {
-# define MU_FOLDER_LIST 0
-# define MU_FOLDER_ENUM 1
-
struct _mu_folder
@@ -41,3 +38,3 @@ struct _mu_folder
mu_url_t url;
- int flags;
+ int is_local;
int ref;
diff --git a/libmailutils/Makefile.am b/libmailutils/Makefile.am
index c940d9c..55b6238 100644
--- a/libmailutils/Makefile.am
+++ b/libmailutils/Makefile.am
@@ -20,3 +20,3 @@ SUBDIRS = \
filter locus mailbox mailer mime msgset opt server string stream stdstream\
- property url imapio datetime . tests
+ property url imapio datetime wicket . tests
@@ -51,3 +51,4 @@ libmailutils_la_LIBADD = \
stdstream/libstdstream.la\
- url/liburl.la
+ url/liburl.la\
+ wicket/libwicket.la
diff --git a/libmailutils/base/wicket.c b/libmailutils/base/wicket.c
index c60ddff..22cd2c1 100644
--- a/libmailutils/base/wicket.c
+++ b/libmailutils/base/wicket.c
@@ -21,20 +21,5 @@
-#include <errno.h>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <pwd.h>
-#include <string.h>
#include <stdlib.h>
-#include <stdio.h>
-#include <unistd.h>
-#include <ctype.h>
#include <mailutils/errno.h>
-#include <mailutils/util.h>
-#include <mailutils/mu_auth.h>
-#include <mailutils/stream.h>
-#include <mailutils/cstr.h>
-#include <mailutils/nls.h>
-#include <mailutils/errno.h>
-
#include <mailutils/sys/auth.h>
@@ -137,239 +122 @@ mu_wicket_set_get_ticket (mu_wicket_t wicket,
-
-/* A "file wicket" implementation */
-
-struct file_wicket
-{
- char *filename;
-};
-
-static void
-_file_wicket_destroy (mu_wicket_t wicket)
-{
- struct file_wicket *fw = mu_wicket_get_data (wicket);
- free (fw->filename);
- free (fw);
-}
-
-struct file_ticket
-{
- char *filename;
- char *user;
- mu_url_t tickurl;
-};
-
-static void
-file_ticket_destroy (mu_ticket_t ticket)
-{
- struct file_ticket *ft = mu_ticket_get_data (ticket);
- if (ft)
- {
- free (ft->filename);
- free (ft->user);
- mu_url_destroy (&ft->tickurl);
- free (ft);
- }
-}
-
-int
-file_ticket_get_cred (mu_ticket_t ticket, mu_url_t url, const char *challenge,
- char **pplain, mu_secret_t *psec)
-{
- struct file_ticket *ft = mu_ticket_get_data (ticket);
- int rc = 0;
-
- if (!ft->tickurl)
- {
- rc = mu_wicket_file_match_url (ft->filename, url,
- MU_URL_PARSE_ALL,
- &ft->tickurl);
- if (rc)
- return rc;
- }
- if (pplain)
- {
- if (ft->user)
- {
- *pplain = strdup (ft->user);
- if (!*pplain)
- rc = ENOMEM;
- }
- else
- rc = mu_url_aget_user (ft->tickurl, pplain);
- }
- else
- rc = mu_url_get_secret (ft->tickurl, psec);
- return rc;
-}
-
-static int
-_file_wicket_get_ticket (mu_wicket_t wicket, void *data,
- const char *user, mu_ticket_t *pticket)
-{
- int rc;
- mu_ticket_t ticket;
- struct file_wicket *fw = data;
- struct file_ticket *ft = calloc (1, sizeof (*ft));
- ft->filename = strdup (fw->filename);
- if (!ft->filename)
- {
- free (ft);
- return ENOMEM;
- }
- if (user)
- {
- ft->user = strdup (user);
- if (!ft->user)
- {
- free (ft->filename);
- free (ft);
- return ENOMEM;
- }
- }
- else
- ft->user = NULL;
-
- rc = mu_ticket_create (&ticket, NULL);
- if (rc)
- {
- free (ft->filename);
- free (ft->user);
- free (ft);
- return rc;
- }
-
- mu_ticket_set_destroy (ticket, file_ticket_destroy, NULL);
- mu_ticket_set_data (ticket, ft, NULL);
- mu_ticket_set_get_cred (ticket, file_ticket_get_cred, NULL);
-
- *pticket = ticket;
- return 0;
-}
-
-int
-mu_wicket_stream_match_url (mu_stream_t stream, struct mu_locus_point *loc,
- mu_url_t url, int parse_flags,
- mu_url_t *pticket_url)
-{
- int rc;
- mu_url_t u = NULL;
- char *buf = NULL;
- size_t bufsize = 0;
- size_t len;
- mu_url_t pret = NULL;
- int weight = 0;
- int line = loc->mu_line;
-
- while ((rc = mu_stream_getline (stream, &buf, &bufsize, &len)) == 0
- && len > 0)
- {
- char *p;
- int err;
- int n;
-
- loc->mu_line++;
- p = mu_str_stripws (buf);
-
- /* Skip empty lines and comments. */
- if (*p == 0 || *p == '#')
- continue;
-
- if ((err = mu_url_create_hint (&u, p, parse_flags, NULL)) != 0)
- {
- /* Skip erroneous entry */
- mu_error (_("%s:%u: cannot create URL: %s"),
- loc->mu_file, loc->mu_line, mu_strerror (err));
- continue;
- }
-
- if (!mu_url_has_flag (u, MU_URL_USER|MU_URL_SECRET))
- {
- mu_error (_("%s:%u: URL is missing required parts"),
- loc->mu_file, loc->mu_line);
- mu_url_destroy (&u);
- continue;
- }
-
- if (!mu_url_matches_ticket (u, url, &n))
- {
- mu_url_destroy (&u);
- continue;
- }
-
- if (!pret || n < weight)
- {
- pret = u;
- weight = n;
- line = loc->mu_line;
- if (weight == 0)
- break;
- }
- }
- free (buf);
-
- if (rc == 0)
- {
- if (pret)
- {
- *pticket_url = pret;
- loc->mu_line = line;
- }
- else
- rc = MU_ERR_NOENT;
- }
-
- return rc;
-}
-
-int
-mu_wicket_file_match_url (const char *name, mu_url_t url,
- int parse_flags,
- mu_url_t *pticket_url)
-{
- mu_stream_t stream;
- int rc;
- struct mu_locus_point loc;
-
- rc = mu_file_stream_create (&stream, name, MU_STREAM_READ);
- if (rc)
- return rc;
- loc.mu_file = (char*) name;
- loc.mu_line = 0;
- loc.mu_col = 0;
- rc = mu_wicket_stream_match_url (stream, &loc, url, parse_flags,
- pticket_url);
- mu_stream_close (stream);
- mu_stream_destroy (&stream);
- return rc;
-}
-
-int
-mu_file_wicket_create (mu_wicket_t *pwicket, const char *filename)
-{
- mu_wicket_t wicket;
- int rc;
- struct file_wicket *fw = calloc (1, sizeof (*fw));
-
- if (!fw)
- return ENOMEM;
- fw->filename = strdup (filename);
- if (!fw->filename)
- {
- free (fw);
- return ENOMEM;
- }
-
- rc = mu_wicket_create (&wicket);
- if (rc)
- {
- free (fw->filename);
- free (fw);
- return rc;
- }
- mu_wicket_set_data (wicket, fw);
- mu_wicket_set_destroy (wicket, _file_wicket_destroy);
- mu_wicket_set_get_ticket (wicket, _file_wicket_get_ticket);
- *pwicket = wicket;
- return 0;
-}
-
diff --git a/libmailutils/mailbox/folder.c b/libmailutils/mailbox/folder.c
index 64f997d..6773544 100644
--- a/libmailutils/mailbox/folder.c
+++ b/libmailutils/mailbox/folder.c
@@ -38,3 +38,3 @@
#include <mailutils/imaputil.h>
-
+#include <mailutils/util.h>
#include <mailutils/sys/folder.h>
@@ -123,2 +123,3 @@ mu_folder_create_from_record (mu_folder_t *pfolder, mu_url_t url,
folder->url = url;
+ folder->is_local = record->flags & MU_RECORD_LOCAL;
/* Initialize the internal foilder lock, now so the
@@ -172,2 +173,48 @@ mu_folder_create (mu_folder_t *pfolder, const char *name)
+int
+mu_folder_attach_ticket (mu_folder_t folder)
+{
+ mu_authority_t auth = NULL;
+ int rc = MU_ERR_NOENT;
+
+ if (mu_folder_get_authority (folder, &auth) == 0 && auth)
+ {
+ char *filename = mu_tilde_expansion (mu_ticket_file,
+ MU_HIERARCHY_DELIMITER, NULL);
+ mu_wicket_t wicket;
+
+ mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE1,
+ ("Reading user ticket file %s", filename));
+ if ((rc = mu_file_wicket_create (&wicket, filename)) == 0)
+ {
+ mu_ticket_t ticket;
+
+ if ((rc = mu_wicket_get_ticket (wicket, NULL, &ticket)) == 0)
+ {
+ rc = mu_authority_set_ticket (auth, ticket);
+ mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE1,
+ ("Retrieved and set ticket: %d", rc));
+ }
+ else
+ mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+ ("Error retrieving ticket: %s\n",
+ mu_strerror (rc)));
+ mu_wicket_destroy (&wicket);
+ }
+ else
+ mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
+ ("Error creating wicket: %s\n", mu_strerror (rc)));
+ free (filename);
+ }
+ return rc;
+}
+
+int
+mu_folder_is_local (mu_folder_t folder)
+{
+ if (!folder)
+ return -1;
+ return folder->is_local;
+}
+
/* The folder is destroy if it is the last reference. */
diff --git a/libmailutils/mailbox/mbx_default.c b/libmailutils/mailbox/mbx_default.c
index 29890bf..bd9f876 100644
--- a/libmailutils/mailbox/mbx_default.c
+++ b/libmailutils/mailbox/mbx_default.c
@@ -346,40 +346,11 @@ percent_expand (const char *file, char **mbox)
-static void
-attach_auth_ticket (mu_mailbox_t mbox)
+int
+mu_mailbox_attach_ticket (mu_mailbox_t mbox)
{
+ int rc;
mu_folder_t folder = NULL;
- mu_authority_t auth = NULL;
- if (mu_mailbox_get_folder (mbox, &folder) == 0
- && mu_folder_get_authority (folder, &auth) == 0
- && auth)
- {
- char *filename = mu_tilde_expansion (mu_ticket_file,
- MU_HIERARCHY_DELIMITER, NULL);
- mu_wicket_t wicket;
- int rc;
-
- mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE1,
- ("Reading user ticket file %s", filename));
- if ((rc = mu_file_wicket_create (&wicket, filename)) == 0)
- {
- mu_ticket_t ticket;
-
- if ((rc = mu_wicket_get_ticket (wicket, NULL, &ticket)) == 0)
- {
- rc = mu_authority_set_ticket (auth, ticket);
- mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_TRACE1,
- ("Retrieved and set ticket: %d", rc));
- }
- else
- mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
- ("Error retrieving ticket: %s\n",
- mu_strerror (rc)));
- mu_wicket_destroy (&wicket);
- }
- else
- mu_debug (MU_DEBCAT_MAILBOX, MU_DEBUG_ERROR,
- ("Error creating wicket: %s\n", mu_strerror (rc)));
- free (filename);
- }
+ if ((rc = mu_mailbox_get_folder (mbox, &folder)) == 0)
+ rc = mu_folder_attach_ticket (folder);
+ return rc;
}
@@ -492,3 +463,3 @@ mu_mailbox_create_default (mu_mailbox_t *pmbox, const char *mail)
if (status == 0)
- attach_auth_ticket (*pmbox);
+ mu_mailbox_attach_ticket (*pmbox);
diff --git a/libmailutils/url/create.c b/libmailutils/url/create.c
index 124be32..3b19a4f 100644
--- a/libmailutils/url/create.c
+++ b/libmailutils/url/create.c
@@ -271,3 +271,12 @@ _mu_url_ctx_parse_host (struct mu_url_ctx *ctx, int has_host)
if (has_host)
- ctx->cur++;
+ {
+ ctx->cur++;
+ if (*ctx->cur == 0)
+ {
+ rc = str_assign (&url->path, "");
+ if (rc == 0)
+ url->flags |= MU_URL_PATH;
+ return rc;
+ }
+ }
return _mu_url_ctx_parse_path (ctx);
diff --git a/libmailutils/wicket/Makefile.am b/libmailutils/wicket/Makefile.am
new file mode 100644
index 0000000..b7f3528
--- a/dev/null
+++ b/libmailutils/wicket/Makefile.am
@@ -0,0 +1,28 @@
+# GNU Mailutils -- a suite of utilities for electronic mail
+# Copyright (C) 2010-2019 Free Software Foundation, Inc.
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License as published by the Free Software Foundation; either
+# version 3 of the License, or (at your option) any later version.
+#
+# This library 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
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General
+# Public License along with this library. If not, see
+# <http://www.gnu.org/licenses/>.
+
+noinst_LTLIBRARIES = libwicket.la
+libwicket_la_SOURCES = \
+ file.c\
+ noauth.c
+
+localedir = $(datadir)/locale
+AM_CPPFLAGS = \
+ @MU_LIB_COMMON_INCLUDES@ -I/libmailutils\
+ -DSYSCONFDIR=\"$(sysconfdir)\"\
+ -DSITE_VIRTUAL_PWDDIR=\"@SITE_VIRTUAL_PWDDIR@\"\
+ -DLOCALEDIR=\"$(localedir)\"
diff --git a/libmailutils/wicket/file.c b/libmailutils/wicket/file.c
new file mode 100644
index 0000000..73e7e65
--- a/dev/null
+++ b/libmailutils/wicket/file.c
@@ -0,0 +1,266 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 1999-2019 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+/* A "file wicket" implementation */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <mailutils/errno.h>
+#include <mailutils/error.h>
+#include <mailutils/auth.h>
+#include <mailutils/url.h>
+#include <mailutils/stream.h>
+#include <mailutils/cstr.h>
+#include <mailutils/nls.h>
+
+struct file_wicket
+{
+ char *filename;
+};
+
+static void
+_file_wicket_destroy (mu_wicket_t wicket)
+{
+ struct file_wicket *fw = mu_wicket_get_data (wicket);
+ free (fw->filename);
+ free (fw);
+}
+
+struct file_ticket
+{
+ char *filename;
+ char *user;
+ mu_url_t tickurl;
+};
+
+static void
+file_ticket_destroy (mu_ticket_t ticket)
+{
+ struct file_ticket *ft = mu_ticket_get_data (ticket);
+ if (ft)
+ {
+ free (ft->filename);
+ free (ft->user);
+ mu_url_destroy (&ft->tickurl);
+ free (ft);
+ }
+}
+
+int
+file_ticket_get_cred (mu_ticket_t ticket, mu_url_t url, const char *challenge,
+ char **pplain, mu_secret_t *psec)
+{
+ struct file_ticket *ft = mu_ticket_get_data (ticket);
+ int rc = 0;
+
+ if (!ft->tickurl)
+ {
+ rc = mu_wicket_file_match_url (ft->filename, url,
+ MU_URL_PARSE_ALL,
+ &ft->tickurl);
+ if (rc)
+ return rc;
+ }
+ if (pplain)
+ {
+ if (ft->user)
+ {
+ *pplain = strdup (ft->user);
+ if (!*pplain)
+ rc = ENOMEM;
+ }
+ else
+ rc = mu_url_aget_user (ft->tickurl, pplain);
+ }
+ else
+ rc = mu_url_get_secret (ft->tickurl, psec);
+ return rc;
+}
+
+static int
+_file_wicket_get_ticket (mu_wicket_t wicket, void *data,
+ const char *user, mu_ticket_t *pticket)
+{
+ int rc;
+ mu_ticket_t ticket;
+ struct file_wicket *fw = data;
+ struct file_ticket *ft = calloc (1, sizeof (*ft));
+ ft->filename = strdup (fw->filename);
+ if (!ft->filename)
+ {
+ free (ft);
+ return ENOMEM;
+ }
+ if (user)
+ {
+ ft->user = strdup (user);
+ if (!ft->user)
+ {
+ free (ft->filename);
+ free (ft);
+ return ENOMEM;
+ }
+ }
+ else
+ ft->user = NULL;
+
+ rc = mu_ticket_create (&ticket, NULL);
+ if (rc)
+ {
+ free (ft->filename);
+ free (ft->user);
+ free (ft);
+ return rc;
+ }
+
+ mu_ticket_set_destroy (ticket, file_ticket_destroy, NULL);
+ mu_ticket_set_data (ticket, ft, NULL);
+ mu_ticket_set_get_cred (ticket, file_ticket_get_cred, NULL);
+
+ *pticket = ticket;
+ return 0;
+}
+
+int
+mu_wicket_stream_match_url (mu_stream_t stream, struct mu_locus_point *loc,
+ mu_url_t url, int parse_flags,
+ mu_url_t *pticket_url)
+{
+ int rc;
+ mu_url_t u = NULL;
+ char *buf = NULL;
+ size_t bufsize = 0;
+ size_t len;
+ mu_url_t pret = NULL;
+ int weight = 0;
+ int line = loc->mu_line;
+
+ while ((rc = mu_stream_getline (stream, &buf, &bufsize, &len)) == 0
+ && len > 0)
+ {
+ char *p;
+ int err;
+ int n;
+
+ loc->mu_line++;
+ p = mu_str_stripws (buf);
+
+ /* Skip empty lines and comments. */
+ if (*p == 0 || *p == '#')
+ continue;
+
+ if ((err = mu_url_create_hint (&u, p, parse_flags, NULL)) != 0)
+ {
+ /* Skip erroneous entry */
+ mu_error (_("%s:%u: cannot create URL: %s"),
+ loc->mu_file, loc->mu_line, mu_strerror (err));
+ continue;
+ }
+
+ if (!mu_url_has_flag (u, MU_URL_USER|MU_URL_SECRET))
+ {
+ mu_error (_("%s:%u: URL is missing required parts"),
+ loc->mu_file, loc->mu_line);
+ mu_url_destroy (&u);
+ continue;
+ }
+
+ if (!mu_url_matches_ticket (u, url, &n))
+ {
+ mu_url_destroy (&u);
+ continue;
+ }
+
+ if (!pret || n < weight)
+ {
+ pret = u;
+ weight = n;
+ line = loc->mu_line;
+ if (weight == 0)
+ break;
+ }
+ }
+ free (buf);
+
+ if (rc == 0)
+ {
+ if (pret)
+ {
+ *pticket_url = pret;
+ loc->mu_line = line;
+ }
+ else
+ rc = MU_ERR_NOENT;
+ }
+
+ return rc;
+}
+
+int
+mu_wicket_file_match_url (const char *name, mu_url_t url,
+ int parse_flags,
+ mu_url_t *pticket_url)
+{
+ mu_stream_t stream;
+ int rc;
+ struct mu_locus_point loc;
+
+ rc = mu_file_stream_create (&stream, name, MU_STREAM_READ);
+ if (rc)
+ return rc;
+ loc.mu_file = (char*) name;
+ loc.mu_line = 0;
+ loc.mu_col = 0;
+ rc = mu_wicket_stream_match_url (stream, &loc, url, parse_flags,
+ pticket_url);
+ mu_stream_close (stream);
+ mu_stream_destroy (&stream);
+ return rc;
+}
+
+int
+mu_file_wicket_create (mu_wicket_t *pwicket, const char *filename)
+{
+ mu_wicket_t wicket;
+ int rc;
+ struct file_wicket *fw = calloc (1, sizeof (*fw));
+
+ if (!fw)
+ return ENOMEM;
+ fw->filename = strdup (filename);
+ if (!fw->filename)
+ {
+ free (fw);
+ return ENOMEM;
+ }
+
+ rc = mu_wicket_create (&wicket);
+ if (rc)
+ {
+ free (fw->filename);
+ free (fw);
+ return rc;
+ }
+ mu_wicket_set_data (wicket, fw);
+ mu_wicket_set_destroy (wicket, _file_wicket_destroy);
+ mu_wicket_set_get_ticket (wicket, _file_wicket_get_ticket);
+ *pwicket = wicket;
+ return 0;
+}
diff --git a/libmailutils/wicket/noauth.c b/libmailutils/wicket/noauth.c
new file mode 100644
index 0000000..2a4da10
--- a/dev/null
+++ b/libmailutils/wicket/noauth.c
@@ -0,0 +1,65 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 1999-2019 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library 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
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <stdlib.h>
+#include <mailutils/errno.h>
+#include <mailutils/auth.h>
+
+static int
+noauth_ticket_get_cred (mu_ticket_t ticket, mu_url_t url, const char *challenge,
+ char **pplain, mu_secret_t *psec)
+{
+ return MU_ERR_AUTH_FAILURE;
+}
+
+int
+mu_noauth_ticket_create (mu_ticket_t *pticket)
+{
+ mu_ticket_t ticket;
+ int rc;
+
+ rc = mu_ticket_create (&ticket, NULL);
+ if (rc)
+ return rc;
+ mu_ticket_set_get_cred (ticket, noauth_ticket_get_cred, NULL);
+ *pticket = ticket;
+ return 0;
+}
+
+static int
+noauth_get_ticket (mu_wicket_t wicket, void *data,
+ const char *user, mu_ticket_t *pticket)
+{
+ return mu_noauth_ticket_create (pticket);
+}
+
+int
+mu_noauth_wicket_create (mu_wicket_t *pwicket)
+{
+ mu_wicket_t wicket;
+ int rc;
+
+ rc = mu_wicket_create (&wicket);
+ if (rc)
+ return rc;
+ mu_wicket_set_get_ticket (wicket, noauth_get_ticket);
+ return 0;
+}
diff --git a/libproto/imap/mbox.c b/libproto/imap/mbox.c
index 1442e62..fde568a 100644
--- a/libproto/imap/mbox.c
+++ b/libproto/imap/mbox.c
@@ -185,3 +185,4 @@ __imap_msg_get_stream (struct _mu_imap_message *imsg, size_t msgno,
clos.save_stream = imbx->cache;
-
+ clos.size = 0;
+
rc = mu_msgset_add_range (msgset, msgno, msgno, MU_MSGSET_NUM);
@@ -759,3 +760,5 @@ _imap_mbx_open (mu_mailbox_t mbox, int flags)
rc = _imap_realloc_messages (imbx, imbx->stats.message_count);
-
+
+ _imap_mbx_scan (mbox, 1, NULL);
+
return rc;
diff --git a/libproto/imap/tests/imapfolder.c b/libproto/imap/tests/imapfolder.c
index 6f91b63..8d3f6ce 100644
--- a/libproto/imap/tests/imapfolder.c
+++ b/libproto/imap/tests/imapfolder.c
@@ -204,2 +204,3 @@ main (int argc, char **argv)
}
+ mu_folder_attach_ticket (folder);
diff --git a/mail/cd.c b/mail/cd.c
index cb71b4c..122a1af 100644
--- a/mail/cd.c
+++ b/mail/cd.c
@@ -26,3 +26,4 @@ mail_cd (int argc, char **argv)
{
- char *dir;
+ char *dir, *edir;
+ int rc;
@@ -35,8 +36,14 @@ mail_cd (int argc, char **argv)
- if (chdir (dir))
+ rc = mu_mailbox_expand_name (dir, &edir);
+ if (rc)
{
- mu_diag_funcall (MU_DIAG_ERROR, "chdir", dir, errno);
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_expand_name", dir, rc);
return 1;
}
- return 0;
+
+ rc = chdir (edir);
+ if (rc)
+ mu_diag_funcall (MU_DIAG_ERROR, "chdir", edir, errno);
+ free (edir);
+ return rc;
}
diff --git a/mail/copy.c b/mail/copy.c
index 476b441..15deebe 100644
--- a/mail/copy.c
+++ b/mail/copy.c
@@ -47,2 +47,3 @@ append_to_mailbox (char const *filename, msgset_t *msglist, int mark,
}
+ mu_mailbox_attach_ticket (mbx);
if ((status = mu_mailbox_open (mbx, MU_STREAM_WRITE | MU_STREAM_CREAT)) != 0)
diff --git a/mail/file.c b/mail/file.c
index 517a6b7..bc94f13 100644
--- a/mail/file.c
+++ b/mail/file.c
@@ -32,3 +32,3 @@ mail_expand_name (const char *name)
char *exp = NULL;
-
+
if (strcmp (name, "#") == 0)
@@ -86,5 +86,14 @@ mail_file (int argc, char **argv)
return 1;
-
- if ((status = mu_mailbox_create (&newbox, name)) != 0
- || (status = mu_mailbox_open (newbox, MU_STREAM_RDWR)) != 0)
+
+ status = mu_mailbox_create (&newbox, name);
+ if (status)
+ {
+ mu_error(_("Cannot create mailbox %s: %s"), name,
+ mu_strerror (status));
+ free (name);
+ return 1;
+ }
+ mu_mailbox_attach_ticket (newbox);
+
+ if ((status = mu_mailbox_open (newbox, MU_STREAM_RDWR)) != 0)
{
@@ -98,3 +107,3 @@ mail_file (int argc, char **argv)
page_invalidate (1); /* Invalidate current page map */
-
+
mu_mailbox_get_url (mbox, &url);
@@ -109,3 +118,3 @@ mail_file (int argc, char **argv)
}
-
+
if (prev_name)
@@ -113,3 +122,3 @@ mail_file (int argc, char **argv)
prev_name = pname;
-
+
mbox = newbox;
@@ -130,2 +139 @@ mail_file (int argc, char **argv)
}
-
diff --git a/mail/mailline.c b/mail/mailline.c
index f1fa4b2..1574125 100644
--- a/mail/mailline.c
+++ b/mail/mailline.c
@@ -20,2 +20,3 @@
#include <mailutils/folder.h>
+#include <mailutils/auth.h>
@@ -211,3 +212,3 @@ ml_command_completion (char *cmd, int start, int end)
struct mu_wordsplit ws;
-
+
for (p = rl_line_buffer; p < rl_line_buffer + start && mu_isblank (*p); p++)
@@ -241,3 +242,3 @@ ml_command_completion (char *cmd, int start, int end)
point |= COMPL_LASTARG;
-
+
ret = entry->command_completion (ws.ws_wordc, ws.ws_wordv, point);
@@ -297,3 +298,3 @@ ml_attempted_completion_over (void)
lexicographically. Array B is treated as case-insensitive.
-
+
If either of the arrays is NULL, the other one is returned unchanged.
@@ -314,3 +315,3 @@ compl_concat (char **a, char **b)
int lwr = 0;
-
+
if (a)
@@ -323,3 +324,3 @@ compl_concat (char **a, char **b)
return b;
-
+
if (b)
@@ -330,3 +331,3 @@ compl_concat (char **a, char **b)
mu_strlower (b[bn]);
- }
+ }
}
@@ -337,3 +338,3 @@ compl_concat (char **a, char **b)
j = bn == 1 ? 0 : 1;
-
+
n = (an - i) + (bn - j) + 1;
@@ -358,3 +359,3 @@ compl_concat (char **a, char **b)
free (b[0]);
-
+
k = 1;
@@ -379,3 +380,3 @@ compl_concat (char **a, char **b)
return ret;
-}
+}
@@ -391,3 +392,3 @@ static char *header_generator (const char *text, int state);
object is a mailbox or pipe, where it is a command).
-
+
CLOSURE supplies argument for MATCHES. It is ignored if MATCHES is NULL.
@@ -401,3 +402,3 @@ msglist_closure_compl (int argc, char **argv, int point,
size_t len = strlen (text);
-
+
if (text[0] == ':')
@@ -413,3 +414,3 @@ msglist_closure_compl (int argc, char **argv, int point,
}
-
+
ml_set_completion_append_character (0);
@@ -452,78 +453,179 @@ command_compl (int argc, char **argv, int point)
}
+
+struct filegen
+{
+ mu_list_t list;
+ mu_iterator_t itr;
+ size_t pathlen;
+ char repl;
+ int flags;
+};
-/* Generate file list based on reference prefix TEXT, relative to PATH.
- Remove PATHLEN leading characters from the returned names. Replace
- them with REPL unless it is 0.
+static void
+filegen_free (struct filegen *fg)
+{
+ mu_iterator_destroy (&fg->itr);
+ mu_list_destroy (&fg->list);
+}
- Select only those files that match given FLAGS (MU_FOLDER_ATTRIBUTE_*
- constants).
+enum
+ {
+ any_folder,
+ local_folder
+ };
- STATE is 0 for the first call, 1 otherwise.
- */
-static char *
-file_generator (const char *text, int state,
- char *path, size_t pathlen,
- char repl,
- int flags)
+#define PATHLEN_AUTO ((size_t)-1)
+
+static int
+filegen_init (struct filegen *fg,
+ const char *text,
+ const char *folder_path,
+ int type,
+ size_t pathlen,
+ int repl,
+ int flags)
{
- static mu_list_t list;
- static mu_iterator_t itr;
+ char *pathref;
+ char *wcard;
+ mu_folder_t folder;
+ size_t count, i, len;
+ mu_url_t url;
+ int rc;
- if (!state)
- {
- char *wcard;
- mu_folder_t folder;
- size_t count;
+ pathref = mu_strdup (text);
+ len = strlen (pathref);
+ for (i = len; i > 0; i--)
+ if (pathref[i-1] == '/')
+ break;
+ wcard = mu_alloc (len - i + 2);
+ strcpy (wcard, pathref + i);
+ strcat (wcard, "%");
+ pathref[i] = 0;
- wcard = mu_alloc (strlen (text) + 2);
- strcat (strcpy (wcard, text), "*");
+ rc = mu_folder_create (&folder, folder_path);
+ if (rc)
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_create", folder_path, rc);
+ free (wcard);
+ free (pathref);
+ return -1;
+ }
- if (mu_folder_create (&folder, path))
+ if (!mu_folder_is_local (folder))
+ {
+ if (type == local_folder)
{
+ mu_error ("%s", _("folder must be set to a local folder"));
free (wcard);
- return NULL;
+ free (pathref);
+ return -1;
}
- mu_folder_list (folder, path, wcard, 1, &list);
+ /* Set ticket for a remote folder */
+ rc = mu_folder_attach_ticket (folder);
+ if (rc)
+ {
+ mu_authority_t auth = NULL;
+
+ if (mu_folder_get_authority (folder, &auth) == 0 && auth)
+ {
+ mu_ticket_t tct;
+ mu_noauth_ticket_create (&tct);
+ rc = mu_authority_set_ticket (auth, tct);
+ if (rc)
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_authority_set_ticket",
+ NULL, rc);
+ }
+ }
+ }
+
+ rc = mu_folder_open (folder, MU_STREAM_READ);
+ if (rc)
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_folder_open", folder_path, rc);
free (wcard);
+ free (pathref);
+ return -1;
+ }
+
+ if (mu_folder_get_url (folder, &url))
+ {
+ free (wcard);
+ free (pathref);
mu_folder_destroy (&folder);
+ }
- if (mu_list_count (list, &count) || count == 0)
- {
- mu_list_destroy (&list);
- return NULL;
- }
- else if (count == 1)
- ml_set_completion_append_character (0);
+ if (pathlen == PATHLEN_AUTO)
+ {
+ char const *urlpath;
+
+ mu_url_sget_path (url, &urlpath);
+ fg->pathlen = strlen (urlpath);
+ while (fg->pathlen > 0 && urlpath[fg->pathlen-1] == '/')
+ fg->pathlen--;
+ if (fg->pathlen == 1 && urlpath[0] == '/')
+ fg->pathlen = 0;
+ }
+ else
+ fg->pathlen = pathlen;
- if (mu_list_get_iterator (list, &itr))
+ mu_folder_list (folder, pathref, wcard, 1, &fg->list);
+ free (wcard);
+ free (pathref);
+ mu_folder_destroy (&folder);
+
+ if (mu_list_count (fg->list, &count) || count == 0)
+ {
+ mu_list_destroy (&fg->list);
+ return -1;
+ }
+ else if (count == 1)
+ {
+ if (flags & MU_FOLDER_ATTRIBUTE_DIRECTORY)
{
- mu_list_destroy (&list);
- return NULL;
+ struct mu_list_response *resp;
+ mu_list_head (fg->list, (void**)&resp);
+ if (resp->type & MU_FOLDER_ATTRIBUTE_DIRECTORY)
+ {
+ size_t len = strlen (resp->name);
+ resp->name = mu_realloc (resp->name, len + 2);
+ resp->name[len] = resp->separator;
+ resp->name[len+1] = 0;
+ }
}
- mu_iterator_first (itr);
+ ml_set_completion_append_character (0);
}
- while (!mu_iterator_is_done (itr))
+ if (mu_list_get_iterator (fg->list, &fg->itr))
+ {
+ mu_list_destroy (&fg->list);
+ return -1;
+ }
+ mu_iterator_first (fg->itr);
+ fg->repl = repl;
+ fg->flags = flags;
+ return 0;
+}
+
+static char *
+filegen_next (struct filegen *fg)
+{
+ while (!mu_iterator_is_done (fg->itr))
{
struct mu_list_response *resp;
- mu_iterator_current (itr, (void**)&resp);
- mu_iterator_next (itr);
- if (resp->type & flags)
+ mu_iterator_current (fg->itr, (void**)&resp);
+ mu_iterator_next (fg->itr);
+ if (resp->type & fg->flags)
{
char *ret;
- if (pathlen)
- {
- size_t len = strlen (resp->name + pathlen);
- char *ptr;
-
- ret = mu_alloc (len + (repl ? 1 : 0) + 1);
- ptr = ret;
- if (repl)
- *ptr++ = repl;
- memcpy (ptr, resp->name + pathlen, len);
- ptr[len] = 0;
- }
- else
- ret = mu_strdup (resp->name);
+ size_t len = strlen (resp->name + fg->pathlen);
+ char *ptr;
+
+ ret = mu_alloc (len + (fg->repl ? 1 : 0) + 1);
+ ptr = ret;
+ if (fg->repl)
+ *ptr++ = fg->repl;
+ memcpy (ptr, resp->name + fg->pathlen, len);
+ ptr[len] = 0;
+ // if (resp->type & (fg->flags & MU_FOLDER_ATTRIBUTE_DIRECTORY))
return ret;
@@ -531,4 +633,3 @@ file_generator (const char *text, int state,
}
- mu_iterator_destroy (&itr);
- mu_list_destroy (&list);
+ filegen_free (fg);
return NULL;
@@ -539,4 +640,3 @@ folder_generator (const char *text, int state)
{
- char *ret;
- static size_t pathlen;
+ static struct filegen fg;
@@ -544,3 +644,4 @@ folder_generator (const char *text, int state)
{
- char *path = util_folder_path ("");
+ int rc;
+ char *path = util_folder_path ("+");
if (!path)
@@ -548,11 +649,11 @@ folder_generator (const char *text, int state)
- pathlen = strlen (path);
- ret = file_generator (text, state, path, pathlen, '+',
- MU_FOLDER_ATTRIBUTE_ALL);
+ rc = filegen_init (&fg, text, path,
+ any_folder,
+ PATHLEN_AUTO, '+',
+ MU_FOLDER_ATTRIBUTE_ALL);
free (path);
+ if (rc)
+ return NULL;
}
- else
- ret = file_generator (text, state, NULL, pathlen, '+',
- MU_FOLDER_ATTRIBUTE_ALL);
- return ret;
+ return filegen_next (&fg);
}
@@ -564,3 +665,3 @@ msgtype_generator (const char *text, int state)
meaning body lookup */
- static char types[] = "dnorTtu/";
+ static char types[] = "dnorTtu/";
static int i;
@@ -661,3 +762,3 @@ file_compl (int argc, char **argv, int point)
char *text;
-
+
if (point & COMPL_WS)
@@ -681,3 +782,3 @@ file_compl (int argc, char **argv, int point)
break;
-
+
default:
@@ -686,3 +787,3 @@ file_compl (int argc, char **argv, int point)
}
-
+
return NULL;
@@ -714,5 +815,3 @@ dir_generator (const char *text, int state)
{
- char *ret;
- static size_t pathlen;
- static int repl;
+ static struct filegen fg;
@@ -721,2 +820,7 @@ dir_generator (const char *text, int state)
char *path;
+ char *p;
+ int rc;
+ char repl;
+ size_t pathlen;
+
switch (text[0])
@@ -724,6 +828,10 @@ dir_generator (const char *text, int state)
case '+':
- text++;
- repl = '+';
- path = util_folder_path (text);
- pathlen = strlen (path) - strlen (text);
+ {
+ char *f;
+ repl = '+';
+ f = util_folder_path ("+");
+ pathlen = strlen (f);
+ path = mu_make_file_name (f, text + 1);
+ free (f);
+ }
break;
@@ -734,8 +842,14 @@ dir_generator (const char *text, int state)
{
- path = mu_get_homedir ();
- text += 2;
- pathlen = strlen (path);
- break;
+ char *home = mu_get_homedir ();
+ pathlen = strlen (home);
+ path = mu_make_file_name (home, text + 2);
+ free (home);
}
- /* else FIXME! */
+ else
+ {
+ ml_attempted_completion_over ();
+ return NULL;
+ /* FIXME: implement user-name completion */
+ }
+ break;
@@ -748,15 +862,32 @@ dir_generator (const char *text, int state)
default:
- path = mu_strdup ("./");
- pathlen = 2;
+ {
+ char *cwd = mu_getcwd ();
+ pathlen = strlen (cwd);
+ path = mu_make_file_name (cwd, text);
+ free (cwd);
+ }
repl = 0;
}
-
- ret = file_generator (text, state, path, pathlen, repl,
- MU_FOLDER_ATTRIBUTE_DIRECTORY);
- free (path);
+ p = strrchr (path, '/');
+ if (*p)
+ {
+ if (p[1])
+ *p++ = 0;
+ else
+ p = "";
+ rc = filegen_init (&fg, p, path[0] ? path : "/",
+ local_folder,
+ pathlen, repl,
+ MU_FOLDER_ATTRIBUTE_DIRECTORY);
+ }
+ else
+ {
+ ml_attempted_completion_over ();
+ rc = -1;
+ }
+ if (rc)
+ return NULL;
}
- else
- ret = file_generator (text, state, NULL, pathlen, repl,
- MU_FOLDER_ATTRIBUTE_DIRECTORY);
- return ret;
+
+ return filegen_next (&fg);
}
@@ -803,16 +934,2 @@ alias_compl (int argc, char **argv, int point)
static char *
-mkfilename (const char *dir, const char *file)
-{
- size_t len = strlen (dir) + 1 + strlen (file) + 1;
- char *p = malloc (len);
- if (p)
- {
- strcpy (p, dir);
- strcat (p, "/");
- strcat (p, file);
- }
- return p;
-}
-
-static char *
exec_generator (const char *text, int state)
@@ -879,3 +996,3 @@ exec_generator (const char *text, int state)
{
- char *name = mkfilename (dir, ent->d_name);
+ char *name = mu_make_file_name (dir, ent->d_name);
if (name)
diff --git a/mail/mailvar.c b/mail/mailvar.c
index 206166c..5cdb7f1 100644
--- a/mail/mailvar.c
+++ b/mail/mailvar.c
@@ -291,3 +291,3 @@ struct mailvar_symbol mailvar_tab[] =
"suppresses the printing of the version when first invoked" },
-
+
{ { NULL }, }
diff --git a/mail/util.c b/mail/util.c
index 0475e9e..f5471e7 100644
--- a/mail/util.c
+++ b/mail/util.c
@@ -44,3 +44,3 @@ util_do_command (const char *fmt, ...)
va_list ap;
-
+
va_start (ap, fmt);
@@ -63,3 +63,3 @@ util_do_command (const char *fmt, ...)
free (cmd);
-
+
/* Hitting return i.e. no command, is equivalent to next
@@ -87,3 +87,3 @@ util_do_command (const char *fmt, ...)
argv = ws.ws_wordv + 1;
-
+
/* Special case: a number alone implies "print" */
@@ -110,5 +110,5 @@ util_do_command (const char *fmt, ...)
`d*' or `p4'. */
-
+
char *p;
-
+
for (p = argv[0] + strlen (argv[0]) - 1;
@@ -119,3 +119,3 @@ util_do_command (const char *fmt, ...)
p++;
-
+
if (strlen (p))
@@ -133,6 +133,6 @@ util_do_command (const char *fmt, ...)
}
-
+
entry = mail_find_command (argv[0]);
}
-
+
if (entry)
@@ -185,3 +185,3 @@ util_foreach_msg (int argc, char **argv, int flags,
size_t
-util_range_msg (size_t low, size_t high, int flags,
+util_range_msg (size_t low, size_t high, int flags,
msg_handler_t func, void *data)
@@ -190,3 +190,3 @@ util_range_msg (size_t low, size_t high, int flags,
size_t count, expect_count;
-
+
msgspec.next = NULL;
@@ -219,3 +219,3 @@ util_range_msg (size_t low, size_t high, int flags,
}
-
+
if (util_get_message (mbox, low, &mesg) == 0)
@@ -252,3 +252,3 @@ util_find_entry (void *table, size_t nmemb, size_t size, const char *cmd)
char *p;
-
+
for (p = table, i = 0; i < nmemb; i++, p += size)
@@ -258,3 +258,3 @@ util_find_entry (void *table, size_t nmemb, size_t size, const char *cmd)
int sl = strlen (cp->shortname);
-
+
if (sl > ll && !strncmp (cp->shortname, cmd, sl))
@@ -287,3 +287,3 @@ util_help (void *table, size_t nmemb, size_t size, const char *word)
}
-
+
mu_stream_unref (out);
@@ -315,3 +315,3 @@ util_command_list (void *table, size_t nmemb, size_t size)
int pos = 0;
-
+
for (p = table, i = 0; i < nmemb; i++, p += size)
@@ -337,3 +337,3 @@ util_command_list (void *table, size_t nmemb, size_t size)
else
- mu_printf ("%s ", cmd);
+ mu_printf ("%s ", cmd);
}
@@ -469,31 +469,17 @@ util_folder_path (const char *name)
char *folder;
- char *tmp;
- char *p;
-
+ int rc;
+
if (mailvar_get (&folder, "folder", mailvar_type_string, 1))
return NULL;
-
+
if (!name)
return NULL;
- if (name[0] == '+')
- name++;
-
- if (folder[0] != '/' && folder[0] != '~')
- {
- char *home = mu_get_homedir ();
- tmp = mu_alloc (strlen (home) + 1 +
- strlen (folder) + 1 +
- strlen (name) + 1);
- sprintf (tmp, "%s/%s/%s", home, folder, name);
- }
- else
+
+ rc = mu_mailbox_expand_name (name, &folder);
+ if (rc)
{
- tmp = mu_alloc (strlen (folder) + 1 +
- strlen (name) + 1);
- sprintf (tmp, "%s/%s", folder, name);
+ mu_diag_funcall (MU_DIAG_ERROR, "mailbox_expand_name", name, rc);
+ return NULL;
}
- p = util_fullpath (tmp);
- free (tmp);
-
- return p;
+ return folder;
}
@@ -506,3 +492,3 @@ util_get_sender (int msgno, int strip)
char *buf = NULL, *p;
-
+
mu_mailbox_get_message (mbox, msgno, &msg);
@@ -661,2 +647,4 @@ util_outfolder_name (char *str)
char *outfolder;
+ char *exp;
+ int rc;
@@ -664,3 +652,3 @@ util_outfolder_name (char *str)
return NULL;
-
+
switch (*str)
@@ -669,7 +657,9 @@ util_outfolder_name (char *str)
case '~':
- str = util_fullpath (str);
- break;
-
case '+':
- str = util_folder_path (str);
+ rc = mu_mailbox_expand_name (str, &exp);
+ if (rc)
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_expand_name", str, rc);
+ return NULL;
+ }
break;
@@ -679,6 +669,11 @@ util_outfolder_name (char *str)
{
- char *ns = NULL;
- mu_asprintf (&ns, "%s/%s", outfolder, str);
- str = util_fullpath (ns);
- free (ns);
+ char *s = mu_make_file_name (outfolder, str);
+ rc = mu_mailbox_expand_name (s, &exp);
+ if (rc)
+ {
+ mu_diag_funcall (MU_DIAG_ERROR, "mu_mailbox_expand_name", s, rc);
+ free (s);
+ return NULL;
+ }
+ free (s);
}
@@ -688,3 +683,3 @@ util_outfolder_name (char *str)
- return mu_strdup (str);
+ return exp;
}
@@ -697,3 +692,3 @@ util_save_outgoing (mu_message_t msg, char *savefile)
char *record;
-
+
if (mailvar_get (&record, "record", mailvar_type_string, 0) == 0)
@@ -727,3 +722,3 @@ util_save_outgoing (mu_message_t msg, char *savefile)
mu_mailbox_destroy (&outbox);
-
+
free (filename);
@@ -838,3 +833,3 @@ util_merge_addresses (char **addr_str, const char *value)
return rc;
-
+
if ((rc = mu_address_create (&addr, *addr_str)) != 0)
@@ -849,3 +844,3 @@ util_merge_addresses (char **addr_str, const char *value)
char *val;
-
+
rc = mu_address_aget_printable (addr, &val);
@@ -875,3 +870,3 @@ is_address_field (const char *name)
char **p;
-
+
for (p = address_fields; *p; p++)
@@ -888,3 +883,3 @@ util_header_expand (mu_header_t *phdr)
int errcnt = 0, rc;
-
+
rc = mu_header_create (&hdr, "", 0);
@@ -895,3 +890,3 @@ util_header_expand (mu_header_t *phdr)
}
-
+
mu_header_get_field_count (*phdr, &nfields);
@@ -900,3 +895,3 @@ util_header_expand (mu_header_t *phdr)
const char *name, *value;
-
+
if (mu_header_sget_field_name (*phdr, i, &name))
@@ -906,3 +901,3 @@ util_header_expand (mu_header_t *phdr)
continue;
-
+
if (is_address_field (name))
@@ -913,3 +908,3 @@ util_header_expand (mu_header_t *phdr)
size_t j;
-
+
if (mu_header_sget_value (hdr, name, &s) == 0)
@@ -934,5 +929,5 @@ util_header_expand (mu_header_t *phdr)
char *p = ws.ws_wordv[j];
-
+
if (mailvar_is_true ("inplacealiases"))
- /* If inplacealiases was set, the value was already expanded */
+ /* If inplacealiases was set, the value was already expanded */
exp = p;
@@ -951,3 +946,3 @@ util_header_expand (mu_header_t *phdr)
}
-
+
mu_address_union (&addr, new_addr);
@@ -955,3 +950,3 @@ util_header_expand (mu_header_t *phdr)
}
-
+
if (addr)
@@ -959,3 +954,3 @@ util_header_expand (mu_header_t *phdr)
const char *newvalue;
-
+
rc = mu_address_sget_printable (addr, &newvalue);
@@ -991,3 +986,3 @@ util_get_message (mu_mailbox_t mbox, size_t msgno, mu_message_t *msg)
}
-
+
status = mu_mailbox_get_message (mbox, msgno, msg);
@@ -1062,3 +1057,3 @@ util_get_charset (void)
tmp = getenv ("LANG");
-
+
if (tmp && mu_parse_lc_all (tmp, &lc_all, MU_LC_CSET) == 0)
@@ -1091,3 +1086,3 @@ util_rfc2047_decode (char **value)
free (charset);
-
+
if (rc)
@@ -1126,3 +1121,3 @@ open_pager (size_t lines)
mu_stream_t str;
-
+
if (pagelines && lines > pagelines && (pager = getenv ("PAGER")))

Return to:

Send suggestions and report system problems to the System administrator.