[Xfce4-commits] <postler:master> Interpret a - (hyphen) in front of a word as negation

Christian Dywan noreply at xfce.org
Mon Jul 11 23:14:03 CEST 2011


Updating branch refs/heads/master
         to a99d7bf27dace4ef2d3608ea8872c1cd106e6168 (commit)
       from 54471f8f40a4674ce7b52c26659ecde2284312c0 (commit)

commit a99d7bf27dace4ef2d3608ea8872c1cd106e6168
Author: Christian Dywan <christian at twotoasts.de>
Date:   Mon Jul 11 01:29:01 2011 +0200

    Interpret a - (hyphen) in front of a word as negation

 postler/postler-index.vala |   21 +++++++++++++++++----
 1 files changed, 17 insertions(+), 4 deletions(-)

diff --git a/postler/postler-index.vala b/postler/postler-index.vala
index b4da099..a8852cb 100644
--- a/postler/postler-index.vala
+++ b/postler/postler-index.vala
@@ -262,12 +262,24 @@ namespace Postler {
                     }
 
                     var cond = new StringBuilder ("(");
-                    foreach (string word in parts[1].split (" ")) {
+                    foreach (string a_word in parts[1].split (" ")) {
+                        /* A - (hyphen) negates search results */
+                        string word, negate;
+                        if (a_word[0] == '-') {
+                            word = a_word.substring (1, -1);
+                            negate = "NOT";
+                        }
+                        else {
+                            word = a_word;
+                            negate = "";
+                        }
+
                         /* Interpret a month as "only messages in that month" */
                         string? month = dates.lookup (word.down ());
                         if (month != null) {
                             cond.append_printf (
-                                "strftime ('%%m', timestamp, 'unixepoch') = '%s' AND ", month);
+                                "%s (strftime ('%%m', timestamp, 'unixepoch') = '%s') AND ",
+                                negate, month);
                             continue;
                         }
                         /* * is a wildcard, ' must be escaped by doubling it */
@@ -275,14 +287,15 @@ namespace Postler {
                         /* any is an alias for subject, sender, attachment, excerpt */
                         /* FIXME: attachment is not indexed yet */
                         if (field == "any") {
-                            var any_cond = new StringBuilder ("(");
+                            var any_cond = new StringBuilder (negate + " (");
                             foreach (string any_field in any_fields)
                                 any_cond.append_printf ("%s LIKE '%%%s%%' OR ", any_field, escaped);
                             cond.append_printf ("%s) AND ",
                                 any_cond.truncate (any_cond.len - 3).str);
                         }
                         else
-                            cond.append_printf ("%s LIKE '%%%s%%' AND ", field, escaped);
+                            cond.append_printf ("%s %s LIKE '%%%s%%' AND ",
+                                                field, negate, escaped);
                     }
                     cond.truncate (cond.len - 4);
                     /* Filter out Trash and Junk */



More information about the Xfce4-commits mailing list