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>
46 xcalloc (size_t nmemb, size_t size);
49 xmalloc (size_t size);
52 xrealloc (void *ptrr, size_t size);
55 xstrdup (const char *s);
58 xstrndup (const char *s, size_t n);
62 /* XXX: I haven't decided yet whether these will actually get exported
63 * into the public interface in notmuch.h
66 typedef struct _notmuch_message notmuch_message_t;
68 /* Open a file containing a single email message.
70 * The caller should call notmuch_message_close when done with this.
72 * Returns NULL if any error occurs.
75 notmuch_message_open (const char *filename);
77 /* Close a notmuch message preivously opened with notmuch_message_open. */
79 notmuch_message_close (notmuch_message_t *message);
81 /* Restrict 'message' to only save the named headers.
83 * When the caller is only interested in a short list of headers,
84 * known in advance, calling this function can avoid wasted time and
85 * memory parsing/saving header values that will never be needed.
87 * The variable arguments should be a list of const char * with a
88 * final '(const char *) NULL' to terminate the list.
90 * If this function is called, it must be called before any calls to
91 * notmuch_message_get_header for this message.
93 * After calling this function, if notmuch_message_get_header is
94 * called with a header name not in this list, then NULL will be
95 * returned even if that header exists in the actual message.
98 notmuch_message_restrict_headers (notmuch_message_t *message, ...);
100 /* Identical to notmuch_message_restrict_headers but accepting a va_list. */
102 notmuch_message_restrict_headersv (notmuch_message_t *message,
105 /* Get the value of the specified header from the message.
107 * The header name is case insensitive.
109 * The returned value is owned by the notmuch message and is valid
110 * only until the message is closed. The caller should copy it if
111 * needing to modify the value or to hold onto it for longer.
113 * Returns NULL if the message does not contain a header line matching
117 notmuch_message_get_header (notmuch_message_t *message,
122 /* Parse an RFC 8222 date string to a time_t value.
124 * The tz_offset argument can be used to also obtain the time-zone
125 * offset, (but can be NULL if the call is not interested in that).
127 * Returns 0 on error.
130 notmuch_parse_date (const char *str, int *tz_offset);