1<?php
2/**
3 * Copyright 2014-2017 Horde LLC (http://www.horde.org/)
4 *
5 * See the enclosed file COPYING for license information (LGPL). If you
6 * did not receive this file, see http://www.horde.org/licenses/lgpl21.
7 *
8 * @category  Horde
9 * @copyright 2014-2017 Horde LLC
10 * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
11 * @package   Core
12 */
13
14/**
15 * This class represents the Received header value.
16 *
17 * @author    Michael Slusarz <slusarz@horde.org>
18 * @category  Horde
19 * @copyright 2014-2017 Horde LLC
20 * @license   http://www.horde.org/licenses/lgpl21 LGPL 2.1
21 * @package   Core
22 * @since     2.17.0
23 */
24class Horde_Core_Mime_Headers_Received
25extends Horde_Mime_Headers_Received
26{
27    /**
28     * Generate a 'Received' header for the Web browser -> Horde hop (conforms
29     * to formatting guidelines in RFC 5321 [4.4]).
30     */
31    public static function createHordeHop()
32    {
33        global $conf, $registry, $injector;
34
35        $remote = $registry->remoteHost();
36
37        if (!empty($_SERVER['REMOTE_IDENT'])) {
38            $remote_ident = $_SERVER['REMOTE_IDENT'] . '@' . $remote->host . ' ';
39        } elseif ($remote->host != $remote->addr) {
40            $remote_ident = $remote->host . ' ';
41        } else {
42            $remote_ident = '';
43        }
44
45        $remote_host = $remote->host;
46        if ($remote_host == $remote->addr) {
47            $remote_host = '[' . $remote_host . ']';
48        }
49
50        if (!empty($conf['server']['name'])) {
51            $server_name = $conf['server']['name'];
52        } elseif (!empty($_SERVER['SERVER_NAME'])) {
53            $server_name = $_SERVER['SERVER_NAME'];
54        } elseif (!empty($_SERVER['HTTP_HOST'])) {
55            $server_name = $_SERVER['HTTP_HOST'];
56        } else {
57            $server_name = 'unknown';
58        }
59
60        $is_ssl = $injector->getInstance('Horde_Browser')->usingSSLConnection();
61
62        return new self(
63            null,
64            'from ' . $remote_host . ' (' . $remote_ident .
65            '[' . $remote->addr . ']) ' .
66            'by ' . $server_name . ' (Horde Framework) with HTTP' .
67            ($is_ssl ? 'S' : '') . '; ' . date('r')
68        );
69    }
70
71}
72