[RFC PATCH 03/14] mailstore can read from maildir: URLs

Ethan Glasser-Camp ethan.glasser.camp at gmail.com
Mon Jun 25 13:41:28 PDT 2012


No code uses this yet.

Signed-off-by: Ethan Glasser-Camp <ethan at betacantrips.com>
---
 lib/mailstore.c |   37 ++++++++++++++++++++++++++++++++++++-
 1 file changed, 36 insertions(+), 1 deletion(-)

diff --git a/lib/mailstore.c b/lib/mailstore.c
index 48acd47..ae02c12 100644
--- a/lib/mailstore.c
+++ b/lib/mailstore.c
@@ -17,14 +17,49 @@
  *
  * Author: Carl Worth <cworth at cworth.org>
  */
+#include <uriparser/Uri.h>
 #include <stdio.h>
 
 #include "notmuch-private.h"
 
+static FILE *
+notmuch_mailstore_basic_open (const char *filename)
+{
+    return fopen (filename, "r");
+}
+
 FILE *
 notmuch_mailstore_open (const char *filename)
 {
-    return fopen (filename, "r");
+    FILE *ret = NULL;
+    UriUriA parsed;
+    UriParserStateA state;
+    state.uri = &parsed;
+    if (uriParseUriA (&state, filename) != URI_SUCCESS) {
+        /* Failure. Fall back to fopen and hope for the best. */
+        ret = notmuch_mailstore_basic_open (filename);
+        goto DONE;
+    }
+
+    if (parsed.scheme.first == NULL) {
+        /* No scheme. Probably not really a URL but just an ordinary filename.
+         * Fall back to fopen for backwards compatibility. */
+        ret = notmuch_mailstore_basic_open (filename);
+        goto DONE;
+    }
+
+    if (0 == strncmp (parsed.scheme.first, "maildir",
+                      parsed.scheme.afterLast-parsed.scheme.first)) {
+        /* Maildir URI of the form maildir:///path/to/file.
+         * We want to fopen("/path/to/file").
+         * pathHead starts at "path/to/file". */
+        ret = notmuch_mailstore_basic_open (parsed.pathHead->text.first - 1);
+        goto DONE;
+    }
+
+DONE:
+    uriFreeUriMembersA (&parsed);
+    return ret;
 }
 
 int
-- 
1.7.9.5



More information about the notmuch mailing list