mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-25 12:28:09 +01:00
notmuch_database_add_message: Sanity check the file as the first thing
This avoids us wasting a bunch of time doing an expensive SHA-1 over a large file only to discover later that it doesn't even *look* like an email message.
This commit is contained in:
parent
81861514c9
commit
cfa228a3d4
1 changed files with 19 additions and 13 deletions
32
database.cc
32
database.cc
|
@ -881,7 +881,25 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
|
||||||
(char *) NULL);
|
(char *) NULL);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
/* The first order of business is to find/create a message ID. */
|
/* 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");
|
||||||
|
|
||||||
|
if (from == NULL &&
|
||||||
|
subject == NULL &&
|
||||||
|
to == NULL)
|
||||||
|
{
|
||||||
|
ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;
|
||||||
|
goto DONE;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now that we're sure it's mail, the first order of business
|
||||||
|
* is to find a message ID (or else create one ourselves). */
|
||||||
|
|
||||||
header = notmuch_message_file_get_header (message_file, "message-id");
|
header = notmuch_message_file_get_header (message_file, "message-id");
|
||||||
if (header) {
|
if (header) {
|
||||||
|
@ -938,18 +956,6 @@ notmuch_database_add_message (notmuch_database_t *notmuch,
|
||||||
date = notmuch_message_file_get_header (message_file, "date");
|
date = notmuch_message_file_get_header (message_file, "date");
|
||||||
_notmuch_message_set_date (message, date);
|
_notmuch_message_set_date (message, date);
|
||||||
|
|
||||||
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");
|
|
||||||
|
|
||||||
if (from == NULL &&
|
|
||||||
subject == NULL &&
|
|
||||||
to == NULL)
|
|
||||||
{
|
|
||||||
ret = NOTMUCH_STATUS_FILE_NOT_EMAIL;
|
|
||||||
goto DONE;
|
|
||||||
}
|
|
||||||
|
|
||||||
_notmuch_message_index_file (message, filename);
|
_notmuch_message_index_file (message, filename);
|
||||||
|
|
||||||
_notmuch_message_sync (message);
|
_notmuch_message_sync (message);
|
||||||
|
|
Loading…
Reference in a new issue