- if (message->value.size) {
- free (message->value.str);
- message->value.str = NULL;
- message->value.size = 0;
- message->value.len = 0;
+notmuch_status_t
+_notmuch_message_file_get_headers (notmuch_message_file_t *message_file,
+ const char **from_out,
+ const char **subject_out,
+ const char **to_out,
+ const char **date_out,
+ char **message_id_out)
+{
+ notmuch_status_t ret;
+ const char *header;
+ const char *from, *to, *subject, *date;
+ char *message_id = NULL;
+
+ /* Parse message up front to get better error status. */
+ ret = _notmuch_message_file_parse (message_file);
+ if (ret)
+ goto DONE;
+
+ /* Before we do any real work, (especially before doing a
+ * potential SHA-1 computation on the entire file's contents),
+ * let's make sure that what we're looking at looks like an
+ * actual email message.
+ */
+ from = _notmuch_message_file_get_header (message_file, "from");
+ subject = _notmuch_message_file_get_header (message_file, "subject");
+ to = _notmuch_message_file_get_header (message_file, "to");
+ date = _notmuch_message_file_get_header (message_file, "date");
+
+ if ((from == NULL || *from == '\0') &&
+ (subject == NULL || *subject == '\0') &&
+ (to == NULL || *to == '\0')) {
+ ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;
+ goto DONE;