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
25 #define _GNU_SOURCE /* For getline */
35 #include <sys/types.h>
48 /* Thanks to Andrew Tridgell's (SAMBA's) talloc for this definition of
49 * unlikely. The talloc source code comes to us via the GNU LGPL v. 3.
51 /* these macros gain us a few percent of speed on gcc */
53 /* the strange !! is to ensure that __builtin_expect() takes either 0 or 1
54 as its first argument */
56 #define likely(x) __builtin_expect(!!(x), 1)
59 #define unlikely(x) __builtin_expect(!!(x), 0)
66 #define unlikely(x) (x)
70 /* These value numbers are chosen to be sup compatible (for now at
74 NOTMUCH_VALUE_MESSAGE_ID = 0,
75 NOTMUCH_VALUE_THREAD = 1,
76 NOTMUCH_VALUE_DATE = 2
79 /* Xapian (with flint backend) complains if we provide a term longer
80 * than this, but I haven't yet found a way to query the limit
81 * programmatically. */
82 #define NOTMUCH_TERM_MAX 245
84 typedef enum _notmuch_private_status {
85 /* First, copy all the public status values. */
86 NOTMUCH_PRIVATE_STATUS_SUCCESS = NOTMUCH_STATUS_SUCCESS,
87 NOTMUCH_PRIVATE_STATUS_XAPIAN_EXCEPTION = NOTMUCH_STATUS_XAPIAN_EXCEPTION,
88 NOTMUCH_PRIVATE_STATUS_FILE_NOT_EMAIL = NOTMUCH_STATUS_FILE_NOT_EMAIL,
89 NOTMUCH_PRIVATE_STATUS_NULL_POINTER = NOTMUCH_STATUS_NULL_POINTER,
90 NOTMUCH_PRIVATE_STATUS_TAG_TOO_LONG = NOTMUCH_STATUS_TAG_TOO_LONG,
92 /* Then add our own private values. */
93 NOTMUCH_PRIVATE_STATUS_TERM_TOO_LONG,
94 NOTMUCH_PRIVATE_STATUS_NO_DOCUMENT_FOUND,
96 NOTMUCH_PRIVATE_STATUS_LAST_STATUS
97 } notmuch_private_status_t;
102 _notmuch_message_create (const void *talloc_owner,
103 notmuch_database_t *notmuch,
104 unsigned int doc_id);
107 _notmuch_message_create_for_message_id (const void *talloc_owner,
108 notmuch_database_t *notmuch,
109 const char *message_id);
111 /* Lookup a prefix value by name.
113 * XXX: This should really be static inside of message.cc, and we can
114 * do that once we convert database.cc to use the
115 * _notmuch_message_add/remove_term functions. */
117 _find_prefix (const char *name);
119 notmuch_private_status_t
120 _notmuch_message_add_term (notmuch_message_t *message,
121 const char *prefix_name,
124 notmuch_private_status_t
125 _notmuch_message_remove_term (notmuch_message_t *message,
126 const char *prefix_name,
130 _notmuch_message_set_filename (notmuch_message_t *message,
131 const char *filename);
134 _notmuch_message_add_thread_id (notmuch_message_t *message,
135 const char *thread_id);
138 _notmuch_message_ensure_thread_id (notmuch_message_t *message);
141 _notmuch_message_set_date (notmuch_message_t *message,
145 _notmuch_message_sync (notmuch_message_t *message);
149 /* XXX: I haven't decided yet whether these will actually get exported
150 * into the public interface in notmuch.h
153 typedef struct _notmuch_message_file notmuch_message_file_t;
155 /* Open a file containing a single email message.
157 * The caller should call notmuch_message_close when done with this.
159 * Returns NULL if any error occurs.
161 notmuch_message_file_t *
162 notmuch_message_file_open (const char *filename);
164 /* Close a notmuch message preivously opened with notmuch_message_open. */
166 notmuch_message_file_close (notmuch_message_file_t *message);
168 /* Restrict 'message' to only save the named headers.
170 * When the caller is only interested in a short list of headers,
171 * known in advance, calling this function can avoid wasted time and
172 * memory parsing/saving header values that will never be needed.
174 * The variable arguments should be a list of const char * with a
175 * final '(const char *) NULL' to terminate the list.
177 * If this function is called, it must be called before any calls to
178 * notmuch_message_get_header for this message.
180 * After calling this function, if notmuch_message_get_header is
181 * called with a header name not in this list, then NULL will be
182 * returned even if that header exists in the actual message.
185 notmuch_message_file_restrict_headers (notmuch_message_file_t *message, ...);
187 /* Identical to notmuch_message_restrict_headers but accepting a va_list. */
189 notmuch_message_file_restrict_headersv (notmuch_message_file_t *message,
192 /* Get the value of the specified header from the message.
194 * The header name is case insensitive.
196 * The returned value is owned by the notmuch message and is valid
197 * only until the message is closed. The caller should copy it if
198 * needing to modify the value or to hold onto it for longer.
200 * Returns NULL if the message does not contain a header line matching
204 notmuch_message_file_get_header (notmuch_message_file_t *message,
209 /* Parse an RFC 8222 date string to a time_t value.
211 * The tz_offset argument can be used to also obtain the time-zone
212 * offset, (but can be NULL if the call is not interested in that).
214 * Returns 0 on error.
217 notmuch_parse_date (const char *str, int *tz_offset);
222 notmuch_sha1_of_string (const char *str);
225 notmuch_sha1_of_file (const char *filename);