Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
bc77d7c0 | 4 | | Copyright CiviCRM LLC. All rights reserved. | |
6a488035 | 5 | | | |
bc77d7c0 TO |
6 | | This work is published under the GNU AGPLv3 license with some | |
7 | | permitted exceptions and without any warranty. For full license | | |
8 | | and copyright information, see https://civicrm.org/licensing | | |
6a488035 | 9 | +--------------------------------------------------------------------+ |
d25dd0ee | 10 | */ |
6a488035 TO |
11 | |
12 | /** | |
13 | * | |
14 | * @package CRM | |
ca5cec67 | 15 | * @copyright CiviCRM LLC https://civicrm.org/licensing |
6a488035 TO |
16 | */ |
17 | ||
28518c90 EM |
18 | /** |
19 | * Class CRM_Mailing_MailStore_Imap | |
20 | */ | |
6a488035 TO |
21 | class CRM_Mailing_MailStore_Imap extends CRM_Mailing_MailStore { |
22 | ||
23 | /** | |
fe482240 | 24 | * Connect to the supplied IMAP server and make sure the two mailboxes exist. |
6a488035 | 25 | * |
90c8230e TO |
26 | * @param string $host |
27 | * Host to connect to. | |
28 | * @param string $username | |
29 | * Authentication username. | |
30 | * @param string $password | |
31 | * Authentication password. | |
32 | * @param bool $ssl | |
33 | * Whether to use IMAP or IMAPS. | |
34 | * @param string $folder | |
35 | * Name of the inbox folder. | |
6a488035 | 36 | * |
dd244018 | 37 | * @return \CRM_Mailing_MailStore_Imap |
6a488035 | 38 | */ |
00be9182 | 39 | public function __construct($host, $username, $password, $ssl = TRUE, $folder = 'INBOX') { |
6a488035 TO |
40 | // default to INBOX if an empty string |
41 | if (!$folder) { | |
42 | $folder = 'INBOX'; | |
43 | } | |
44 | ||
45 | if ($this->_debug) { | |
46 | ||
47 | print "connecting to $host, authenticating as $username and selecting $folder\n"; | |
48 | ||
49 | } | |
50 | ||
be2fb01f | 51 | $options = ['ssl' => $ssl, 'uidReferencing' => TRUE]; |
6a488035 TO |
52 | $this->_transport = new ezcMailImapTransport($host, NULL, $options); |
53 | $this->_transport->authenticate($username, $password); | |
54 | $this->_transport->selectMailbox($folder); | |
55 | ||
be2fb01f CW |
56 | $this->_ignored = implode($this->_transport->getHierarchyDelimiter(), [$folder, 'CiviMail', 'ignored']); |
57 | $this->_processed = implode($this->_transport->getHierarchyDelimiter(), [$folder, 'CiviMail', 'processed']); | |
353ffa53 | 58 | $boxes = $this->_transport->listMailboxes(); |
6a488035 TO |
59 | |
60 | if ($this->_debug) { | |
61 | print 'mailboxes found: ' . implode(', ', $boxes) . "\n"; | |
62 | } | |
63 | ||
64 | if (!in_array(strtolower($this->_ignored), array_map('strtolower', $boxes))) { | |
65 | $this->_transport->createMailbox($this->_ignored); | |
66 | } | |
67 | ||
68 | if (!in_array(strtolower($this->_processed), array_map('strtolower', $boxes))) { | |
69 | $this->_transport->createMailbox($this->_processed); | |
70 | } | |
71 | } | |
72 | ||
73 | /** | |
74 | * Expunge the messages marked for deletion, CRM-7356 | |
75 | */ | |
00be9182 | 76 | public function expunge() { |
6a488035 TO |
77 | $this->_transport->expunge(); |
78 | } | |
79 | ||
80 | /** | |
fe482240 | 81 | * Move the specified message to the ignored folder. |
6a488035 | 82 | * |
90c8230e TO |
83 | * @param int $nr |
84 | * Number of the message to move. | |
6a488035 | 85 | */ |
00be9182 | 86 | public function markIgnored($nr) { |
6a488035 TO |
87 | if ($this->_debug) { |
88 | print "setting $nr as seen and moving it to the ignored mailbox\n"; | |
89 | } | |
90 | $this->_transport->setFlag($nr, 'SEEN'); | |
91 | $this->_transport->copyMessages($nr, $this->_ignored); | |
92 | $this->_transport->delete($nr); | |
93 | } | |
94 | ||
95 | /** | |
fe482240 | 96 | * Move the specified message to the processed folder. |
6a488035 | 97 | * |
90c8230e TO |
98 | * @param int $nr |
99 | * Number of the message to move. | |
6a488035 | 100 | */ |
00be9182 | 101 | public function markProcessed($nr) { |
6a488035 TO |
102 | if ($this->_debug) { |
103 | print "setting $nr as seen and moving it to the processed mailbox\n"; | |
104 | } | |
105 | $this->_transport->setFlag($nr, 'SEEN'); | |
106 | $this->_transport->copyMessages($nr, $this->_processed); | |
107 | $this->_transport->delete($nr); | |
108 | } | |
96025800 | 109 | |
6a488035 | 110 | } |