3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
36 require_once 'ezc/Base/src/ezc_bootstrap.php';
37 require_once 'ezc/autoload/mail_autoload.php';
40 * Class CRM_Mailing_MailStore_Imap
42 class CRM_Mailing_MailStore_Imap
extends CRM_Mailing_MailStore
{
45 * Connect to the supplied IMAP server and make sure the two mailboxes exist
47 * @param string $host host to connect to
48 * @param string $username authentication username
49 * @param string $password authentication password
50 * @param bool $ssl whether to use IMAP or IMAPS
51 * @param string $folder name of the inbox folder
53 * @return \CRM_Mailing_MailStore_Imap
55 function __construct($host, $username, $password, $ssl = TRUE, $folder = 'INBOX') {
56 // default to INBOX if an empty string
63 print "connecting to $host, authenticating as $username and selecting $folder\n";
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);
72 $this->_ignored
= implode($this->_transport
->getHierarchyDelimiter(), array($folder, 'CiviMail', 'ignored'));
73 $this->_processed
= implode($this->_transport
->getHierarchyDelimiter(), array($folder, 'CiviMail', 'processed'));
74 $boxes = $this->_transport
->listMailboxes();
77 print 'mailboxes found: ' . implode(', ', $boxes) . "\n";
80 if (!in_array(strtolower($this->_ignored
), array_map('strtolower', $boxes))) {
81 $this->_transport
->createMailbox($this->_ignored
);
84 if (!in_array(strtolower($this->_processed
), array_map('strtolower', $boxes))) {
85 $this->_transport
->createMailbox($this->_processed
);
90 * Expunge the messages marked for deletion, CRM-7356
93 $this->_transport
->expunge();
97 * Move the specified message to the ignored folder
99 * @param integer $nr number of the message to move
103 function markIgnored($nr) {
105 print "setting $nr as seen and moving it to the ignored mailbox\n";
107 $this->_transport
->setFlag($nr, 'SEEN');
108 $this->_transport
->copyMessages($nr, $this->_ignored
);
109 $this->_transport
->delete($nr);
113 * Move the specified message to the processed folder
115 * @param integer $nr number of the message to move
119 function markProcessed($nr) {
121 print "setting $nr as seen and moving it to the processed mailbox\n";
123 $this->_transport
->setFlag($nr, 'SEEN');
124 $this->_transport
->copyMessages($nr, $this->_processed
);
125 $this->_transport
->delete($nr);