1 /* notmuch-private.h - Internal interfaces for notmuch.
3 * Copyright © 2009 Carl Worth
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.
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.
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/ .
18 * Author: Carl Worth <cworth@cworth.org>
21 #ifndef NOTMUCH_PRIVATE_H
22 #define NOTMUCH_PRIVATE_H
27 #define _GNU_SOURCE /* For getline */
33 #include <sys/types.h>
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.
50 /* these macros gain us a few percent of speed on gcc */
52 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
53 as its first argument */
55 #define likely(x) __builtin_expect(!!(x), 1)
58 #define unlikely(x) __builtin_expect(!!(x), 0)
65 #define unlikely(x) (x)
71 xcalloc (size_t nmemb, size_t size);
74 xmalloc (size_t size);
77 xrealloc (void *ptrr, size_t size);
80 xstrdup (const char *s);
83 xstrndup (const char *s, size_t n);
88 _notmuch_message_create (notmuch_results_t *owner,
89 notmuch_database_t *notmuch,
94 /* XXX: I haven't decided yet whether these will actually get exported
95 * into the public interface in notmuch.h
98 typedef struct _notmuch_message_file notmuch_message_file_t;
100 /* Open a file containing a single email message.
102 * The caller should call notmuch_message_close when done with this.
104 * Returns NULL if any error occurs.
106 notmuch_message_file_t *
107 notmuch_message_file_open (const char *filename);
109 /* Close a notmuch message preivously opened with notmuch_message_open. */
111 notmuch_message_file_close (notmuch_message_file_t *message);
113 /* Restrict 'message' to only save the named headers.
115 * When the caller is only interested in a short list of headers,
116 * known in advance, calling this function can avoid wasted time and
117 * memory parsing/saving header values that will never be needed.
119 * The variable arguments should be a list of const char * with a
120 * final '(const char *) NULL' to terminate the list.
122 * If this function is called, it must be called before any calls to
123 * notmuch_message_get_header for this message.
125 * After calling this function, if notmuch_message_get_header is
126 * called with a header name not in this list, then NULL will be
127 * returned even if that header exists in the actual message.
130 notmuch_message_file_restrict_headers (notmuch_message_file_t *message, ...);
132 /* Identical to notmuch_message_restrict_headers but accepting a va_list. */
134 notmuch_message_file_restrict_headersv (notmuch_message_file_t *message,
137 /* Get the value of the specified header from the message.
139 * The header name is case insensitive.
141 * The returned value is owned by the notmuch message and is valid
142 * only until the message is closed. The caller should copy it if
143 * needing to modify the value or to hold onto it for longer.
145 * Returns NULL if the message does not contain a header line matching
149 notmuch_message_file_get_header (notmuch_message_file_t *message,
154 /* Parse an RFC 8222 date string to a time_t value.
156 * The tz_offset argument can be used to also obtain the time-zone
157 * offset, (but can be NULL if the call is not interested in that).
159 * Returns 0 on error.
162 notmuch_parse_date (const char *str, int *tz_offset);