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