+ header = notmuch_message_file_get_header (message_file, "message-id");
+ if (header) {
+ message_id = parse_message_id (header, NULL);
+ /* So the header value isn't RFC-compliant, but it's
+ * better than no message-id at all. */
+ if (message_id == NULL)
+ message_id = xstrdup (header);
+ } else {
+ /* No message-id at all, let's generate one by taking a
+ * hash over the file's contents. */
+ char *sha1 = notmuch_sha1_of_file (filename);
+
+ /* If that failed too, something is really wrong. Give up. */
+ if (sha1 == NULL) {
+ ret = NOTMUCH_STATUS_FILE_ERROR;
+ goto DONE;
+ }
+
+ message_id = g_strdup_printf ("notmuch-sha1-%s", sha1);
+ free (sha1);
+ }
+