File: Email.php

package info (click to toggle)
php-horde-imp 6.2.17-2
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 20,712 kB
  • ctags: 6,649
  • sloc: php: 36,418; xml: 23,136; makefile: 9; sh: 3
file content (118 lines) | stat: -rw-r--r-- 3,305 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
<?php
/**
 * Copyright 2013-2016 Horde LLC (http://www.horde.org/)
 *
 * See the enclosed file COPYING for license information (GPL). If you
 * did not receive this file, see http://www.horde.org/licenses/gpl.
 *
 * @category  Horde
 * @copyright 2013-2016 Horde LLC
 * @license   http://www.horde.org/licenses/gpl GPL
 * @package   IMP
 */

/**
 * Spam reporting driver via e-mail.
 *
 * @author    Michael Slusarz <slusarz@horde.org>
 * @category  Horde
 * @copyright 2013-2016 Horde LLC
 * @license   http://www.horde.org/licenses/gpl GPL
 * @package   IMP
 */
class IMP_Spam_Email implements IMP_Spam_Base
{
    /**
     * Reporting e-mail.
     *
     * @var string
     */
    protected $_email;

    /**
     * E-mail format.
     *
     * @var string
     */
    protected $_format;

    /**
     * Constructor.
     *
     * @param string $email   Reporting e-mail.
     * @param string $format  E-mail format.
     */
    public function __construct($email, $format)
    {
        $this->_email = $email;
        $this->_format = $format;
    }

    /**
     */
    public function report(IMP_Contents $contents, $action)
    {
        global $injector, $registry;

        $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create();

        switch ($this->_format) {
        case 'redirect':
            /* Send the message. */
            try {
                $imp_compose->redirectMessage($contents->getIndicesOb());
                $imp_compose->sendRedirectMessage($this->_email, false);
                return true;
            } catch (IMP_Compose_Exception $e) {
                $e->log();
            }
            break;

        case 'digest':
        default:
            try {
                $from_line = $injector->getInstance('IMP_Identity')->getFromLine();
            } catch (Horde_Exception $e) {
                $from_line = null;
            }

            /* Build the MIME structure. */
            $mime = new Horde_Mime_Part();
            $mime->setType('multipart/digest');

            $rfc822 = new Horde_Mime_Part();
            $rfc822->setType('message/rfc822');
            $rfc822->setContents($contents->fullMessageText(array(
                'stream' => true
            )));

            $mime->addPart($rfc822);

            $spam_headers = new Horde_Mime_Headers();
            $spam_headers->addMessageIdHeader();
            $spam_headers->addHeader('Date', date('r'));
            $spam_headers->addHeader('To', $this->_email);
            if (!is_null($from_line)) {
                $spam_headers->addHeader('From', $from_line);
            }
            $spam_headers->addHeader('Subject', sprintf(_("%s report from %s"), $action == IMP_Spam::SPAM ? 'spam' : 'innocent', $registry->getAuth()));

            /* Send the message. */
            try {
                $recip_list = $imp_compose->recipientList(array(
                    'to' => $this->_email
                ));
                $imp_compose->sendMessage($recip_list['list'], $spam_headers, $mime, 'UTF-8');
                $rfc822->clearContents();
                return true;
            } catch (IMP_Compose_Exception $e) {
                $e->log();
                $rfc822->clearContents();
            }
            break;
        }

        return false;
    }

}