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
26 #define _GNU_SOURCE /* For getline */
31 #include <sys/types.h>
44 xcalloc (size_t nmemb, size_t size);
47 xmalloc (size_t size);
50 xrealloc (void *ptrr, size_t size);
53 xstrdup (const char *s);
56 xstrndup (const char *s, size_t n);
60 /* XXX: I haven't decided yet whether these will actually get exported
61 * into the public interface in notmuch.h
64 typedef struct _notmuch_message notmuch_message_t;
66 /* Open a file containing a single email message.
68 * The caller should call notmuch_message_close when done with this.
70 * Returns NULL if any error occurs.
73 notmuch_message_open (const char *filename);
75 /* Close a notmuch message preivously opened with notmuch_message_open. */
77 notmuch_message_close (notmuch_message_t *message);
79 /* Restrict 'message' to only save the named headers.
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.
85 * The variable arguments should be a list of const char * with a
86 * final '(const char *) NULL' to terminate the list.
88 * If this function is called, it must be called before any calls to
89 * notmuch_message_get_header for this message.
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.
96 notmuch_message_restrict_headers (notmuch_message_t *message, ...);
98 /* Identical to notmuch_message_restrict_headers but accepting a va_list. */
100 notmuch_message_restrict_headersv (notmuch_message_t *message,
103 /* Get the value of the specified header from the message.
105 * The header name is case insensitive.
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.
111 * Returns NULL if the message does not contain a header line matching
115 notmuch_message_get_header (notmuch_message_t *message,
120 /* Parse an RFC 8222 date string to a time_t value.
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).
125 * Returns 0 on error.
128 notmuch_parse_date (const char *str, int *tz_offset);