Package: listadmin / 2.42-1.3

follow_https_redirects Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Description: Make listadmin properly follow redirects to HTTPS-using mailmans
Author: Gunnar Wolf <gwolf@debian.org>
Bug: https://bugs.debian.org/873287
Forwarded: No
Last-Update: 2018-09-20

Index: listadmin-2.42/listadmin.pl
===================================================================
--- listadmin-2.42.orig/listadmin.pl
+++ listadmin-2.42/listadmin.pl
@@ -643,6 +643,9 @@ sub uio_adminurl {
 sub mailman_url {
     my ($list, $pattern, $params, $action) = @_;
 
+    # Calling mailman_url with $pattern often requires the redirects
+    # _NOT_ to be resolved (i.e. for logging)
+    my $nopattern = !( defined($pattern) or $pattern );
     my ($lp, $domain) = split ('@', $list);
 
     $pattern ||= uio_adminurl ($domain);
@@ -659,9 +662,30 @@ sub mailman_url {
 	$url .= "/$action";
     }
     $url .= "?$params" if $params;
+
+    $url = resolve_redirects($url) if $nopattern;
     return $url;
 }
 
+sub resolve_redirects {
+    # Test whether the URL is a redirect and, if so, replace it with
+    # the destination one.
+    my ($url, $resp, $req);
+    $url = shift;
+    $resp = $ua->get($url);
+    # If the URL could not get to the requested URL, there's no point
+    # in trying any further
+    if (! $resp->is_success) {
+	print STDERR "Error: Fetching $url\n";
+	print STDERR $resp->status_line, "\n";
+	return undef;
+    }
+
+    # $req will have the final URI, even if redirects were followed.
+    $req = $resp->request->uri;
+    return $req;
+}
+
 # Returns a ref to a hash with all the information about pending messages
 sub get_list {
     my ($list, $config, $pw) = @_;