]> git.notmuchmail.org Git - notmuch/blob - notmuch-private.h
Rework message parsing to use getline rather than mmap.
[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 #define _GNU_SOURCE /* For getline */
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <stdarg.h>
31 #include <sys/types.h>
32 #include <sys/stat.h>
33 #include <sys/mman.h>
34 #include <string.h>
35 #include <errno.h>
36 #include <fcntl.h>
37 #include <unistd.h>
38 #include <ctype.h>
39
40 NOTMUCH_BEGIN_DECLS
41
42 /* xutil.c */
43 void *
44 xcalloc (size_t nmemb, size_t size);
45
46 void *
47 xmalloc (size_t size);
48
49 void *
50 xrealloc (void *ptrr, size_t size);
51
52 char *
53 xstrdup (const char *s);
54
55 char *
56 xstrndup (const char *s, size_t n);
57
58 /* message.c */
59
60 /* XXX: I haven't decided yet whether these will actually get exported
61  * into the public interface in notmuch.h
62  */
63
64 typedef struct _notmuch_message notmuch_message_t;
65
66 /* Open a file containing a single email message.
67  *
68  * The caller should call notmuch_message_close when done with this.
69  *
70  * Returns NULL if any error occurs.
71  */
72 notmuch_message_t *
73 notmuch_message_open (const char *filename);
74
75 /* Close a notmuch message preivously opened with notmuch_message_open. */
76 void
77 notmuch_message_close (notmuch_message_t *message);
78
79 /* Restrict 'message' to only save the named headers.
80  *
81  * When the caller is only interested in a short list of headers,
82  * known in advance, calling this function can avoid wasted time and
83  * memory parsing/saving header values that will never be needed.
84  *
85  * The variable arguments should be a list of const char * with a
86  * final '(const char *) NULL' to terminate the list.
87  *
88  * If this function is called, it must be called before any calls to
89  * notmuch_message_get_header for this message.
90  *
91  * After calling this function, if notmuch_message_get_header is
92  * called with a header name not in this list, then NULL will be
93  * returned even if that header exists in the actual message.
94  */
95 void
96 notmuch_message_restrict_headers (notmuch_message_t *message, ...);
97
98 /* Identical to notmuch_message_restrict_headers but accepting a va_list. */
99 void
100 notmuch_message_restrict_headersv (notmuch_message_t *message,
101                                    va_list va_headers);
102
103 /* Get the value of the specified header from the message.
104  *
105  * The header name is case insensitive.
106  *
107  * The returned value is owned by the notmuch message and is valid
108  * only until the message is closed. The caller should copy it if
109  * needing to modify the value or to hold onto it for longer.
110  *
111  * Returns NULL if the message does not contain a header line matching
112  * 'header'.
113  */
114 const char *
115 notmuch_message_get_header (notmuch_message_t *message,
116                             const char *header);
117
118 /* date.c */
119
120 /* Parse an RFC 8222 date string to a time_t value.
121  *
122  * The tz_offset argument can be used to also obtain the time-zone
123  * offset, (but can be NULL if the call is not interested in that).
124  *
125  * Returns 0 on error.
126  */
127 time_t
128 notmuch_parse_date (const char *str, int *tz_offset);
129
130 NOTMUCH_END_DECLS
131
132 #endif