def mails(): query = search_query.compile(request.args.get("q")) if request.args.get("q") else {'tags': {}} mails = mail_service.mails(query) if "inbox" in query['tags']: mails = [mail for mail in mails if not mail.has_tag('trash')] mails = sorted(mails, key=lambda mail: mail.date, reverse=True) mails = [mail.as_dict() for mail in mails] response = { "stats": { "total": len(mails), "read": 0, "starred": 0, "replied": 0 }, "mails": mails } return respond_json(response)
def test_tags_with_quotes(self): self.assertEquals(search_query.compile(u"in:\"inbox\"")["tags"], ["inbox"]) self.assertEquals(search_query.compile(u"in:'inbox'")["tags"], ["inbox"])
def test_general_search(self): self.assertEquals(search_query.compile(u"searching")["general"], "searching")
def test_tag_negate(self): self.assertEquals(search_query.compile(u"-in:trash")["not_tags"], ["trash"])
def test_two_tags_or(self): self.assertEquals(search_query.compile(u"in:inbox or in:trash")["tags"], ["inbox", "trash"])
def test_one_tag(self): self.assertEquals(search_query.compile(u"in:inbox")["tags"], ["inbox"]) self.assertEquals(search_query.compile(u"in:trash")["tags"], ["trash"])