mirror of
https://git.notmuchmail.org/git/notmuch
synced 2024-11-26 12:55:18 +01:00
implement sort order for notmuch show
This commit is contained in:
parent
8b84f00cce
commit
61a547bd3e
2 changed files with 32 additions and 14 deletions
|
@ -721,7 +721,7 @@ class Message(object):
|
||||||
easy to change to a new format when the format changes."""
|
easy to change to a new format when the format changes."""
|
||||||
|
|
||||||
format = self.format_message_internal()
|
format = self.format_message_internal()
|
||||||
output = "\n\fmessage{ id:%s depth:%d match:%d filename:%s" \
|
output = "\fmessage{ id:%s depth:%d match:%d filename:%s" \
|
||||||
% (format['id'], indent, format['match'], format['filename'])
|
% (format['id'], indent, format['match'], format['filename'])
|
||||||
output += "\n\fheader{"
|
output += "\n\fheader{"
|
||||||
|
|
||||||
|
@ -729,7 +729,7 @@ class Message(object):
|
||||||
output += "\n%s (%s) (" % (format["headers"]["from"],
|
output += "\n%s (%s) (" % (format["headers"]["from"],
|
||||||
format["headers"]["date"])
|
format["headers"]["date"])
|
||||||
output += ", ".join(format["tags"])
|
output += ", ".join(format["tags"])
|
||||||
output += ")\n"
|
output += ")"
|
||||||
|
|
||||||
output += "\nSubject: %s" % format["headers"]["subject"]
|
output += "\nSubject: %s" % format["headers"]["subject"]
|
||||||
output += "\nFrom: %s" % format["headers"]["from"]
|
output += "\nFrom: %s" % format["headers"]["from"]
|
||||||
|
@ -739,7 +739,7 @@ class Message(object):
|
||||||
if format["headers"]["bcc"]:
|
if format["headers"]["bcc"]:
|
||||||
output += "\nBcc: %s" % format["headers"]["bcc"]
|
output += "\nBcc: %s" % format["headers"]["bcc"]
|
||||||
output += "\nDate: %s" % format["headers"]["date"]
|
output += "\nDate: %s" % format["headers"]["date"]
|
||||||
output += "\nheader}\f"
|
output += "\n\fheader}"
|
||||||
|
|
||||||
output += "\n\fbody{"
|
output += "\n\fbody{"
|
||||||
|
|
||||||
|
@ -748,7 +748,7 @@ class Message(object):
|
||||||
for p in parts:
|
for p in parts:
|
||||||
if not p.has_key("filename"):
|
if not p.has_key("filename"):
|
||||||
output += "\n\fpart{ "
|
output += "\n\fpart{ "
|
||||||
output += "ID: %d, Content-type:%s\n" % (p["id"],
|
output += "ID: %d, Content-type: %s\n" % (p["id"],
|
||||||
p["content_type"])
|
p["content_type"])
|
||||||
if p.has_key("content"):
|
if p.has_key("content"):
|
||||||
output += "\n%s\n" % p["content"]
|
output += "\n%s\n" % p["content"]
|
||||||
|
@ -763,7 +763,7 @@ class Message(object):
|
||||||
output += "\n\fattachment}\n"
|
output += "\n\fattachment}\n"
|
||||||
|
|
||||||
output += "\n\fbody}\n"
|
output += "\n\fbody}\n"
|
||||||
output += "\n\fmessage}\n"
|
output += "\n\fmessage}"
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
36
notmuch
36
notmuch
|
@ -290,16 +290,34 @@ if __name__ == '__main__':
|
||||||
#-------------------------------------
|
#-------------------------------------
|
||||||
elif sys.argv[1] == 'search':
|
elif sys.argv[1] == 'search':
|
||||||
db = Database()
|
db = Database()
|
||||||
if len(sys.argv) == 2:
|
query_string = ''
|
||||||
#no further search term
|
sort_order="newest-first"
|
||||||
querystr=''
|
first_search_term = None
|
||||||
else:
|
for (i, arg) in enumerate(sys.argv[1:]):
|
||||||
#mangle arguments wrapping terms with spaces in quotes
|
if arg.startswith('--sort='):
|
||||||
querystr = quote_query_line(sys.argv[2:])
|
sort_order=arg.split("=")[1]
|
||||||
|
if not sort_order in ("oldest-first", "newest-first"):
|
||||||
|
raise Exception("unknown sort order")
|
||||||
|
elif not arg.startswith('--'):
|
||||||
|
#save the position of the first sys.argv that is a search term
|
||||||
|
first_search_term = i+1
|
||||||
|
|
||||||
|
if first_search_term:
|
||||||
|
#mangle arguments wrapping terms with spaces in quotes
|
||||||
|
querystr = quote_query_line(sys.argv[first_search_term:])
|
||||||
|
|
||||||
|
|
||||||
logging.debug("search "+querystr)
|
logging.debug("search "+querystr)
|
||||||
t = Query(db,querystr).search_threads()
|
qry = Query(db,querystr)
|
||||||
|
if sort_order == "oldest-first":
|
||||||
|
qry.set_sort(Query.SORT.OLDEST_FIRST)
|
||||||
|
else:
|
||||||
|
qry.set_sort(Query.SORT.NEWEST_FIRST)
|
||||||
|
t = qry.search_threads()
|
||||||
|
|
||||||
for thread in t:
|
for thread in t:
|
||||||
print(str(thread))
|
print(str(thread))
|
||||||
|
|
||||||
#-------------------------------------
|
#-------------------------------------
|
||||||
elif sys.argv[1] == 'show':
|
elif sys.argv[1] == 'show':
|
||||||
entire_thread = False
|
entire_thread = False
|
||||||
|
@ -344,7 +362,7 @@ if __name__ == '__main__':
|
||||||
|
|
||||||
first_toplevel = False
|
first_toplevel = False
|
||||||
|
|
||||||
msgs.print_messages(out_format, 0, True)
|
msgs.print_messages(out_format, 0, entire_thread)
|
||||||
|
|
||||||
if out_format.lower() == "json":
|
if out_format.lower() == "json":
|
||||||
sys.stdout.write("]")
|
sys.stdout.write("]")
|
||||||
|
|
Loading…
Reference in a new issue