[Xfce4-commits] <postler:master> Revise search statement implementation and skip trash

Christian Dywan noreply at xfce.org
Sun Jul 3 14:02:03 CEST 2011


Updating branch refs/heads/master
         to cbcc2c9127f3737526284f95cf7c3475ab3c00db (commit)
       from 546cc802ee557945c49e935d32805284c718151f (commit)

commit cbcc2c9127f3737526284f95cf7c3475ab3c00db
Author: Christian Dywan <christian at twotoasts.de>
Date:   Sun Jul 3 01:48:52 2011 +0200

    Revise search statement implementation and skip trash
    
    Unless you are literally looking at Trash or Junk you don't
    want to see messages stored in it. Filtering by 'uri' will
    still show what's there.

 postler/postler-index.vala |   38 +++++++++++++++++++++++---------------
 1 files changed, 23 insertions(+), 15 deletions(-)

diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index e659ab3..a8d4d30 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -310,19 +310,21 @@ namespace Postler {
         public string[] get_messages (string folder) throws GLib.Error {
             unowned string sql = """
                 SELECT threads AS thread_id FROM messages
-                WHERE $FIELD LIKE ?2 GROUP BY threads
+                WHERE $FIELD LIKE ?2 $CASE GROUP BY threads
                 HAVING (SELECT COUNT (*) FROM messages WHERE id = thread_id)
                 ORDER BY date ASC
                 """;
 
             if (statement_list == null) {
-                if (database.prepare_v2 (sql.replace ("$FIELD", "uri"),
+                if (database.prepare_v2 (sql.replace ("$FIELD", "uri").replace ("$CASE", ""),
                                          -1, out statement_list) != Sqlite.OK)
                     throw new GLib.FileError.FAILED (_("Failed to list messages: %s"), database.errmsg ());
             }
 
             /* file:// or search:field/value */
-            bool success;
+            unowned Sqlite.Statement statement = statement_list;
+            Sqlite.Statement temporary_statement;
+            string search_value;
             if (folder.has_prefix ("search:")) {
                 string[] parts = folder.slice (7, -1).split ("/", 2);
                 if (parts[0] == null || parts[1] == null)
@@ -333,28 +335,34 @@ namespace Postler {
                     field = "sender";
                 else if (field == "to")
                     field = "recipients";
-                Sqlite.Statement statement;
-                if (database.prepare_v2 (sql.replace ("$FIELD", field),
-                                         -1, out statement) != Sqlite.OK)
-                    throw new GLib.FileError.FAILED (_("Failed to list messages: %s"), database.errmsg ());
-                string search_value = "%%%s%%".printf (parts[1]);
-                success = statement_list.bind_text (2, search_value, -1) == Sqlite.OK;
+                /* We can use the prepared statement for uri search */
+                search_value = "%%%s%%".printf (parts[1]);
+                if (field != "uri") {
+                    /* Filter out Trash and Junk */
+                    string real_sql = sql.replace ("$CASE",
+                        "AND uri NOT LIKE '%/Trash/%' AND uri NOT LIKE '%/Junk/%'");
+                    if (database.prepare_v2 (real_sql.replace ("$FIELD", field),
+                                             -1, out temporary_statement) != Sqlite.OK)
+                        throw new GLib.FileError.FAILED (_("Failed to list messages: %s"), database.errmsg ());
+                    statement = temporary_statement;
+                }
             }
             else
-                success = statement_list.bind_text (2, folder, -1) == Sqlite.OK;
+                search_value = folder;
 
+            bool success = statement.bind_text (2, search_value, -1) == Sqlite.OK;
             int result = Sqlite.ERROR;
-            success = success && row_or_done (((result = statement_list.step ())));
+            success = success && row_or_done (((result = statement.step ())));
             if (!success) {
-                statement_list.reset ();
+                statement.reset ();
                 throw new GLib.FileError.FAILED (_("Failed to list messages: %s"), database.errmsg ());
             }
             string[] ids = {};
             while (result == Sqlite.ROW) {
-                ids += statement_list.column_text (0);
-                result = statement_list.step ();
+                ids += statement.column_text (0);
+                result = statement.step ();
             }
-            statement_list.reset ();
+            statement.reset ();
             return ids;
         }
 



More information about the Xfce4-commits mailing list