3 +--------------------------------------------------------------------+
4 | Copyright CiviCRM LLC. All rights reserved. |
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 |
9 +--------------------------------------------------------------------+
15 * @copyright CiviCRM LLC https://civicrm.org/licensing
19 * Class CRM_Mailing_MailStore_Imap
21 class CRM_Mailing_MailStore_Imap
extends CRM_Mailing_MailStore
{
24 * Connect to the supplied IMAP server and make sure the two mailboxes exist.
28 * @param string $username
29 * Authentication username.
30 * @param string $password
31 * Authentication password.
33 * Whether to use IMAP or IMAPS.
34 * @param string $folder
35 * Name of the inbox folder.
36 * @param bool $useXOAUTH2
37 * Use XOAUTH2 authentication method
39 * @return \CRM_Mailing_MailStore_Imap
41 public function __construct($host, $username, $password, $ssl = TRUE, $folder = 'INBOX', $useXOAUTH2 = FALSE) {
42 // default to INBOX if an empty string
49 print "connecting to $host, authenticating as $username and selecting $folder\n";
54 'listLimit' => defined('MAIL_BATCH_SIZE') ? MAIL_BATCH_SIZE
: 1000,
56 'uidReferencing' => TRUE,
58 $this->_transport
= new ezcMailImapTransport($host, NULL, $options);
60 $this->_transport
->authenticate($username, $password, ezcMailImapTransport
::AUTH_XOAUTH2
);
63 $this->_transport
->authenticate($username, $password);
65 $this->_transport
->selectMailbox($folder);
67 $this->_ignored
= implode($this->_transport
->getHierarchyDelimiter(), [$folder, 'CiviMail', 'ignored']);
68 $this->_processed
= implode($this->_transport
->getHierarchyDelimiter(), [$folder, 'CiviMail', 'processed']);
69 $boxes = $this->_transport
->listMailboxes();
72 print 'mailboxes found: ' . implode(', ', $boxes) . "\n";
75 if (!in_array(strtolower($this->_ignored
), array_map('strtolower', $boxes))) {
76 $this->_transport
->createMailbox($this->_ignored
);
79 if (!in_array(strtolower($this->_processed
), array_map('strtolower', $boxes))) {
80 $this->_transport
->createMailbox($this->_processed
);
85 * Expunge the messages marked for deletion, CRM-7356
87 public function expunge() {
88 $this->_transport
->expunge();
92 * Move the specified message to the ignored folder.
95 * Number of the message to move.
97 public function markIgnored($nr) {
99 print "setting $nr as seen and moving it to the ignored mailbox\n";
101 $this->_transport
->setFlag($nr, 'SEEN');
102 $this->_transport
->copyMessages($nr, $this->_ignored
);
103 $this->_transport
->delete($nr);
107 * Move the specified message to the processed folder.
110 * Number of the message to move.
112 public function markProcessed($nr) {
114 print "setting $nr as seen and moving it to the processed mailbox\n";
116 $this->_transport
->setFlag($nr, 'SEEN');
117 $this->_transport
->copyMessages($nr, $this->_processed
);
118 $this->_transport
->delete($nr);