Fix how the mailinglist subscription form handles parameters
authorMagnus Hagander <magnus@hagander.net>
Sat, 3 Oct 2015 11:02:44 +0000 (13:02 +0200)
committerMagnus Hagander <magnus@hagander.net>
Sat, 3 Oct 2015 11:02:44 +0000 (13:02 +0200)
This was plain broken for things like nomail and digest, but even with
the right syntax it probably did not work right together with the fact
that we require confirmation for subscriptions.

Issue spotted by Amir Rohan, fix suggested by Alvaro Herrera, (broken) code by me

pgweb/lists/views.py

index bb8b44591c2f87cfd403aa8d807a67e1f40f2292..512c01400aec58a8aa702492c85a1ccac08a109f 100644 (file)
@@ -16,16 +16,24 @@ def subscribe(request):
        if request.POST:
                form = SubscribeForm(request.POST)
                if form.is_valid():
-                       mailtxt = ""
                        if form.cleaned_data['action'] == 'subscribe':
-                               mailtxt += "subscribe %s\n" % form.cleaned_data['lists']
                                mailsubject = "subscribe"
-                               if not form.cleaned_data['receive']:
-                                       mailtxt += "set nomail\n"
-                               if form.cleaned_data['digest']:
-                                       mailtxt += "set digest\n"
+                               # Default is get mail and not digest, in which case we send a regular
+                               # subscribe request. In other cases, we send subscribe-set which also
+                               # sets those flags.
+                               if form.cleaned_data['receive'] and not form.cleaned_data['digest']:
+                                       mailtxt = "subscribe %s\n" % form.cleaned_data['lists']
+                               else:
+                                       tags = []
+                                       if not form.cleaned_data['receive']:
+                                               tags.append('nomail')
+                                       if form.cleaned_data['digest']:
+                                               tags.append('digest')
+
+                                       mailtxt = "subscribe-set %s %s\n" % (form.cleaned_data['lists'],
+                                                                                                               ",".join(tags))
                        else:
-                               mailtxt += "unsubscribe %s\n" % form.cleaned_data['lists']
+                               mailtxt = "unsubscribe %s\n" % form.cleaned_data['lists']
                                mailsubject = "unsubscribe"
 
                        send_simple_mail(form.cleaned_data['email'],