1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
| | /* mailstore.c - code to access individual messages
*
* Copyright © 2009 Carl Worth
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see http://www.gnu.org/licenses/ .
*
* Author: Carl Worth <cworth@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)
{
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
notmuch_mailstore_close (FILE *file)
{
return fclose (file);
}
|