730
730
"DELETE FROM MessageLocationTable WHERE folder_id=?");
731
731
stmt.bind_rowid(0, folder_id);
733
stmt.exec(cancellable);
733
735
Db.Statement update_stmt = cx.prepare(
734
736
"UPDATE FolderTable SET unread_count = 0 WHERE id=?");
735
737
update_stmt.bind_rowid(0, folder_id);
736
739
update_stmt.exec(cancellable);
738
741
return Db.TransactionOutcome.COMMIT;
945
// Clears all remove markers from the folder
946
public async void clear_remove_markers_async(Cancellable? cancellable) throws Error {
948
public async Gee.Set<ImapDB.EmailIdentifier>? get_marked_ids_async(Cancellable? cancellable)
950
Gee.Set<ImapDB.EmailIdentifier> ids = new Gee.HashSet<ImapDB.EmailIdentifier>();
951
yield db.exec_transaction_async(Db.TransactionType.RO, (cx) => {
952
Db.Statement stmt = cx.prepare("""
953
SELECT message_id, ordering
954
FROM MessageLocationTable
955
WHERE folder_id=? AND remove_marker<>?
957
stmt.bind_rowid(0, folder_id);
958
stmt.bind_bool(1, false);
960
Db.Result results = stmt.exec(cancellable);
961
while (!results.finished) {
962
ids.add(new ImapDB.EmailIdentifier(results.rowid_at(0), new Imap.UID(results.int64_at(1))));
964
results.next(cancellable);
967
return Db.TransactionOutcome.DONE;
970
return ids.size > 0 ? ids : null;
973
// Clears all remove markers from the folder except those in the exceptions Collection
974
public async void clear_remove_markers_async(Gee.Collection<ImapDB.EmailIdentifier>? exceptions,
975
Cancellable? cancellable) throws Error {
947
976
yield db.exec_transaction_async(Db.TransactionType.WO, (cx) => {
948
Db.Statement stmt = cx.prepare("""
977
StringBuilder sql = new StringBuilder();
949
979
UPDATE MessageLocationTable
950
980
SET remove_marker=?
951
981
WHERE folder_id=? AND remove_marker <> ?
984
if (exceptions != null && exceptions.size > 0) {
986
AND message_id NOT IN (
988
Gee.Iterator<ImapDB.EmailIdentifier> iter = exceptions.iterator();
989
while (iter.next()) {
990
sql.append(iter.get().message_id.to_string());
997
Db.Statement stmt = cx.prepare(sql.str);
953
998
stmt.bind_bool(0, false);
954
999
stmt.bind_rowid(1, folder_id);
955
1000
stmt.bind_bool(2, false);
1776
1821
if (email.fields == Geary.Email.Field.NONE)
1779
// Build the combined email from the merge, which will be used to save the attachments
1780
Geary.Email combined_email = row.to_email(location.email_id);
1781
do_add_attachments(cx, combined_email, location.message_id, cancellable);
1783
1824
// Merge in any fields in the submitted email that aren't already in the database or are mutable
1784
1825
int new_unread_count = 0;
1785
1826
if (((fetched_fields & email.fields) != email.fields) ||
1786
1827
email.fields.is_any_set(Geary.Email.MUTABLE_FIELDS)) {
1787
Geary.Email.Field new_fields;
1788
do_merge_message_row(cx, row, out new_fields, out updated_contacts,
1789
ref new_unread_count, cancellable);
1828
// Build the combined email from the merge, which will be used to save the attachments
1829
Geary.Email combined_email = row.to_email(location.email_id);
1791
1831
// Update attachments if not already in the database
1792
1832
if (!fetched_fields.fulfills(Attachment.REQUIRED_FIELDS)
1838
// Must add attachments to the email object after they're saved to
1840
do_add_attachments(cx, combined_email, location.message_id, cancellable);
1842
Geary.Email.Field new_fields;
1843
do_merge_message_row(cx, row, out new_fields, out updated_contacts,
1844
ref new_unread_count, cancellable);
1798
1846
if (do_check_for_message_search_row(cx, location.message_id, cancellable))
1799
1847
do_merge_email_in_search_table(cx, location.message_id, new_fields, combined_email, cancellable);
1827
1875
Gee.List<Geary.Attachment> list = new Gee.ArrayList<Geary.Attachment>();
1829
1877
list.add(new ImapDB.Attachment(cx.database.db_file.get_parent(), results.string_at(1),
1830
results.string_at(2), results.int64_at(3), message_id, results.rowid_at(0),
1878
results.nonnull_string_at(2), results.int64_at(3), message_id, results.rowid_at(0),
1831
1879
Geary.Attachment.Disposition.from_int(results.int_at(4))));
1832
1880
} while (results.next(cancellable));