~ubuntu-branches/ubuntu/saucy/geary/saucy-updates

« back to all changes in this revision

Viewing changes to src/engine/imap-db/imap-db-folder.vala

  • Committer: Package Import Robot
  • Author(s): Sebastien Bacher
  • Date: 2013-10-10 17:40:37 UTC
  • mfrom: (1.1.8)
  • Revision ID: package-import@ubuntu.com-20131010174037-5p5o4dlsoewek2kg
Tags: 0.4.0-0ubuntu1
New stable version

Show diffs side-by-side

added added

removed removed

Lines of Context:
730
730
                "DELETE FROM MessageLocationTable WHERE folder_id=?");
731
731
            stmt.bind_rowid(0, folder_id);
732
732
            
 
733
            stmt.exec(cancellable);
 
734
            
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);
 
738
            
736
739
            update_stmt.exec(cancellable);
737
740
            
738
741
            return Db.TransactionOutcome.COMMIT;
942
945
        return count;
943
946
    }
944
947
    
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)
 
949
        throws Error {
 
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<>?
 
956
            """);
 
957
            stmt.bind_rowid(0, folder_id);
 
958
            stmt.bind_bool(1, false);
 
959
            
 
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))));
 
963
                
 
964
                results.next(cancellable);
 
965
            }
 
966
            
 
967
            return Db.TransactionOutcome.DONE;
 
968
        }, cancellable);
 
969
        
 
970
        return ids.size > 0 ? ids : null;
 
971
    }
 
972
    
 
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();
 
978
            sql.append("""
949
979
                UPDATE MessageLocationTable
950
980
                SET remove_marker=?
951
981
                WHERE folder_id=? AND remove_marker <> ?
952
982
            """);
 
983
            
 
984
            if (exceptions != null && exceptions.size > 0) {
 
985
                sql.append("""
 
986
                    AND message_id NOT IN (
 
987
                """);
 
988
                Gee.Iterator<ImapDB.EmailIdentifier> iter = exceptions.iterator();
 
989
                while (iter.next()) {
 
990
                    sql.append(iter.get().message_id.to_string());
 
991
                    if (iter.has_next())
 
992
                        sql.append(", ");
 
993
                }
 
994
                sql.append(")");
 
995
            }
 
996
            
 
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);
1477
1522
        
1478
1523
        Db.Result results = fetch_stmt.exec(cancellable);
1479
1524
        
1480
 
        if (results.finished)
 
1525
        if (results.finished || results.is_null_at(0))
1481
1526
            return null;
1482
1527
        
1483
1528
        return new Geary.Imap.EmailFlags(Geary.Imap.MessageFlags.deserialize(results.string_at(0)));
1776
1821
        if (email.fields == Geary.Email.Field.NONE)
1777
1822
            return;
1778
1823
        
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);
1782
 
        
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);
1790
1830
            
1791
1831
            // Update attachments if not already in the database
1792
1832
            if (!fetched_fields.fulfills(Attachment.REQUIRED_FIELDS)
1795
1835
                    cancellable);
1796
1836
            }
1797
1837
            
 
1838
            // Must add attachments to the email object after they're saved to
 
1839
            // the database.
 
1840
            do_add_attachments(cx, combined_email, location.message_id, cancellable);
 
1841
            
 
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);
 
1845
            
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);
1800
1848
            else
1827
1875
        Gee.List<Geary.Attachment> list = new Gee.ArrayList<Geary.Attachment>();
1828
1876
        do {
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));
1833
1881