X-Git-Url: https://git.notmuchmail.org/git?a=blobdiff_plain;f=lib%2Fmessage-file.c;h=d7acf0d5b4e2739eac56756c1ca35f30eeacf424;hb=4ce7591610444a1c5ef6f56b57af8e180437fa62;hp=eda1b748e2022d73d2d8737f04151f342e0787ad;hpb=df8885f62c13f77b2b16cbb211e3a727945870b0;p=notmuch diff --git a/lib/message-file.c b/lib/message-file.c index eda1b748..d7acf0d5 100644 --- a/lib/message-file.c +++ b/lib/message-file.c @@ -13,7 +13,7 @@ * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License - * along with this program. If not, see http://www.gnu.org/licenses/ . + * along with this program. If not, see https://www.gnu.org/licenses/ . * * Author: Carl Worth */ @@ -37,27 +37,6 @@ struct _notmuch_message_file { GMimeMessage *message; }; -static int -strcase_equal (const void *a, const void *b) -{ - return strcasecmp (a, b) == 0; -} - -static unsigned int -strcase_hash (const void *ptr) -{ - const char *s = ptr; - - /* This is the djb2 hash. */ - unsigned int hash = 5381; - while (s && *s) { - hash = ((hash << 5) + hash) + tolower (*s); - s++; - } - - return hash; -} - static int _notmuch_message_file_destructor (notmuch_message_file_t *message) { @@ -76,7 +55,8 @@ _notmuch_message_file_destructor (notmuch_message_file_t *message) /* Create a new notmuch_message_file_t for 'filename' with 'ctx' as * the talloc owner. */ notmuch_message_file_t * -_notmuch_message_file_open_ctx (void *ctx, const char *filename) +_notmuch_message_file_open_ctx (notmuch_database_t *notmuch, + void *ctx, const char *filename) { notmuch_message_file_t *message; @@ -98,16 +78,18 @@ _notmuch_message_file_open_ctx (void *ctx, const char *filename) return message; FAIL: - fprintf (stderr, "Error opening %s: %s\n", filename, strerror (errno)); + _notmuch_database_log (notmuch, "Error opening %s: %s\n", + filename, strerror (errno)); _notmuch_message_file_close (message); return NULL; } notmuch_message_file_t * -_notmuch_message_file_open (const char *filename) +_notmuch_message_file_open (notmuch_database_t *notmuch, + const char *filename) { - return _notmuch_message_file_open_ctx (NULL, filename); + return _notmuch_message_file_open_ctx (notmuch, NULL, filename); } void @@ -170,25 +152,12 @@ _notmuch_message_file_parse (notmuch_message_file_t *message) goto DONE; } - if (is_mbox) { - if (! g_mime_parser_eos (parser)) { - /* This is a multi-message mbox. */ - status = NOTMUCH_STATUS_FILE_NOT_EMAIL; - goto DONE; - } + if (is_mbox && ! g_mime_parser_eos (parser)) { /* - * For historical reasons, we support single-message mboxes, - * but this behavior is likely to change in the future, so - * warn. + * This is a multi-message mbox. (For historical reasons, we + * do support single-message mboxes.) */ - static notmuch_bool_t mbox_warning = FALSE; - if (! mbox_warning) { - mbox_warning = TRUE; - fprintf (stderr, "\ -Warning: %s is an mbox containing a single message,\n\ -likely caused by misconfigured mail delivery. Support for single-message\n\ -mboxes is deprecated and may be removed in the future.\n", message->filename); - } + status = NOTMUCH_STATUS_FILE_NOT_EMAIL; } DONE: @@ -232,6 +201,38 @@ _notmuch_message_file_get_mime_message (notmuch_message_file_t *message, * * Return NULL on errors, empty string for non-existing headers. */ + +static char * +_extend_header (char *combined, const char *value) { + char *decoded; + + decoded = g_mime_utils_header_decode_text (value); + if (! decoded) { + if (combined) { + g_free (combined); + combined = NULL; + } + goto DONE; + } + + if (combined) { + char *tmp = g_strdup_printf ("%s %s", combined, decoded); + g_free (decoded); + g_free (combined); + if (! tmp) { + combined = NULL; + goto DONE; + } + + combined = tmp; + } else { + combined = decoded; + } + DONE: + return combined; +} + +#if (GMIME_MAJOR_VERSION < 3) static char * _notmuch_message_file_get_combined_header (notmuch_message_file_t *message, const char *header) @@ -253,37 +254,13 @@ _notmuch_message_file_get_combined_header (notmuch_message_file_t *message, do { const char *value; - char *decoded; - if (strcasecmp (g_mime_header_iter_get_name (iter), header) != 0) continue; /* Note that GMime retains ownership of value... */ value = g_mime_header_iter_get_value (iter); - /* ... while decoded needs to be freed with g_free(). */ - decoded = g_mime_utils_header_decode_text (value); - if (! decoded) { - if (combined) { - g_free (combined); - combined = NULL; - } - goto DONE; - } - - if (combined) { - char *tmp = g_strdup_printf ("%s %s", combined, decoded); - g_free (decoded); - g_free (combined); - if (! tmp) { - combined = NULL; - goto DONE; - } - - combined = tmp; - } else { - combined = decoded; - } + combined = _extend_header (combined, value); } while (g_mime_header_iter_next (iter)); /* Return empty string for non-existing headers. */ @@ -295,6 +272,39 @@ _notmuch_message_file_get_combined_header (notmuch_message_file_t *message, return combined; } +#else +static char * +_notmuch_message_file_get_combined_header (notmuch_message_file_t *message, + const char *header) +{ + char *combined = NULL; + GMimeHeaderList *headers; + + headers = g_mime_object_get_header_list (GMIME_OBJECT (message->message)); + if (! headers) + return NULL; + + + for (int i=0; i < g_mime_header_list_get_count (headers); i++) { + const char *value; + GMimeHeader *g_header = g_mime_header_list_get_header_at (headers, i); + + if (strcasecmp (g_mime_header_get_name (g_header), header) != 0) + continue; + + /* GMime retains ownership of value, we hope */ + value = g_mime_header_get_value (g_header); + + combined = _extend_header (combined, value); + } + + /* Return empty string for non-existing headers. */ + if (! combined) + combined = g_strdup (""); + + return combined; +} +#endif const char * _notmuch_message_file_get_header (notmuch_message_file_t *message,