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

« back to all changes in this revision

Viewing changes to src/engine/imap-db/imap-db-account.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:
75
75
        try {
76
76
            db.open(
77
77
                Db.DatabaseFlags.CREATE_DIRECTORY | Db.DatabaseFlags.CREATE_FILE | Db.DatabaseFlags.CHECK_CORRUPTION,
78
 
                null, cancellable);
 
78
                cancellable);
79
79
        } catch (Error err) {
80
80
            warning("Unable to open database: %s", err.message);
81
81
            
331
331
            Db.Result result = statement.exec(cancellable);
332
332
            while (!result.finished) {
333
333
                try {
334
 
                    Contact contact = new Contact(result.string_at(0), result.string_at(1),
 
334
                    Contact contact = new Contact(result.nonnull_string_at(0), result.string_at(1),
335
335
                        result.int_at(2), result.string_at(3), ContactFlags.deserialize(result.string_at(4)));
336
336
                    contacts.add(contact);
337
337
                } catch (Geary.DatabaseError err) {
567
567
        Geary.RFC822.MessageID message_id, Geary.Email.Field requested_fields, bool partial_ok,
568
568
        Gee.Collection<Geary.FolderPath?>? folder_blacklist, Geary.EmailFlags? flag_blacklist,
569
569
        Cancellable? cancellable = null) throws Error {
 
570
        check_open();
 
571
        
570
572
        Gee.HashMultiMap<Geary.Email, Geary.FolderPath?> messages
571
573
            = new Gee.HashMultiMap<Geary.Email, Geary.FolderPath?>();
572
574
        
717
719
    public async Gee.Collection<Geary.EmailIdentifier>? search_async(string prepared_query,
718
720
        int limit = 100, int offset = 0, Gee.Collection<Geary.FolderPath?>? folder_blacklist = null,
719
721
        Gee.Collection<Geary.EmailIdentifier>? search_ids = null, Cancellable? cancellable = null) throws Error {
 
722
        check_open();
 
723
        
720
724
        Gee.ArrayList<ImapDB.SearchEmailIdentifier> search_results
721
725
            = new Gee.ArrayList<ImapDB.SearchEmailIdentifier>();
722
726
        
775
779
        return (search_results.size == 0 ? null : search_results);
776
780
    }
777
781
    
778
 
    public async Gee.Collection<string>? get_search_matches_async(string prepared_query,
 
782
    // This applies a fudge-factor set of matches when the database results
 
783
    // aren't entirely satisfactory, such as when you search for an email
 
784
    // address and the database tokenizes out the @ and ., etc.  It's not meant
 
785
    // to be comprehensive, just a little extra highlighting applied to make
 
786
    // the results look a little closer to what you typed.
 
787
    private void add_literal_matches(string raw_query, Gee.Set<string> search_matches) {
 
788
        foreach (string word in raw_query.split(" ")) {
 
789
            if (word.has_suffix("\""))
 
790
                word = word.substring(0, word.length - 1);
 
791
            if (word.has_prefix("\""))
 
792
                word = word.substring(1);
 
793
            
 
794
            if (!String.is_empty_or_whitespace(word))
 
795
                search_matches.add(word);
 
796
        }
 
797
    }
 
798
    
 
799
    public async Gee.Collection<string>? get_search_matches_async(string raw_query, string prepared_query,
779
800
        Gee.Collection<ImapDB.EmailIdentifier> ids, Cancellable? cancellable = null) throws Error {
 
801
        check_open();
 
802
        
780
803
        Gee.Set<string> search_matches = new Gee.HashSet<string>();
781
804
        
782
805
        // Create a question mark for each ID.
800
823
            Db.Result result = stmt.exec(cancellable);
801
824
            while (!result.finished) {
802
825
                // Build a list of search offsets.
803
 
                string[] offset_array = result.string_at(0).split(" ");
 
826
                string[] offset_array = result.nonnull_string_at(0).split(" ");
804
827
                Gee.ArrayList<SearchOffset> all_offsets = new Gee.ArrayList<SearchOffset>();
805
828
                int j = 0;
806
829
                while (true) {
814
837
                // Iterate over the offset list, scrape strings from the database, and push
815
838
                // the results into our return set.
816
839
                foreach(SearchOffset offset in all_offsets) {
817
 
                    string text = result.string_at(offset.column + 1);
 
840
                    string text = result.nonnull_string_at(offset.column + 1);
818
841
                    search_matches.add(text[offset.byte_offset : offset.byte_offset + offset.size].down());
819
842
                }
820
843
                
824
847
            return Db.TransactionOutcome.DONE;
825
848
        }, cancellable);
826
849
        
 
850
        add_literal_matches(raw_query, search_matches);
 
851
        
827
852
        return (search_matches.size == 0 ? null : search_matches);
828
853
    }
829
854
    
830
855
    public async Geary.Email fetch_email_async(ImapDB.EmailIdentifier email_id,
831
856
        Geary.Email.Field required_fields, Cancellable? cancellable = null) throws Error {
 
857
        check_open();
 
858
        
832
859
        Geary.Email? email = null;
833
860
        yield db.exec_transaction_async(Db.TransactionType.RO, (cx) => {
834
861
            // TODO: once we have a way of deleting messages, we won't be able
890
917
     */
891
918
    public async Gee.MultiMap<Geary.EmailIdentifier, Geary.FolderPath>? get_containing_folders_async(
892
919
        Gee.Collection<Geary.EmailIdentifier> ids, Cancellable? cancellable) throws Error {
 
920
        check_open();
 
921
        
893
922
        Gee.HashMultiMap<Geary.EmailIdentifier, Geary.FolderPath> map
894
923
            = new Gee.HashMultiMap<Geary.EmailIdentifier, Geary.FolderPath>();
895
924
        yield db.exec_transaction_async(Db.TransactionType.RO, (cx, cancellable) => {
1193
1222
            return null;
1194
1223
        
1195
1224
        int64 parent_id = result.int64_at(0);
1196
 
        string name = result.string_at(1);
 
1225
        string name = result.nonnull_string_at(1);
1197
1226
        
1198
1227
        // Here too, one level of loop detection is better than nothing.
1199
1228
        if (folder_id == parent_id) {