Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
8c9251b3 | 6 | | Copyright CiviCRM LLC (c) 2004-2018 | |
6a488035 TO |
7 | +--------------------------------------------------------------------+ |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
6a488035 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
8c9251b3 | 31 | * @copyright CiviCRM LLC (c) 2004-2018 |
6a488035 TO |
32 | */ |
33 | ||
28518c90 EM |
34 | /** |
35 | * Class CRM_Mailing_MailStore_Imap | |
36 | */ | |
6a488035 TO |
37 | class CRM_Mailing_MailStore_Imap extends CRM_Mailing_MailStore { |
38 | ||
39 | /** | |
fe482240 | 40 | * Connect to the supplied IMAP server and make sure the two mailboxes exist. |
6a488035 | 41 | * |
90c8230e TO |
42 | * @param string $host |
43 | * Host to connect to. | |
44 | * @param string $username | |
45 | * Authentication username. | |
46 | * @param string $password | |
47 | * Authentication password. | |
48 | * @param bool $ssl | |
49 | * Whether to use IMAP or IMAPS. | |
50 | * @param string $folder | |
51 | * Name of the inbox folder. | |
6a488035 | 52 | * |
dd244018 | 53 | * @return \CRM_Mailing_MailStore_Imap |
6a488035 | 54 | */ |
00be9182 | 55 | public function __construct($host, $username, $password, $ssl = TRUE, $folder = 'INBOX') { |
6a488035 TO |
56 | // default to INBOX if an empty string |
57 | if (!$folder) { | |
58 | $folder = 'INBOX'; | |
59 | } | |
60 | ||
61 | if ($this->_debug) { | |
62 | ||
63 | print "connecting to $host, authenticating as $username and selecting $folder\n"; | |
64 | ||
65 | } | |
66 | ||
67 | $options = array('ssl' => $ssl, 'uidReferencing' => TRUE); | |
68 | $this->_transport = new ezcMailImapTransport($host, NULL, $options); | |
69 | $this->_transport->authenticate($username, $password); | |
70 | $this->_transport->selectMailbox($folder); | |
71 | ||
353ffa53 | 72 | $this->_ignored = implode($this->_transport->getHierarchyDelimiter(), array($folder, 'CiviMail', 'ignored')); |
6a488035 | 73 | $this->_processed = implode($this->_transport->getHierarchyDelimiter(), array($folder, 'CiviMail', 'processed')); |
353ffa53 | 74 | $boxes = $this->_transport->listMailboxes(); |
6a488035 TO |
75 | |
76 | if ($this->_debug) { | |
77 | print 'mailboxes found: ' . implode(', ', $boxes) . "\n"; | |
78 | } | |
79 | ||
80 | if (!in_array(strtolower($this->_ignored), array_map('strtolower', $boxes))) { | |
81 | $this->_transport->createMailbox($this->_ignored); | |
82 | } | |
83 | ||
84 | if (!in_array(strtolower($this->_processed), array_map('strtolower', $boxes))) { | |
85 | $this->_transport->createMailbox($this->_processed); | |
86 | } | |
87 | } | |
88 | ||
89 | /** | |
90 | * Expunge the messages marked for deletion, CRM-7356 | |
91 | */ | |
00be9182 | 92 | public function expunge() { |
6a488035 TO |
93 | $this->_transport->expunge(); |
94 | } | |
95 | ||
96 | /** | |
fe482240 | 97 | * Move the specified message to the ignored folder. |
6a488035 | 98 | * |
90c8230e TO |
99 | * @param int $nr |
100 | * Number of the message to move. | |
6a488035 | 101 | */ |
00be9182 | 102 | public function markIgnored($nr) { |
6a488035 TO |
103 | if ($this->_debug) { |
104 | print "setting $nr as seen and moving it to the ignored mailbox\n"; | |
105 | } | |
106 | $this->_transport->setFlag($nr, 'SEEN'); | |
107 | $this->_transport->copyMessages($nr, $this->_ignored); | |
108 | $this->_transport->delete($nr); | |
109 | } | |
110 | ||
111 | /** | |
fe482240 | 112 | * Move the specified message to the processed folder. |
6a488035 | 113 | * |
90c8230e TO |
114 | * @param int $nr |
115 | * Number of the message to move. | |
6a488035 | 116 | */ |
00be9182 | 117 | public function markProcessed($nr) { |
6a488035 TO |
118 | if ($this->_debug) { |
119 | print "setting $nr as seen and moving it to the processed mailbox\n"; | |
120 | } | |
121 | $this->_transport->setFlag($nr, 'SEEN'); | |
122 | $this->_transport->copyMessages($nr, $this->_processed); | |
123 | $this->_transport->delete($nr); | |
124 | } | |
96025800 | 125 | |
6a488035 | 126 | } |