]> git.notmuchmail.org Git - notmuch/blob - notmuch-private.h
Hook up our fancy new notmuch_parse_date function.
[notmuch] / notmuch-private.h
1 /* notmuch-private.h - Internal interfaces for notmuch.
2  *
3  * Copyright © 2009 Carl Worth
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see http://www.gnu.org/licenses/ .
17  *
18  * Author: Carl Worth <cworth@cworth.org>
19  */
20
21 #ifndef NOTMUCH_PRIVATE_H
22 #define NOTMUCH_PRIVATE_H
23
24 #include "notmuch.h"
25
26 #include <stdio.h>
27 #include <stdlib.h>
28 #include <stdarg.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <sys/mman.h>
32 #include <string.h>
33 #include <errno.h>
34 #include <fcntl.h>
35 #include <unistd.h>
36 #include <ctype.h>
37
38 NOTMUCH_BEGIN_DECLS
39
40 /* xutil.c */
41 void *
42 xcalloc (size_t nmemb, size_t size);
43
44 void *
45 xmalloc (size_t size);
46
47 void *
48 xrealloc (void *ptrr, size_t size);
49
50 char *
51 xstrdup (const char *s);
52
53 char *
54 xstrndup (const char *s, size_t n);
55
56 /* message.c */
57
58 /* XXX: I haven't decided yet whether these will actually get exported
59  * into the public interface in notmuch.h
60  */
61
62 typedef struct _notmuch_message notmuch_message_t;
63
64 /* Open a file containing a single email message.
65  *
66  * The caller should call notmuch_message_close when done with this.
67  *
68  * Returns NULL if any error occurs.
69  */
70 notmuch_message_t *
71 notmuch_message_open (const char *filename);
72
73 /* Close a notmuch message preivously opened with notmuch_message_open. */
74 void
75 notmuch_message_close (notmuch_message_t *message);
76
77 /* Restrict 'message' to only save the named headers.
78  *
79  * When the caller is only interested in a short list of headers,
80  * known in advance, calling this function can avoid wasted time and
81  * memory parsing/saving header values that will never be needed.
82  *
83  * The variable arguments should be a list of const char * with a
84  * final '(const char *) NULL' to terminate the list.
85  *
86  * If this function is called, it must be called before any calls to
87  * notmuch_message_get_header for this message.
88  *
89  * After calling this function, if notmuch_message_get_header is
90  * called with a header name not in this list, then NULL will be
91  * returned even if that header exists in the actual message.
92  */
93 void
94 notmuch_message_restrict_headers (notmuch_message_t *message, ...);
95
96 /* Identical to notmuch_message_restrict_headers but accepting a va_list. */
97 void
98 notmuch_message_restrict_headersv (notmuch_message_t *message,
99                                    va_list va_headers);
100
101 /* Get the value of the specified header from the message.
102  *
103  * The header name is case insensitive.
104  *
105  * The returned value is owned by the notmuch message and is valid
106  * only until the message is closed. The caller should copy it if
107  * needing to modify the value or to hold onto it for longer.
108  *
109  * Returns NULL if the message does not contain a header line matching
110  * 'header'.
111  */
112 const char *
113 notmuch_message_get_header (notmuch_message_t *message,
114                             const char *header);
115
116 /* date.c */
117
118 /* Parse an RFC 8222 date string to a time_t value.
119  *
120  * The tz_offset argument can be used to also obtain the time-zone
121  * offset, (but can be NULL if the call is not interested in that).
122  *
123  * Returns 0 on error.
124  */
125 time_t
126 notmuch_parse_date (const char *str, int *tz_offset);
127
128 NOTMUCH_END_DECLS
129
130 #endif