xref: /plugin/smtp/helper.php (revision ee5c02056e482f4a07fb4b075ec45c4dfd3de0e8)
14dc22474SAndreas Gohr<?php
2*ee5c0205SAndreas Gohr
3*ee5c0205SAndreas Gohruse dokuwiki\Extension\Plugin;
4*ee5c0205SAndreas Gohr
54dc22474SAndreas Gohr/**
64dc22474SAndreas Gohr * DokuWiki Plugin smtp (Helper Component)
74dc22474SAndreas Gohr *
84dc22474SAndreas Gohr * @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
94dc22474SAndreas Gohr * @author  Andreas Gohr <andi@splitbrain.org>
104dc22474SAndreas Gohr */
11*ee5c0205SAndreas Gohrclass helper_plugin_smtp extends Plugin
12*ee5c0205SAndreas Gohr{
1327827474SAndreas Gohr    /**
1427827474SAndreas Gohr     * Return a string usable as EHLO message
1527827474SAndreas Gohr     *
16*ee5c0205SAndreas Gohr     * @param string $ehlo configured EHLO (overrides automatic detection)
1727827474SAndreas Gohr     * @return string
1827827474SAndreas Gohr     */
19*ee5c0205SAndreas Gohr    public static function getEHLO($ehlo = '')
20*ee5c0205SAndreas Gohr    {
2127827474SAndreas Gohr        if (empty($ehlo)) {
22*ee5c0205SAndreas Gohr            $ip = $_SERVER["SERVER_ADDR"] ?? '';
23*ee5c0205SAndreas Gohr            if (empty($ip)) {
24ae907de1SMoritz Raguschat                return "localhost.localdomain";
25*ee5c0205SAndreas Gohr            }
26ae907de1SMoritz Raguschat
27ae907de1SMoritz Raguschat            // Indicate IPv6 address according to RFC 2821, if applicable.
28ae907de1SMoritz Raguschat            $colonPos = strpos($ip, ':');
29ae907de1SMoritz Raguschat            if ($colonPos !== false) {
30ae907de1SMoritz Raguschat                $ip = 'IPv6:' . $ip;
31ae907de1SMoritz Raguschat            }
32ae907de1SMoritz Raguschat
33ae907de1SMoritz Raguschat            return "[" . $ip . "]";
3427827474SAndreas Gohr        }
3527827474SAndreas Gohr        return $ehlo;
3627827474SAndreas Gohr    }
374dc22474SAndreas Gohr}
38