Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
7e9e8871 | 4 | | CiviCRM version 4.7 | |
6a488035 | 5 | +--------------------------------------------------------------------+ |
e7112fa7 | 6 | | Copyright CiviCRM LLC (c) 2004-2015 | |
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 | |
e7112fa7 | 31 | * @copyright CiviCRM LLC (c) 2004-2015 |
6a488035 TO |
32 | */ |
33 | ||
34 | require_once 'ezc/Base/src/ezc_bootstrap.php'; | |
35 | require_once 'ezc/autoload/mail_autoload.php'; | |
28518c90 EM |
36 | |
37 | /** | |
38 | * Class CRM_Mailing_MailStore_Imap | |
39 | */ | |
6a488035 TO |
40 | class CRM_Mailing_MailStore_Imap extends CRM_Mailing_MailStore { |
41 | ||
42 | /** | |
fe482240 | 43 | * Connect to the supplied IMAP server and make sure the two mailboxes exist. |
6a488035 | 44 | * |
90c8230e TO |
45 | * @param string $host |
46 | * Host to connect to. | |
47 | * @param string $username | |
48 | * Authentication username. | |
49 | * @param string $password | |
50 | * Authentication password. | |
51 | * @param bool $ssl | |
52 | * Whether to use IMAP or IMAPS. | |
53 | * @param string $folder | |
54 | * Name of the inbox folder. | |
6a488035 | 55 | * |
dd244018 | 56 | * @return \CRM_Mailing_MailStore_Imap |
6a488035 | 57 | */ |
00be9182 | 58 | public function __construct($host, $username, $password, $ssl = TRUE, $folder = 'INBOX') { |
6a488035 TO |
59 | // default to INBOX if an empty string |
60 | if (!$folder) { | |
61 | $folder = 'INBOX'; | |
62 | } | |
63 | ||
64 | if ($this->_debug) { | |
65 | ||
66 | print "connecting to $host, authenticating as $username and selecting $folder\n"; | |
67 | ||
68 | } | |
69 | ||
70 | $options = array('ssl' => $ssl, 'uidReferencing' => TRUE); | |
71 | $this->_transport = new ezcMailImapTransport($host, NULL, $options); | |
72 | $this->_transport->authenticate($username, $password); | |
73 | $this->_transport->selectMailbox($folder); | |
74 | ||
353ffa53 | 75 | $this->_ignored = implode($this->_transport->getHierarchyDelimiter(), array($folder, 'CiviMail', 'ignored')); |
6a488035 | 76 | $this->_processed = implode($this->_transport->getHierarchyDelimiter(), array($folder, 'CiviMail', 'processed')); |
353ffa53 | 77 | $boxes = $this->_transport->listMailboxes(); |
6a488035 TO |
78 | |
79 | if ($this->_debug) { | |
80 | print 'mailboxes found: ' . implode(', ', $boxes) . "\n"; | |
81 | } | |
82 | ||
83 | if (!in_array(strtolower($this->_ignored), array_map('strtolower', $boxes))) { | |
84 | $this->_transport->createMailbox($this->_ignored); | |
85 | } | |
86 | ||
87 | if (!in_array(strtolower($this->_processed), array_map('strtolower', $boxes))) { | |
88 | $this->_transport->createMailbox($this->_processed); | |
89 | } | |
90 | } | |
91 | ||
92 | /** | |
93 | * Expunge the messages marked for deletion, CRM-7356 | |
94 | */ | |
00be9182 | 95 | public function expunge() { |
6a488035 TO |
96 | $this->_transport->expunge(); |
97 | } | |
98 | ||
99 | /** | |
fe482240 | 100 | * Move the specified message to the ignored folder. |
6a488035 | 101 | * |
90c8230e TO |
102 | * @param int $nr |
103 | * Number of the message to move. | |
6a488035 | 104 | */ |
00be9182 | 105 | public function markIgnored($nr) { |
6a488035 TO |
106 | if ($this->_debug) { |
107 | print "setting $nr as seen and moving it to the ignored mailbox\n"; | |
108 | } | |
109 | $this->_transport->setFlag($nr, 'SEEN'); | |
110 | $this->_transport->copyMessages($nr, $this->_ignored); | |
111 | $this->_transport->delete($nr); | |
112 | } | |
113 | ||
114 | /** | |
fe482240 | 115 | * Move the specified message to the processed folder. |
6a488035 | 116 | * |
90c8230e TO |
117 | * @param int $nr |
118 | * Number of the message to move. | |
6a488035 | 119 | */ |
00be9182 | 120 | public function markProcessed($nr) { |
6a488035 TO |
121 | if ($this->_debug) { |
122 | print "setting $nr as seen and moving it to the processed mailbox\n"; | |
123 | } | |
124 | $this->_transport->setFlag($nr, 'SEEN'); | |
125 | $this->_transport->copyMessages($nr, $this->_processed); | |
126 | $this->_transport->delete($nr); | |
127 | } | |
96025800 | 128 | |
6a488035 | 129 | } |