Merged in [15706] from kivinen@iki.fi:

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.
 - Legacy-Id: 15744
Note: SVN reference [15706] has been migrated to Git commit f9eeee0cc9
This commit is contained in:
Henrik Levkowetz 2018-11-09 21:23:45 +00:00
commit 236ee7639d
2 changed files with 8 additions and 1 deletions

View file

@ -704,7 +704,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: %s" % 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: