Merge pull request #11742 from seanmadsen/NFC-CRM_PCP_Form_Event
[civicrm-core.git] / CRM / Mailing / MailStore / Pop3.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
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
31 * @copyright CiviCRM LLC (c) 2004-2018
32 */
33
34 /**
35 * Class CRM_Mailing_MailStore_Pop3
36 */
37 class CRM_Mailing_MailStore_Pop3 extends CRM_Mailing_MailStore {
38
39 /**
40 * Connect to the supplied POP3 server and make sure the two mail dirs exist
41 *
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 POP3 or POP3S.
50 *
51 * @return \CRM_Mailing_MailStore_Pop3
52 */
53 public function __construct($host, $username, $password, $ssl = TRUE) {
54 if ($this->_debug) {
55 print "connecting to $host and authenticating as $username\n";
56 }
57
58 $options = array('ssl' => $ssl);
59 $this->_transport = new ezcMailPop3Transport($host, NULL, $options);
60 $this->_transport->authenticate($username, $password);
61
62 $this->_ignored = $this->maildir(implode(DIRECTORY_SEPARATOR, array(
63 'CiviMail.ignored',
64 date('Y'),
65 date('m'),
66 date('d'),
67 )));
68 $this->_processed = $this->maildir(implode(DIRECTORY_SEPARATOR, array(
69 'CiviMail.processed',
70 date('Y'),
71 date('m'),
72 date('d'),
73 )));
74 }
75
76 /**
77 * Fetch the specified message to the local ignore folder.
78 *
79 * @param int $nr
80 * Number of the message to fetch.
81 */
82 public function markIgnored($nr) {
83 if ($this->_debug) {
84 print "fetching message $nr and putting it in the ignored mailbox\n";
85 }
86 $set = new ezcMailStorageSet($this->_transport->fetchByMessageNr($nr), $this->_ignored);
87 $parser = new ezcMailParser();
88 $parser->parseMail($set);
89 $this->_transport->delete($nr);
90 }
91
92 /**
93 * Fetch the specified message to the local processed folder.
94 *
95 * @param int $nr
96 * Number of the message to fetch.
97 */
98 public function markProcessed($nr) {
99 if ($this->_debug) {
100 print "fetching message $nr and putting it in the processed mailbox\n";
101 }
102 $set = new ezcMailStorageSet($this->_transport->fetchByMessageNr($nr), $this->_processed);
103 $parser = new ezcMailParser();
104 $parser->parseMail($set);
105 $this->_transport->delete($nr);
106 }
107
108 }