From 2a7775e9643c05e2fac6459ca3dcfacf23f6829d Mon Sep 17 00:00:00 2001
From: Amir <amir@localhost.localdomain>
Date: Mon, 5 Oct 2015 14:14:01 +0300
Subject: [PATCH 2/2] Search: clean query for msgid check and return canonical
 msgid in response

---
 django/archives/mailarchives/views.py | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/django/archives/mailarchives/views.py b/django/archives/mailarchives/views.py
index 3acb3e6..6ee32fd 100644
--- a/django/archives/mailarchives/views.py
+++ b/django/archives/mailarchives/views.py
@@ -465,15 +465,16 @@ def search(request):
 		# This could be a messageid. So try to get that one specifically first.
 		# We don't do a more specific check if it's a messageid because doing
 		# a key lookup is cheap...
+		qmsgid = query.lstrip(" \t\r\n<").rstrip(" \t\r\n>")
 		curs.execute("SELECT messageid FROM messages WHERE messageid=%(q)s", {
-				'q': query,
+				'q': qmsgid,
 				})
 		a = curs.fetchall()
 		if len(a) == 1:
 			# Yup, this was a messageid
 			resp = HttpResponse(mimetype='application/json')
 
-			json.dump({'messageidmatch': 1}, resp)
+			json.dump({'messageidmatch': 1, 'messageid' : qmsgid}, resp)
 			return resp
 		# If not found, fall through to a regular search
 
-- 
2.4.3

