*
* @param array $params The configuration parameter array.
*/
- function __construct($params)
+ public function __construct($params)
{
/* Check for missing params. */
$paramlist = $this->getParameterList();
abstract public function getMail();
/**
- * Processes a single mail message by calling any user defined functions,
- * stripping bare newlines, and adding color information to the headers.
- *
- * @param string $header The message header text.
- * @param string $body The message body text.
- *
- * @return string The complete message.
- */
- protected function _processMailMessage($header, $body)
- {
- $msg = rtrim($header);
-
- if (empty($this->_params['acctcolor'])) {
- $msg .= "\nX-color: " . $this->_params['acctcolor'];
- }
- $msg .= "\n\n" . $body;
-
- /* If there is a user defined function, call it with the current
- * message as an argument. */
- if ($GLOBALS['conf']['hooks']['fetchmail_filter']) {
- $msg = Horde::callHook('_imp_hook_fetchmail_filter', array($msg), 'imp');
- }
-
- return $msg;
- }
-
- /**
* Checks the message size to see if it exceeds the maximum value
* allowable in the configuration file.
*
}
/**
- * Add the message to the requested local mailbox.
+ * Add the message to the requested local mailbox, performing any
+ * necessary processing.
*
- * @param string $msg The message text.
+ * @param string $header The message header text.
+ * @param string $body The message body text.
*
* @return boolean True on success, false on failure.
*/
- protected function _addMessage($msg)
+ protected function _addMessage($header, $body)
{
+ $msg = rtrim($header);
+
+ if (empty($this->_params['acctcolor'])) {
+ $msg .= "\nX-color: " . $this->_params['acctcolor'];
+ }
+ $msg .= "\n\n" . $body;
+
+ /* If there is a user defined function, call it with the current
+ * message as an argument. */
+ if ($GLOBALS['conf']['hooks']['fetchmail_filter']) {
+ $msg = Horde::callHook('_imp_hook_fetchmail_filter', array($msg), 'imp');
+ }
+
try {
$GLOBALS['imp_imap']->ob->append($this->_params['lmailbox'], array(array('data' => $msg)));
return true;
/**
* Constructor.
*/
- function __construct()
+ public function __construct()
{
/* Read all the user's accounts from the prefs object or build
* a new account from the standard values given in prefs.php. */
*/
public function getValue($key, $account)
{
- return (isset($this->_accounts[$account][$key])) ? $this->_accounts[$account][$key] : false;
+ return isset($this->_accounts[$account][$key])
+ ? $this->_accounts[$account][$key]
+ : false;
}
/**
*/
public function getAllValues($account)
{
- return (isset($this->_accounts[$account])) ? $this->_accounts[$account] : false;
+ return isset($this->_accounts[$account])
+ ? $this->_accounts[$account]
+ : false;
}
/**
public function getAll($key)
{
$list = array();
+
foreach (array_keys($this->_accounts) as $account) {
$list[$account] = $this->getValue($key, $account);
}
/* These parameters are checkbox items - make sure they are stored
* as boolean values. */
$list = array('del', 'onlynew', 'markseen', 'loginfetch');
- if (in_array($key, $list) && !is_bool($val)) {
- if (($val == 'yes') || (intval($val) != 0)) {
- $val = true;
- } else {
- $val = false;
- }
- }
- $this->_accounts[$account][$key] = $val;
+ $this->_accounts[$account][$key] =
+ (in_array($key, $list) && !is_bool($val) &&
+ (($val == 'yes') || (intval($val) != 0)));
+
$this->_save();
}
'name' => _("POP3"),
'string' => 'pop3',
'port' => 110,
- 'base' => 'POP3'
+ 'base' => 'POP3',
+ 'secure' => false
),
- 'pop3sslvalid' => array(
+ 'pop3tls' => array(
+ 'name' => _("POP3 over TLS"),
+ 'string' => 'pop3',
+ 'port' => 110,
+ 'base' => 'POP3',
+ 'secure' => 'tls'
+ ),
+ 'pop3ssl' => array(
'name' => _("POP3 over SSL"),
'string' => 'pop3',
'port' => 995,
- 'base' => 'POP3'
+ 'base' => 'POP3',
+ 'secure' => 'ssl'
),
'imap' => array(
'name' => _("IMAP"),
'string' => 'imap',
'port' => 143,
- 'base' => 'IMAP'
+ 'base' => 'IMAP',
+ 'secure' => false
+ ),
+ 'imaptls' => array(
+ 'name' => _("IMAP"),
+ 'string' => 'imap over TLS',
+ 'port' => 143,
+ 'base' => 'IMAP',
+ 'secure' => 'tls'
),
'imapsslvalid' => array(
'name' => _("IMAP over SSL"),
'string' => 'imap',
'port' => 993,
- 'base' => 'IMAP'
+ 'base' => 'IMAP',
+ 'secure' => 'ssl'
)
);
}
/**
- * Checks if the remote mailbox exists.
- *
- * @return boolean Does the remote mailbox exist?
- */
- protected function _remoteMboxExists($mbox)
- {
- if (strcasecmp($mbox, 'INBOX') === 0) {
- /* INBOX always exists and is a special case. */
- return true;
- }
-
- try {
- $res = $this->_ob->listMailboxes($mbox, array('flat' => true));
- return (bool)count($res);
- } catch (Horde_Imap_Client_Exception $e) {
- return false;
- }
- }
-
- /**
* Attempts to connect to the mail server
*
* @return mixed Returns true on success or PEAR_Error on failure.
'hostspec' => $this->_params['server'],
'password' => $this->_params['password'],
'port' => $protocols[$this->_params['protocol']]['port'],
- 'username' => $this->_params['username']
- // TODO: secure
+ 'username' => $this->_params['username'],
+ 'secure' => $protocols[$this->_params['protocol']]['secure']
);
try {
*/
public function getMail()
{
- $flags = $to_store = array();
+ $to_store = array();
$numMsgs = 0;
$stream = $this->_connect();
/* Check to see if remote mailbox exists. */
$mbox = $this->_params['rmailbox'];
- if (!$mbox || !$this->_remoteMboxExists($mbox)) {
+
+ /* INBOX always exists and is a special case. */
+ if ($mbox && strcasecmp($mbox, 'INBOX') !== 0) {
+ try {
+ $res = $this->_ob->listMailboxes($mbox, array('flat' => true));
+ if (!count($res)) {
+ $mbox = false;
+ }
+ } catch (Horde_Imap_Client_Exception $e) {
+ $mbox = false;
+ }
+ }
+
+ if (!$mbox) {
return PEAR::raiseError(_("Invalid Remote Mailbox"));
}
}
try {
- $search_res = $GLOBALS['imp_imap']->ob->search($mbox, $query);
+ $search_res = $this->_ob->search($mbox, $query);
if (empty($search_res['match'])) {
return 0;
}
- $fetch_res = $GLOBALS['imp_imap']->ob->fetch($mbox, array(
+ $fetch_res = $this->_ob->fetch($mbox, array(
Horde_Imap_Client::FETCH_ENVELOPE => true,
Horde_Imap_Client::FETCH_SIZE => true
return 0;
}
+ /* Mark message seen if 'markseen' is set. */
+ $peek = !$this->_params['markseen'];
+
reset($fetch_res);
while (list($id, $ob) = each($fetch_res)) {
/* Check message size. */
}
try {
- $res = $GLOBALS['imp_imap']->ob->fetch($this->_mailbox, array(
- Horde_Imap_Client::FETCH_HEADERTEXT => array(array('peek' => true)),
+ $res = $this->_ob->fetch($mbox, array(
+ Horde_Imap_Client::FETCH_HEADERTEXT => array(array('peek' => $peek)),
Horde_Imap_Client::FETCH_BODYTEXT => array(array('peek' => true))
- ), array('ids' => array($this->_index)));
- $mail_source = $this->_processMailMessage($res[$this->_index]['headertext'][0], $res[$this->_index]['bodytext'][0]);
+ ), array('ids' => array($id)));
} catch (Horde_Imap_Client_Exception $e) {
continue;
}
/* Append to the server. */
- if ($this->_addMessage($mail_source)) {
+ if ($this->_addMessage($res[$id]['headertext'][0], $res[$id]['bodytext'][0])) {
++$numMsgs;
$to_store[] = $id;
}
}
/* Remove the mail if 'del' is set. */
- if ($this->_params['del']) {
- $flags[] = '\\deleted';
- }
-
- /* Mark message seen if 'markseen' is set. */
- if ($this->_params['markseen']) {
- $flags[] = '\\seen';
- }
-
- if (!empty($flags)) {
+ if ($numMsgs && $this->_params['del']) {
try {
- $imp_imap->ob->store($mbox, array('add' => $flags, 'ids' => $to_store));
- if ($this->_params['del']) {
- $imp_imap->ob->expunge($mbox, array('ids' => $to_store));
- }
+ $imp_imap->ob->store($mbox, array('add' => array('\\deleted'), 'ids' => $to_store));
+ $imp_imap->ob->expunge($mbox, array('ids' => $to_store));
} catch (Horde_Imap_Client_Exception $e) {}
}