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