From 7aa610168d0c3a83b38e46a4bbd324a2b02eb556 Mon Sep 17 00:00:00 2001 From: Alex Cabal Date: Fri, 3 Jan 2025 18:46:46 -0600 Subject: [PATCH] Resolve Google Groups URL redirects --- lib/Project.php | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/Project.php b/lib/Project.php index f96a49fb..73e3fb86 100644 --- a/lib/Project.php +++ b/lib/Project.php @@ -218,6 +218,25 @@ final class Project{ $this->DiscussionUrl = null; } else{ + if(preg_match('|^https://groups\.google\.com/d/msgid/|iu', $this->DiscussionUrl)){ + // This URL links to a message which will perform some HTTP redirects to resolve to the actual thread URL. + // Resolve that URL before continuing. + $curl = curl_init(); + + curl_setopt($curl, CURLOPT_HEADER, true); + curl_setopt($curl, CURLOPT_NOBODY, true); + curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); + curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); + + curl_setopt($curl, CURLOPT_URL, $this->DiscussionUrl); + curl_exec($curl); + + /** @var string $url */ + $url = curl_getinfo($curl, CURLINFO_EFFECTIVE_URL); + + $this->DiscussionUrl = $url; + } + if(preg_match('|^https://groups\.google\.com/g/standardebooks/|iu', $this->DiscussionUrl)){ // Get the base thread URL in case we were passed a URL with a specific message or query string. $this->DiscussionUrl = preg_replace('|^(https://groups\.google\.com/g/standardebooks/c/[^/]+).*|iu', '\1', $this->DiscussionUrl);