[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[mpop-users] [PATCH 4/9] Allow %-escaped strings in maildir and exchange paths



---
 src/delivery.c | 35 +++++++++++++----------------------
 1 file changed, 13 insertions(+), 22 deletions(-)

diff --git a/src/delivery.c b/src/delivery.c
index d81c56a..c68e9ff 100644
--- a/src/delivery.c
+++ b/src/delivery.c
@@ -341,7 +341,7 @@ int delivery_method_maildir_open(delivery_method_t *dm, const char *from,
         pop3_session_t *session, long recv_index, char **errstr)
 {
     maildir_data_t *maildir_data;
-    char *filename;
+    char *filename, *maildir;
     struct timeval tv;
     int fd;
 
@@ -354,12 +354,16 @@ int delivery_method_maildir_open(delivery_method_t *dm, const char *from,
         *errstr = xasprintf(_("cannot get system time: %s"), strerror(errno));
         return DELIVERY_EUNKNOWN;
     }
+    maildir = expand_session_variables(maildir_data->maildir, session, recv_index, from);
+    
     /* See http://cr.yp.to/proto/maildir.html for a description of file name
      * generation. */
-    filename = xasprintf("%stmp%c" PRINTFLLD ".M%06luP" PRINTFLLD "Q%lu.%s",
-				maildir_data->maildir, PATH_SEP, (unsigned long long)tv.tv_sec,
+    filename = xasprintf("%s%ctmp%c" PRINTFLLD ".M%06luP" PRINTFLLD "Q%lu.%s",
+				maildir, PATH_SEP, PATH_SEP, (unsigned long long)tv.tv_sec,
 				(unsigned long)tv.tv_usec, (long long)getpid(), 
 				++maildir_sequence_number, maildir_data->hostname);
+    free(maildir);
+	
     /* Instead of waiting for stat() to return ENOENT, we open() the file with
      * O_CREAT | O_EXCL. There is no point in trying again after some time,
      * because the filename is intended to be unique. If it is not, we should
@@ -423,7 +427,6 @@ int delivery_method_maildir_init(delivery_method_t *dm, void *data,
         char **errstr)
 {
     maildir_data_t *maildir_data;
-    struct stat statdata;
     char hostname[256];
 
     maildir_data = xmalloc(sizeof(maildir_data_t));
@@ -454,13 +457,6 @@ int delivery_method_maildir_init(delivery_method_t *dm, void *data,
     dm->want_from_addr = 0;
     dm->open = delivery_method_maildir_open;
     dm->close = delivery_method_maildir_close;
-    maildir_data->maildir = xastrcat(maildir_data->maildir, "/");
-    if (stat(maildir_data->maildir, &statdata) != 0)
-    {
-        *errstr = xasprintf(_("cannot access %s: %s"), maildir_data->maildir,
-                strerror(errno));
-        return DELIVERY_EUNKNOWN;
-    }
     (void)umask(S_IRWXG | S_IRWXO);
 
     return DELIVERY_EOK;
@@ -503,7 +499,7 @@ int delivery_method_exchange_open(delivery_method_t *dm,
         char **errstr)
 {
     exchange_data_t *exchange_data;
-    char *filename;
+    char *filename, *pickupdir;
     struct timeval tv;
     int fd;
 
@@ -516,13 +512,16 @@ int delivery_method_exchange_open(delivery_method_t *dm,
         *errstr = xasprintf(_("cannot get system time: %s"), strerror(errno));
         return DELIVERY_EUNKNOWN;
     }
+    
+    pickupdir = expand_session_variables(exchange_data->pickupdir, session, recv_index, from);
     /* Choose a unique filename (similar to the maildir method) that ends with
      * ".eml" */
-    filename = xasprintf("%s%s-" PRINTFLLD "-M%06luP" PRINTFLLD "Q%lu-%s.eml", 
-				exchange_data->pickupdir, PACKAGE_NAME,
+    filename = xasprintf("%s%c%s-" PRINTFLLD "-M%06luP" PRINTFLLD "Q%lu-%s.eml", 
+				pickupdir, PATH_SEP, PACKAGE_NAME,
                 (long long)tv.tv_sec, (unsigned long)tv.tv_usec,
                 (long long)getpid(), ++exchange_sequence_number,
                 exchange_data->hostname);
+    free(pickupdir);
 #if W32_NATIVE
     /* Open the file and deny read and write access to other processes, e.g.
      * Exchange */
@@ -587,7 +586,6 @@ int delivery_method_exchange_init(delivery_method_t *dm, void *data,
         char **errstr)
 {
     exchange_data_t *exchange_data;
-    struct stat statdata;
     char hostname[256];
 
     exchange_data = xmalloc(sizeof(exchange_data_t));
@@ -618,13 +616,6 @@ int delivery_method_exchange_init(delivery_method_t *dm, void *data,
     dm->want_from_addr = 0;
     dm->open = delivery_method_exchange_open;
     dm->close = delivery_method_exchange_close;
-    exchange_data->pickupdir = xastrcat(exchange_data->pickupdir, "/");
-    if (stat(exchange_data->pickupdir, &statdata) != 0)
-    {
-        *errstr = xasprintf(_("cannot access %s: %s"),
-                exchange_data->pickupdir, strerror(errno));
-        return DELIVERY_EUNKNOWN;
-    }
     (void)umask(S_IRWXG | S_IRWXO);
 
     return DELIVERY_EOK;
-- 
2.1.1