httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s.@apache.org
Subject svn commit: r1331072 - in /httpd/mod_mbox/trunk: CHANGES module-2.0/mbox_parse.c
Date Thu, 26 Apr 2012 20:34:32 GMT
Author: sf
Date: Thu Apr 26 20:34:31 2012
New Revision: 1331072

URL: http://svn.apache.org/viewvc?rev=1331072&view=rev
Log:
Try to obtain the list post address from the file .listname if no
List-Post header is found.

PR: 53120
Submitted by: Daniel Shahaf, Stefan Fritsch

Modified:
    httpd/mod_mbox/trunk/CHANGES
    httpd/mod_mbox/trunk/module-2.0/mbox_parse.c

Modified: httpd/mod_mbox/trunk/CHANGES
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/CHANGES?rev=1331072&r1=1331071&r2=1331072&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/CHANGES (original)
+++ httpd/mod_mbox/trunk/CHANGES Thu Apr 26 20:34:31 2012
@@ -1,5 +1,8 @@
 Changes for mod_mbox 0.2
 
+  *) Try to obtain the list post address from the file .listname if no
+     List-Post header is found. PR 53120. [Daniel Shahaf, Stefan Fritsch]
+
   *) Convert mails and From and Subject headers to UTF-8.
      Re-indexing of all mbox files is necessary.  The minimum required httpd
      version is now 2.3.15. PR 48864. PR 52182. PR 52195.

Modified: httpd/mod_mbox/trunk/module-2.0/mbox_parse.c
URL: http://svn.apache.org/viewvc/httpd/mod_mbox/trunk/module-2.0/mbox_parse.c?rev=1331072&r1=1331071&r2=1331072&view=diff
==============================================================================
--- httpd/mod_mbox/trunk/module-2.0/mbox_parse.c (original)
+++ httpd/mod_mbox/trunk/module-2.0/mbox_parse.c Thu Apr 26 20:34:31 2012
@@ -42,6 +42,9 @@
 #include "apr_date.h"
 #include "apr_lib.h"
 
+/* for dirname() */
+#include <libgen.h>
+
 #define OPEN_DBM(r, db, flags, suffix, temp, status) \
     temp = apr_pstrcat(r->pool, r->filename, suffix, NULL); \
     status = apr_dbm_open(&db, temp, flags, APR_OS_DEFAULT, r->pool );
@@ -1120,14 +1123,41 @@ static apr_table_t *fetch_first_headers(
     return table;
 }
 
-char *mbox_get_list_post(request_rec *r, char *path)
+/* Creates fake List-Post header from file generated by:
+ *   printf '%s@%s\n' > PATH/.listname
+ */
+static char *read_listname(char *path, apr_pool_t *p)
 {
     apr_status_t rv;
-    char *fullpath;
     apr_file_t *f;
-    apr_table_t *headers;
+    char buf[256];
+    apr_size_t nread;
+
+    rv = apr_file_open(&f,
+                       apr_pstrcat(p, path, "/.listname", (char*)NULL),
+                       APR_READ, APR_OS_DEFAULT, p);
+    if (rv != APR_SUCCESS) {
+        return NULL;
+    }
+
+    rv = apr_file_read_full(f, buf, sizeof(buf) - 1, &nread);
+    if (rv != APR_EOF) {
+        return NULL;
+    }
+
+    buf[nread] = '\0';
+    if (nread > 0 && buf[--nread] == '\n') {
+        buf[nread] = '\0';
+    }
+    apr_file_close(f);
+    return apr_pstrcat(p, "<mailto:", buf, ">", NULL);
+}
 
-    fullpath = apr_pstrcat(r->pool, r->filename, path, NULL);
+static const char *get_list_post(request_rec *r, char *path, char *fullpath)
+{
+    apr_status_t rv;
+    apr_file_t *f;
+    apr_table_t *headers;
 
     rv = apr_file_open(&f, fullpath, APR_READ, APR_OS_DEFAULT, r->pool);
 
@@ -1136,13 +1166,23 @@ char *mbox_get_list_post(request_rec *r,
     }
 
     headers = fetch_first_headers(r, f);
+    apr_file_close(f);
+
     if (headers == NULL) {
         return NULL;
     }
 
-    apr_file_close(f);
+    return apr_table_get(headers, "List-Post");
+}
+
+char *mbox_get_list_post(request_rec *r, char *path)
+{
+    char *fullpath = apr_pstrcat(r->pool, r->filename, path, NULL);
+    const char *list_post = get_list_post(r, path, fullpath);
 
-    return apr_pstrdup(r->pool, apr_table_get(headers, "List-Post"));
+    if (list_post != NULL)
+        return apr_pstrdup(r->pool, list_post);
+    return read_listname(dirname(fullpath), r->pool);
 }
 
 /**



Mime
View raw message