diff --git a/sql/CMakeLists.txt b/sql/CMakeLists.txt index 6f207fec..05b6ec56 100644 --- a/sql/CMakeLists.txt +++ b/sql/CMakeLists.txt @@ -15,3 +15,4 @@ install(FILES version-012.sql DESTINATION ${SQL_DEST}) install(FILES version-013.sql DESTINATION ${SQL_DEST}) install(FILES version-014.sql DESTINATION ${SQL_DEST}) install(FILES version-015.sql DESTINATION ${SQL_DEST}) +install(FILES version-016.sql DESTINATION ${SQL_DEST}) diff --git a/sql/version-016.sql b/sql/version-016.sql new file mode 100644 index 00000000..f0066352 --- /dev/null +++ b/sql/version-016.sql @@ -0,0 +1,9 @@ +-- +-- For a while there, we weren't properly indexing attachment filenames in the +-- search table. To be proper (and since this is right before a major release) +-- we want to make sure anyone who's been running the dailies has a good +-- database, which unfortunately means ditching the search table and letting +-- Geary recreate it properly. +-- + +DELETE FROM MessageSearchTable diff --git a/src/engine/imap-db/imap-db-folder.vala b/src/engine/imap-db/imap-db-folder.vala index 70c30124..3c6e3c9a 100644 --- a/src/engine/imap-db/imap-db-folder.vala +++ b/src/engine/imap-db/imap-db-folder.vala @@ -1821,17 +1821,12 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { if (email.fields == Geary.Email.Field.NONE) return; - // Build the combined email from the merge, which will be used to save the attachments - Geary.Email combined_email = row.to_email(location.email_id); - do_add_attachments(cx, combined_email, location.message_id, cancellable); - // Merge in any fields in the submitted email that aren't already in the database or are mutable int new_unread_count = 0; if (((fetched_fields & email.fields) != email.fields) || email.fields.is_any_set(Geary.Email.MUTABLE_FIELDS)) { - Geary.Email.Field new_fields; - do_merge_message_row(cx, row, out new_fields, out updated_contacts, - ref new_unread_count, cancellable); + // Build the combined email from the merge, which will be used to save the attachments + Geary.Email combined_email = row.to_email(location.email_id); // Update attachments if not already in the database if (!fetched_fields.fulfills(Attachment.REQUIRED_FIELDS) @@ -1840,6 +1835,14 @@ private class Geary.ImapDB.Folder : BaseObject, Geary.ReferenceSemantics { cancellable); } + // Must add attachments to the email object after they're saved to + // the database. + do_add_attachments(cx, combined_email, location.message_id, cancellable); + + Geary.Email.Field new_fields; + do_merge_message_row(cx, row, out new_fields, out updated_contacts, + ref new_unread_count, cancellable); + if (do_check_for_message_search_row(cx, location.message_id, cancellable)) do_merge_email_in_search_table(cx, location.message_id, new_fields, combined_email, cancellable); else