r = _archivesAPI('/message-id.json/%s' % thread.messageid)
return sorted(r, key=lambda x: x['date'], reverse=True)
+def refresh_single_thread(thread):
+ r = sorted(_archivesAPI('/message-id.json/%s' % thread.messageid), key=lambda x: x['date'])
+ if thread.latestmsgid != r[-1]['msgid']:
+ # There is now a newer mail in the thread!
+ thread.latestmsgid = r[-1]['msgid']
+ thread.latestmessage = r[-1]['date']
+ thread.latestauthor = r[-1]['from']
+ thread.latestsubject = r[-1]['subj']
+ thread.save()
+ parse_and_add_attachments(r, thread)
+ # Potentially update the last mail date - if there wasn't already a mail on each patch
+ # from a *different* thread that had an earlier date.
+ for p in thread.patches.filter(lastmail__lt=thread.latestmessage):
+ p.lastmail = thread.latestmessage
+ p.save()
+
@transaction.atomic
def annotateMessage(request):
thread = get_object_or_404(MailThread, pk=int(request.POST['t']))
fields = [field.name for field in self._meta.fields]
fields.extend([field.name for field in self._meta.many_to_many])
return model_to_dict(self, fields=fields)
+
from datetime import datetime
from email.mime.text import MIMEText
from email.utils import formatdate, make_msgid
+import json
from pgcommitfest.mailqueue.util import send_mail, send_simple_mail
from pgcommitfest.userprofile.util import UserWrapper
from models import CommitFest, Patch, PatchOnCommitFest, PatchHistory, Committer
+from models import MailThread
from forms import PatchForm, NewPatchForm, CommentForm, CommitFestFilterForm
from forms import BulkEmailForm
-from ajax import doAttachThread
+from ajax import doAttachThread, refresh_single_thread
from feeds import ActivityFeed
def home(request):
'breadcrumbs': [{'title': cf.title, 'href': '/%s/' % cf.pk},],
'savebutton': 'Send email',
})
+
+
+@csrf_exempt
+def thread_notify(request):
+ if request.method != 'POST':
+ return HttpResponseForbidden("Invalid method")
+
+ j = json.loads(request.body)
+ if j['apikey'] != settings.ARCHIVES_APIKEY:
+ return HttpResponseForbidden("Invalid API key")
+
+ for m in j['messageids']:
+ try:
+ t = MailThread.objects.get(messageid=m)
+ refresh_single_thread(t)
+ except Exception, e:
+ # Just ignore it, we'll check again later
+ pass
+
+ return HttpResponse(status=200)
ARCHIVES_SERVER="localhost"
ARCHIVES_PORT="8001"
ARCHIVES_HOST="archives.postgresql.org" # Host: header to send
+ARCHIVES_APIKEY=None
# Email address to pgsql-hackers. Set to something local to test maybe?
HACKERS_EMAIL="pgsql-hackers-testing@localhost"
url(r'^(\d+)/reports/authorstats/$', reports.authorstats),
url(r'^search/$', views.global_search),
url(r'^ajax/(\w+)/$', ajax.main),
+ url(r'^thread_notify/$', views.thread_notify),
url(r'^selectable/', include('selectable.urls')),
from django.db import connection
from pgcommitfest.commitfest.models import MailThread
-from pgcommitfest.commitfest.ajax import _archivesAPI, parse_and_add_attachments
+from pgcommitfest.commitfest.ajax import refresh_single_thread
if __name__ == "__main__":
debug = "--debug" in sys.argv
logging.debug("Checking for updated mail threads in the archives")
for thread in MailThread.objects.filter(patches__commitfests__status__in=(1,2,3)).distinct():
logging.debug("Checking %s in the archives" % thread.messageid)
- r = sorted(_archivesAPI('/message-id.json/%s' % thread.messageid), key=lambda x: x['date'])
- if thread.latestmsgid != r[-1]['msgid']:
- # There is now a newer mail in the thread!
- logging.info("Thread %s updated" % thread.messageid)
- thread.latestmsgid = r[-1]['msgid']
- thread.latestmessage = r[-1]['date']
- thread.latestauthor = r[-1]['from']
- thread.latestsubject = r[-1]['subj']
- thread.save()
- parse_and_add_attachments(r, thread)
- # Potentially update the last mail date - if there wasn't already a mail on each patch
- # from a *different* thread that had an earlier date.
- for p in thread.patches.filter(lastmail__lt=thread.latestmessage):
- logging.debug("Last mail time updated for %s" % thread.messageid)
- p.lastmail = thread.latestmessage
- p.save()
+ refresh_single_thread(thread)
connection.close()
logging.debug("Done.")