]> git.notmuchmail.org Git - notmuch/blobdiff - notmuch
notmuch: Use Query.count_messages() rather len(Query.search_messages())
[notmuch] / notmuch
diff --git a/notmuch b/notmuch
index acebe38e56a2e8d2e870dfdaae9e9fe32e8d8f5c..5fc98bbef52a1ac5674edc97b225aba36882453e 100755 (executable)
--- a/notmuch
+++ b/notmuch
@@ -6,6 +6,7 @@ notmuch configuration (e.g. the database path)
 
 This code is licensed under the GNU GPL v3+."""
 import sys, os, re, logging
+from subprocess import call
 from cnotmuch.notmuch import Database, Query
 PREFIX=re.compile('(\w+):(.*$)')
 #TODO Handle variable: NOTMUCH-CONFIG
@@ -113,6 +114,11 @@ if __name__ == '__main__':
        """ Interactively setup notmuch for first use. """
        print "Not implemented."
    #-------------------------------------
+   elif sys.argv[1] == 'new':
+       """ Interactively setup notmuch for first use. """
+       #print "Not implemented. We cheat by calling the proper notmuch"
+       call(['notmuch new'],shell=True)
+   #-------------------------------------
    elif sys.argv[1] == 'help':
        if len(sys.argv) == 2: print HELPTEXT
        else: print "Not implemented"
@@ -143,7 +149,8 @@ if __name__ == '__main__':
          #mangle arguments wrapping terms with spaces in quotes
          querystr = quote_query_line(sys.argv[2:])
       logging.debug("count "+querystr)
-      print(len(Query(db,querystr).search_messages()))
+      print(Query(db,querystr).count_messages())
+      
    #-------------------------------------
    elif sys.argv[1] == 'tag':
       #build lists of tags to be added and removed
@@ -182,12 +189,16 @@ if __name__ == '__main__':
    #-------------------------------------
    elif sys.argv[1] == 'dump':
       #TODO: implement "dump <filename>"
+      if len(sys.argv) == 2:
+         f = sys.stdout
+      else:
+         f = open(sys.argv[2],"w")
       db = Database()
       q = Query(db,'')
       q.set_sort(Query.SORT.MESSAGE_ID)
       m = q.search_messages()
       for msg in m:
-         print("%s (%s)" % (msg.get_message_id(), msg.get_tags()))
+         f.write("%s (%s)\n" % (msg.get_message_id(), msg.get_tags()))
    #-------------------------------------
    else:
        # unknown command