dovecot-1.2: Created mail_user_[try_]home_expand(). Used them fo...

dovecot at dovecot.org dovecot at dovecot.org
Sun Aug 31 12:23:48 EEST 2008


details:   http://hg.dovecot.org/dovecot-1.2/rev/b2a258213ee0
changeset: 8137:b2a258213ee0
user:      Timo Sirainen <tss at iki.fi>
date:      Sun Aug 31 12:23:43 2008 +0300
description:
Created mail_user_[try_]home_expand(). Used them for expanding mail directories.

diffstat:

17 files changed, 94 insertions(+), 51 deletions(-)
src/lib-storage/index/cydir/cydir-storage.c      |   10 ++---
src/lib-storage/index/dbox/dbox-storage.c        |   10 ++---
src/lib-storage/index/maildir/maildir-storage.c  |    5 +-
src/lib-storage/index/mbox/mbox-storage.c        |    4 +-
src/lib-storage/index/raw/raw-storage.c          |   10 ++---
src/lib-storage/list/mailbox-list-fs-iter.c      |    4 +-
src/lib-storage/list/mailbox-list-fs.c           |   10 +----
src/lib-storage/list/mailbox-list-maildir-iter.c |    1 
src/lib-storage/list/mailbox-list-maildir.c      |    3 -
src/lib-storage/mail-user.c                      |   19 +++++++++
src/lib-storage/mail-user.h                      |    5 ++
src/lib-storage/mailbox-list-private.h           |    3 +
src/lib-storage/mailbox-list.c                   |   42 +++++++++++++++++-----
src/plugins/mbox-snarf/mbox-snarf-plugin.c       |    7 ++-
src/plugins/trash/trash-plugin.c                 |    1 
src/plugins/virtual/virtual-storage.c            |   10 ++---
src/plugins/zlib/zlib-plugin.c                   |    1 

diffs (truncated from 468 to 300 lines):

diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/index/cydir/cydir-storage.c
--- a/src/lib-storage/index/cydir/cydir-storage.c	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/index/cydir/cydir-storage.c	Sun Aug 31 12:23:43 2008 +0300
@@ -34,10 +34,10 @@ static int cydir_list_iter_is_mailbox(st
 
 static int
 cydir_get_list_settings(struct mailbox_list_settings *list_set,
-			const char *data, enum mail_storage_flags flags,
+			const char *data, struct mail_storage *storage,
 			const char **layout_r, const char **error_r)
 {
-	bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
+	bool debug = (storage->flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
 
 	*layout_r = "fs";
 
@@ -55,8 +55,8 @@ cydir_get_list_settings(struct mailbox_l
 
 	if (debug)
 		i_info("cydir: data=%s", data);
-	return mailbox_list_settings_parse(data, list_set, layout_r, NULL,
-					   error_r);
+	return mailbox_list_settings_parse(data, list_set, storage->ns,
+					   layout_r, NULL, error_r);
 }
 
 static struct mail_storage *cydir_alloc(void)
@@ -80,7 +80,7 @@ static int cydir_create(struct mail_stor
 	struct stat st;
 	const char *layout;
 
-	if (cydir_get_list_settings(&list_set, data, _storage->flags,
+	if (cydir_get_list_settings(&list_set, data, _storage,
 				    &layout, error_r) < 0)
 		return -1;
 	list_set.mail_storage_flags = &_storage->flags;
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/index/dbox/dbox-storage.c
--- a/src/lib-storage/index/dbox/dbox-storage.c	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/index/dbox/dbox-storage.c	Sun Aug 31 12:23:43 2008 +0300
@@ -46,11 +46,11 @@ static int dbox_list_iter_is_mailbox(str
 
 static int
 dbox_get_list_settings(struct mailbox_list_settings *list_set,
-		       const char *data, enum mail_storage_flags flags,
+		       const char *data, struct mail_storage *storage,
 		       const char **layout_r, const char **alt_dir_r,
 		       const char **error_r)
 {
-	bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
+	bool debug = (storage->flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
 
 	*layout_r = "fs";
 
@@ -68,8 +68,8 @@ dbox_get_list_settings(struct mailbox_li
 
 	if (debug)
 		i_info("dbox: data=%s", data);
-	return mailbox_list_settings_parse(data, list_set, layout_r, alt_dir_r,
-					   error_r);
+	return mailbox_list_settings_parse(data, list_set, storage->ns,
+					   layout_r, alt_dir_r, error_r);
 }
 
 static struct mail_storage *dbox_alloc(void)
@@ -93,7 +93,7 @@ static int dbox_create(struct mail_stora
 	struct stat st;
 	const char *layout, *alt_dir;
 
-	if (dbox_get_list_settings(&list_set, data, _storage->flags,
+	if (dbox_get_list_settings(&list_set, data, _storage,
 				   &layout, &alt_dir, error_r) < 0)
 		return -1;
 	list_set.mail_storage_flags = &_storage->flags;
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/index/maildir/maildir-storage.c
--- a/src/lib-storage/index/maildir/maildir-storage.c	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/index/maildir/maildir-storage.c	Sun Aug 31 12:23:43 2008 +0300
@@ -5,7 +5,6 @@
 #include "array.h"
 #include "hostpid.h"
 #include "str.h"
-#include "home-expand.h"
 #include "mkdir-parents.h"
 #include "unlink-directory.h"
 #include "unlink-old-files.h"
@@ -109,8 +108,8 @@ maildir_get_list_settings(struct mailbox
 	} else {
 		if (debug)
 			i_info("maildir: data=%s", data);
-		if (mailbox_list_settings_parse(data, list_set, layout_r, NULL,
-						error_r) < 0)
+		if (mailbox_list_settings_parse(data, list_set, storage->ns,
+						layout_r, NULL, error_r) < 0)
 			return -1;
 	}
 
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/index/mbox/mbox-storage.c
--- a/src/lib-storage/index/mbox/mbox-storage.c	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/index/mbox/mbox-storage.c	Sun Aug 31 12:23:43 2008 +0300
@@ -7,7 +7,6 @@
 #include "restrict-access.h"
 #include "mkdir-parents.h"
 #include "unlink-directory.h"
-#include "home-expand.h"
 #include "mbox-storage.h"
 #include "mbox-lock.h"
 #include "mbox-file.h"
@@ -313,7 +312,7 @@ mbox_get_list_settings(struct mailbox_li
 		if ((flags & MAIL_STORAGE_FLAG_NO_AUTODETECTION) == 0 &&
 		    p == NULL && data[strlen(data)-1] != '/') {
 			/* if the data points to a file, treat it as an INBOX */
-			data = home_expand(data);
+			data = mail_user_home_expand(storage->ns->user, data);
 			if (stat(data, &st) < 0 || S_ISDIR(st.st_mode))
 				list_set->root_dir = data;
 			else {
@@ -322,6 +321,7 @@ mbox_get_list_settings(struct mailbox_li
 			}
 		} else {
 			if (mailbox_list_settings_parse(data, list_set,
+							storage->ns,
 							layout_r, NULL,
 							error_r) < 0)
 				return -1;
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/index/raw/raw-storage.c
--- a/src/lib-storage/index/raw/raw-storage.c	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/index/raw/raw-storage.c	Sun Aug 31 12:23:43 2008 +0300
@@ -27,10 +27,10 @@ static int raw_list_iter_is_mailbox(stru
 
 static int
 raw_get_list_settings(struct mailbox_list_settings *list_set,
-		      const char *data, enum mail_storage_flags flags,
+		      const char *data, struct mail_storage *storage,
 		      const char **layout_r, const char **error_r)
 {
-	bool debug = (flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
+	bool debug = (storage->flags & MAIL_STORAGE_FLAG_DEBUG) != 0;
 
 	*layout_r = "fs";
 
@@ -48,8 +48,8 @@ raw_get_list_settings(struct mailbox_lis
 
 	if (debug)
 		i_info("raw: data=%s", data);
-	return mailbox_list_settings_parse(data, list_set, layout_r, NULL,
-					   error_r);
+	return mailbox_list_settings_parse(data, list_set, storage->ns,
+					   layout_r, NULL, error_r);
 }
 
 static struct mail_storage *raw_alloc(void)
@@ -73,7 +73,7 @@ static int raw_create(struct mail_storag
 	struct stat st;
 	const char *layout;
 
-	if (raw_get_list_settings(&list_set, data, _storage->flags,
+	if (raw_get_list_settings(&list_set, data, _storage,
 				  &layout, error_r) < 0)
 		return -1;
 	list_set.mail_storage_flags = &_storage->flags;
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/list/mailbox-list-fs-iter.c
--- a/src/lib-storage/list/mailbox-list-fs-iter.c	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/list/mailbox-list-fs-iter.c	Sun Aug 31 12:23:43 2008 +0300
@@ -2,7 +2,6 @@
 
 #include "lib.h"
 #include "array.h"
-#include "home-expand.h"
 #include "unlink-directory.h"
 #include "imap-match.h"
 #include "mailbox-tree.h"
@@ -199,7 +198,8 @@ static const char *list_get_rootdir(stru
 					last = p;
 			}
 			name = p = t_strdup_until(name, last+1);
-			if (home_try_expand(&name) == 0) {
+			if (mailbox_list_try_get_absolute_path(ctx->ctx.list,
+							       &name)) {
 				*vpath = p;
 				return name;
 			}
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/list/mailbox-list-fs.c
--- a/src/lib-storage/list/mailbox-list-fs.c	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/list/mailbox-list-fs.c	Sun Aug 31 12:23:43 2008 +0300
@@ -2,7 +2,6 @@
 
 #include "lib.h"
 #include "hostpid.h"
-#include "home-expand.h"
 #include "mkdir-parents.h"
 #include "subscription-file.h"
 #include "mailbox-list-fs.h"
@@ -140,7 +139,6 @@ fs_list_get_path(struct mailbox_list *_l
 fs_list_get_path(struct mailbox_list *_list, const char *name,
 		 enum mailbox_list_path_type type)
 {
-	struct fs_mailbox_list *list = (struct fs_mailbox_list *)_list;
 	const struct mailbox_list_settings *set = &_list->set;
 
 	if (name == NULL) {
@@ -161,12 +159,8 @@ fs_list_get_path(struct mailbox_list *_l
 
 	i_assert(mailbox_list_is_valid_pattern(_list, name));
 
-	if ((list->list.flags & MAILBOX_LIST_FLAG_FULL_FS_ACCESS) != 0 &&
-	    (*name == '/' || *name == '~')) {
-		if (home_try_expand(&name) == 0)
-			return name;
-		/* fallback to using ~dir */
-	}
+	if (mailbox_list_try_get_absolute_path(_list, &name))
+		return name;
 
 	switch (type) {
 	case MAILBOX_LIST_PATH_TYPE_DIR:
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/list/mailbox-list-maildir-iter.c
--- a/src/lib-storage/list/mailbox-list-maildir-iter.c	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/list/mailbox-list-maildir-iter.c	Sun Aug 31 12:23:43 2008 +0300
@@ -2,7 +2,6 @@
 
 #include "lib.h"
 #include "str.h"
-#include "home-expand.h"
 #include "imap-match.h"
 #include "mailbox-tree.h"
 #include "mailbox-list-subscriptions.h"
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/list/mailbox-list-maildir.c
--- a/src/lib-storage/list/mailbox-list-maildir.c	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/list/mailbox-list-maildir.c	Sun Aug 31 12:23:43 2008 +0300
@@ -3,7 +3,6 @@
 #include "lib.h"
 #include "array.h"
 #include "hostpid.h"
-#include "home-expand.h"
 #include "subscription-file.h"
 #include "mailbox-list-maildir.h"
 
@@ -71,7 +70,7 @@ maildir_list_get_absolute_path(struct ma
 {
 	const char *p;
 
-	if (home_try_expand(&name) < 0) {
+	if (!mailbox_list_try_get_absolute_path(list, &name)) {
 		/* fallback to using as ~name */
 		return name;
 	}
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/mail-user.c
--- a/src/lib-storage/mail-user.c	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/mail-user.c	Sun Aug 31 12:23:43 2008 +0300
@@ -41,3 +41,22 @@ void mail_user_deinit(struct mail_user *
 	*_user = NULL;
 	user->v.deinit(user);
 }
+
+const char *mail_user_home_expand(struct mail_user *user, const char *path)
+{
+	(void)mail_user_try_home_expand(user, &path);
+	return path;
+}
+
+int mail_user_try_home_expand(struct mail_user *user, const char **pathp)
+{
+	const char *path = *pathp;
+
+	if (path[0] == '~' && (path[1] == '/' || path[1] == '\0')) {
+		if (user->home == NULL)
+			return -1;
+
+		*pathp = t_strconcat(user->home, path + 1, NULL);
+	}
+	return 0;
+}
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/mail-user.h
--- a/src/lib-storage/mail-user.h	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/mail-user.h	Sun Aug 31 12:23:43 2008 +0300
@@ -36,4 +36,9 @@ struct mail_user *mail_user_init(const c
 struct mail_user *mail_user_init(const char *username, const char *home);
 void mail_user_deinit(struct mail_user **user);
 
+/* Replace ~/ at the beginning of the path with the user's home directory. */
+const char *mail_user_home_expand(struct mail_user *user, const char *path);
+/* Returns 0 if ok, -1 if home directory isn't set. */
+int mail_user_try_home_expand(struct mail_user *user, const char **path);
+
 #endif
diff -r 285f636884dc -r b2a258213ee0 src/lib-storage/mailbox-list-private.h
--- a/src/lib-storage/mailbox-list-private.h	Sun Aug 31 11:50:27 2008 +0300
+++ b/src/lib-storage/mailbox-list-private.h	Sun Aug 31 12:23:43 2008 +0300
@@ -116,6 +116,7 @@ void mailbox_lists_deinit(void);
 
 int mailbox_list_settings_parse(const char *data,
 				struct mailbox_list_settings *set,
+				struct mail_namespace *ns,
 				const char **layout, const char **alt_dir_r,
 				const char **error_r);
 
@@ -127,6 +128,8 @@ void mailbox_list_iter_update(struct mai
 
 bool mailbox_list_name_is_too_large(const char *name, char sep);
 enum mailbox_list_file_type mailbox_list_get_file_type(const struct dirent *d);
+bool mailbox_list_try_get_absolute_path(struct mailbox_list *list,


More information about the dovecot-cvs mailing list