Browse Source

Update Core\Mail

Fix hostname() method.
Visman 4 years ago
parent
commit
fdc213aea4
1 changed files with 16 additions and 3 deletions
  1. 16 3
      app/Core/Mail.php

+ 16 - 3
app/Core/Mail.php

@@ -643,9 +643,22 @@ class Mail
      */
     protected function hostname(): string
     {
-        return empty($_SERVER['SERVER_NAME'])
-            ? (isset($_SERVER['SERVER_ADDR']) ? '[' . $_SERVER['SERVER_ADDR'] . ']' : '[127.0.0.1]')
-            : $_SERVER['SERVER_NAME'];
+        $name = $_SERVER['SERVER_NAME'] ?? null;
+        $ip   = $_SERVER['SERVER_ADDR'] ?? '';
+
+        if ($name) {
+            $name = \preg_replace('%[\x00-\x1F]%', '', \trim($name)); // ????
+        } else {
+            $name = '[127.0.0.1]';
+
+            if (\filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV4)) {
+                $name = "[{$ip}]";
+            } elseif (\filter_var($ip, \FILTER_VALIDATE_IP, \FILTER_FLAG_IPV6)) {
+                $name = "[IPv6:{$ip}]";
+            }
+        }
+
+        return $name;
     }
 
     /**