]> git.notmuchmail.org Git - notmuch/blob - notmuch-private.h
notmuch dump: Fix the sorting of results.
[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 #ifndef _GNU_SOURCE
27 #define _GNU_SOURCE /* For getline */
28 #endif
29
30 #include <stdio.h>
31 #include <stdlib.h>
32 #include <stdarg.h>
33 #include <sys/types.h>
34 #include <sys/stat.h>
35 #include <sys/mman.h>
36 #include <string.h>
37 #include <errno.h>
38 #include <fcntl.h>
39 #include <unistd.h>
40 #include <ctype.h>
41
42 NOTMUCH_BEGIN_DECLS
43
44 #include <talloc.h>
45
46
47 /* Thanks to Andrew Tridgell's (SAMBA's) talloc for this definition of
48  * unlikely. The talloc source code comes to us via the GNU LGPL v. 3.
49  */
50 /* these macros gain us a few percent of speed on gcc */
51 #if (__GNUC__ >= 3)
52 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
53    as its first argument */
54 #ifndef likely
55 #define likely(x)   __builtin_expect(!!(x), 1)
56 #endif
57 #ifndef unlikely
58 #define unlikely(x) __builtin_expect(!!(x), 0)
59 #endif
60 #else
61 #ifndef likely
62 #define likely(x) (x)
63 #endif
64 #ifndef unlikely
65 #define unlikely(x) (x)
66 #endif
67 #endif
68
69 /* These value numbers are chosen to be sup compatible (for now at
70  * least). */
71
72 typedef enum {
73     NOTMUCH_VALUE_MESSAGE_ID = 0,
74     NOTMUCH_VALUE_THREAD = 1,
75     NOTMUCH_VALUE_DATE = 2
76 } notmuch_value_t;
77
78 /* xutil.c */
79 void *
80 xcalloc (size_t nmemb, size_t size);
81
82 void *
83 xmalloc (size_t size);
84
85 void *
86 xrealloc (void *ptrr, size_t size);
87
88 char *
89 xstrdup (const char *s);
90
91 char *
92 xstrndup (const char *s, size_t n);
93
94 /* message.cc */
95
96 notmuch_message_t *
97 _notmuch_message_create (notmuch_results_t *owner,
98                          notmuch_database_t *notmuch,
99                          unsigned int doc_id);
100
101 /* message-file.c */
102
103 /* XXX: I haven't decided yet whether these will actually get exported
104  * into the public interface in notmuch.h
105  */
106
107 typedef struct _notmuch_message_file notmuch_message_file_t;
108
109 /* Open a file containing a single email message.
110  *
111  * The caller should call notmuch_message_close when done with this.
112  *
113  * Returns NULL if any error occurs.
114  */
115 notmuch_message_file_t *
116 notmuch_message_file_open (const char *filename);
117
118 /* Close a notmuch message preivously opened with notmuch_message_open. */
119 void
120 notmuch_message_file_close (notmuch_message_file_t *message);
121
122 /* Restrict 'message' to only save the named headers.
123  *
124  * When the caller is only interested in a short list of headers,
125  * known in advance, calling this function can avoid wasted time and
126  * memory parsing/saving header values that will never be needed.
127  *
128  * The variable arguments should be a list of const char * with a
129  * final '(const char *) NULL' to terminate the list.
130  *
131  * If this function is called, it must be called before any calls to
132  * notmuch_message_get_header for this message.
133  *
134  * After calling this function, if notmuch_message_get_header is
135  * called with a header name not in this list, then NULL will be
136  * returned even if that header exists in the actual message.
137  */
138 void
139 notmuch_message_file_restrict_headers (notmuch_message_file_t *message, ...);
140
141 /* Identical to notmuch_message_restrict_headers but accepting a va_list. */
142 void
143 notmuch_message_file_restrict_headersv (notmuch_message_file_t *message,
144                                         va_list va_headers);
145
146 /* Get the value of the specified header from the message.
147  *
148  * The header name is case insensitive.
149  *
150  * The returned value is owned by the notmuch message and is valid
151  * only until the message is closed. The caller should copy it if
152  * needing to modify the value or to hold onto it for longer.
153  *
154  * Returns NULL if the message does not contain a header line matching
155  * 'header'.
156  */
157 const char *
158 notmuch_message_file_get_header (notmuch_message_file_t *message,
159                                  const char *header);
160
161 /* date.c */
162
163 /* Parse an RFC 8222 date string to a time_t value.
164  *
165  * The tz_offset argument can be used to also obtain the time-zone
166  * offset, (but can be NULL if the call is not interested in that).
167  *
168  * Returns 0 on error.
169  */
170 time_t
171 notmuch_parse_date (const char *str, int *tz_offset);
172
173 NOTMUCH_END_DECLS
174
175 #endif