Added easier to detect error message when search returns 0 results. This currently parses html result from the mailarchive system, but when we get proper API to mailarchive system it should be changed to do that instead. Fixes #2126. Commit ready for merge.

- Legacy-Id: 15706
This commit is contained in:
Tero Kivinen 2018-11-03 11:08:18 +00:00
parent 56acd00c6c
commit f9eeee0cc9
2 changed files with 8 additions and 1 deletions

View file

@ -687,7 +687,10 @@ def search_mail_archive(request, name, request_id):
try:
res["messages"] = mailarch.retrieve_messages(res["query_data_url"])[:MAX_RESULTS]
except Exception as e:
res["error"] = "Retrieval from mail archive failed: {}".format(unicode(e))
if unicode(e) == "NONE":
res["error"] = "No results found"
else:
res["error"] = "Retrieval from mail archive failed: {}".format(unicode(e))
# raise # useful when debugging
return JsonResponse(res)

View file

@ -4,6 +4,7 @@
import datetime, tarfile, mailbox, tempfile, hashlib, base64, email.utils
import urllib
import urllib2, contextlib
import re
from django.conf import settings
@ -92,6 +93,9 @@ def retrieve_messages(query_data_url):
with contextlib.closing(urllib2.urlopen(query_data_url, timeout=15)) as fileobj:
content_type = fileobj.info()["Content-type"]
if not content_type.startswith("application/x-tar"):
if content_type.startswith("text/html"):
if not re.search("no-results", fileobj.read(20000)) is None:
raise Exception("NONE")
raise Exception("Export failed - this usually means no matches were found")
with tarfile.open(fileobj=fileobj, mode='r|*') as tar: