Merge pull request #6002 from christianbeeznest/ofaj-22284

Message: Convert relative links to absolute in email content - refs BT#22284
pull/6006/head
christianbeeznest 9 months ago committed by GitHub
commit e03d1ac1c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 16
      public/main/inc/lib/message.lib.php

@ -352,6 +352,8 @@ class MessageManager
if ($sendEmail) {
$notification = new Notification();
$sender_info = api_get_user_info($user_sender_id);
$baseUrl = $baseUrl ?? api_get_path(WEB_PATH);
$content = self::processRelativeLinks($content, $baseUrl);
// add file attachment additional attributes
$attachmentAddedByMail = [];
@ -422,6 +424,20 @@ class MessageManager
return false;
}
/**
* Converts relative URLs in href and src attributes to absolute URLs.
*/
private static function processRelativeLinks(string $content, string $baseUrl): string
{
return preg_replace_callback(
'/(href|src)="(\/[^"]*)"/',
function ($matches) use ($baseUrl) {
return $matches[1] . '="' . rtrim($baseUrl, '/') . $matches[2] . '"';
},
$content
);
}
/**
* @param int $receiverUserId
* @param string $subject

Loading…
Cancel
Save