summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Rosenthal <jrosenthal@jhu.edu>2010-03-25 15:17:31 +0100
committerJesse Rosenthal <jrosenthal@jhu.edu>2010-03-25 15:17:31 +0100
commit46d06838ae171b744c443b1ec812cebe82996cfa (patch)
tree8b3d9d504a37fed3b8b2905cbcd230a9cf738887
parentbdc3a95bb7de2e333d31ef31f733e83bada078ff (diff)
notmuch: Make modifications to implement notmuch search
-rwxr-xr-xnotmuch45
1 files changed, 39 insertions, 6 deletions
diff --git a/notmuch b/notmuch
index b08334d..6111a7e 100755
--- a/notmuch
+++ b/notmuch
@@ -1,10 +1,14 @@
#!/usr/bin/env python
-"""This is a notmuch implementation in python. It's goal is to allow running the test suite on the cnotmuch python bindings.
+"""This is a notmuch implementation in python.
+It's goal is to allow running the test suite on the cnotmuch python bindings.
This "binary" honors the NOTMUCH_CONFIG environmen variable for reading a user's
-notmuch configuration (e.g. the database path)
+notmuch configuration (e.g. the database path).
-This code is licensed under the GNU GPL v3+."""
+ (c) 2010 by Sebastian Spaeth <Sebastian@SSpaeth.de>
+ Jesse Rosenthal <jrosenthal@jhu.edu>
+ This code is licensed under the GNU GPL v3+.
+"""
from __future__ import with_statement # This isn't required in Python 2.6
import sys, os, re, logging
from subprocess import call
@@ -299,16 +303,45 @@ if __name__ == '__main__':
#-------------------------------------
elif sys.argv[1] == 'show':
db = Database()
+ out_format="text"
if len(sys.argv) == 2:
#no further search term
querystr=''
+ elif sys.argv[2].startswith("--format="):
+ out_format = sys.argv[2].split("=")[1].strip()
+
+ if not out_format in ("json", "text"):
+ raise Exception("unknown format")
+
+ if len(sys.argv) == 3:
+ querystr = ''
+ else:
+ querystr = quote_query_line(sys.argv[3:])
else:
#mangle arguments wrapping terms with spaces in quotes
querystr = quote_query_line(sys.argv[2:])
+
logging.debug("show "+querystr)
- m = Query(db,querystr).search_messages()
- for msg in m:
- print(msg.format_as_text())
+ t = Query(db,querystr).search_threads()
+
+ first_toplevel=True
+ if out_format.lower()=="json":
+ sys.stdout.write("[")
+
+ for thrd in t:
+ msgs = thrd.get_toplevel_messages()
+
+ if not first_toplevel:
+ if format.lower()=="json":
+ sys.stdout.write(", ")
+
+ first_toplevel = False
+
+ msgs.show_messages(out_format, 0, True)
+
+ if out_format.lower() == "json":
+ sys.stdout.write("]")
+ sys.stdout.write("\n")
#-------------------------------------
elif sys.argv[1] == 'reply':