|
14 | 14 | from email.mime.text import MIMEText
|
15 | 15 | from email.utils import formatdate, make_msgid
|
16 | 16 | import json
|
| 17 | +import urllib |
17 | 18 |
|
18 | 19 | from pgcommitfest.mailqueue.util import send_mail, send_simple_mail
|
19 | 20 | from pgcommitfest.userprofile.util import UserWrapper
|
|
22 | 23 | from .models import MailThread
|
23 | 24 | from .forms import PatchForm, NewPatchForm, CommentForm, CommitFestFilterForm
|
24 | 25 | from .forms import BulkEmailForm
|
25 |
| -from .ajax import doAttachThread, refresh_single_thread |
| 26 | +from .ajax import doAttachThread, refresh_single_thread, _archivesAPI |
26 | 27 | from .feeds import ActivityFeed
|
27 | 28 |
|
28 | 29 |
|
@@ -249,13 +250,42 @@ def commitfest(request, cfid):
|
249 | 250 | 'header_activity_link': 'activity/',
|
250 | 251 | })
|
251 | 252 |
|
| 253 | +def patches_by_messageid(messageid): |
| 254 | + # First try to find the messageid in our database |
| 255 | + patches = Patch.objects.select_related().filter(mailthread__messageid=messageid).order_by('created',).all() |
| 256 | + if patches: |
| 257 | + return patches |
| 258 | + |
| 259 | + urlsafe_messageid = urllib.parse.quote(messageid) |
| 260 | + |
| 261 | + # If it's not there, try to find it in the archives |
| 262 | + try: |
| 263 | + thread = _archivesAPI(f'/message-id.json/{urlsafe_messageid}') |
| 264 | + except Http404: |
| 265 | + return [] |
| 266 | + |
| 267 | + if len(thread) == 0: |
| 268 | + return [] |
| 269 | + |
| 270 | + first_email = min(thread, key=lambda x: x['date']) |
| 271 | + |
| 272 | + return Patch.objects.select_related().filter(mailthread__messageid=first_email['msgid']).order_by('created',).all() |
| 273 | + |
252 | 274 |
|
253 | 275 | def global_search(request):
|
254 | 276 | if 'searchterm' not in request.GET:
|
255 | 277 | return HttpResponseRedirect('/')
|
256 |
| - searchterm = request.GET['searchterm'] |
| 278 | + searchterm = request.GET['searchterm'].strip() |
| 279 | + patches = [] |
| 280 | + |
| 281 | + if '@' in searchterm: |
| 282 | + # This is probably a messageid, so let's try to look up patches related |
| 283 | + # to it. Let's first remove any < and > around it though. |
| 284 | + cleaned_id = searchterm.removeprefix('<').removesuffix('>') |
| 285 | + patches = patches_by_messageid(cleaned_id) |
257 | 286 |
|
258 |
| - patches = Patch.objects.select_related().filter(name__icontains=searchterm).order_by('created',).all() |
| 287 | + if not patches: |
| 288 | + patches = Patch.objects.select_related().filter(name__icontains=searchterm).order_by('created',).all() |
259 | 289 |
|
260 | 290 | if len(patches) == 1:
|
261 | 291 | patch = patches[0]
|
|
0 commit comments