Exemplo n.º 1
0
 /**
  */
 public function update(Horde_Core_Prefs_Ui $ui)
 {
     $alist = new Horde_Mail_Rfc822_List(preg_split("/[\r\n]+/", $ui->vars->safe_addrs));
     $alist->unique();
     if ($GLOBALS['prefs']->setValue('image_replacement_addrs', json_encode($alist->bare_addresses))) {
         $this->_addrlist = $alist;
         return true;
     }
     return false;
 }
Exemplo n.º 2
0
 /**
  * @return string
  */
 public function getEmail()
 {
     $allAccounts = $this->accountService->findByUserId($this->userId);
     $addressesList = new \Horde_Mail_Rfc822_List();
     foreach ($allAccounts as $account) {
         $inbox = $account->getInbox();
         if (is_null($inbox)) {
             continue;
         }
         $addressesList->add($account->getEmail());
     }
     return $addressesList;
 }
Exemplo n.º 3
0
 /**
  * Add objects to the container.
  *
  * @param mixed $obs  A RFC 822 object (or list of objects) to store in
  *                    this object.
  */
 public function add($obs)
 {
     if ($obs instanceof Horde_Mail_Rfc822_Object) {
         $obs = array($obs);
     }
     foreach ($obs as $val) {
         /* Only allow addresses. */
         if ($val instanceof Horde_Mail_Rfc822_Address) {
             parent::add($val);
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Parse an address list created by the dynamic view JS code.
  *
  * @param string $json  JSON input code.
  *
  * @return Horde_Mail_Rfc822_List  A list of addresses.
  */
 public function parseAddressList($json)
 {
     $data = json_decode($json);
     $out = new Horde_Mail_Rfc822_List();
     if (isset($data->g)) {
         $addrs = $data->a;
         $ob = new Horde_Mail_Rfc822_Group($data->g);
         $ob_add = $ob->addresses;
         $out->add($ob);
     } else {
         $addrs = array($data);
         $ob_add = $out;
     }
     foreach ($addrs as $jval) {
         $addr_ob = new Horde_Mail_Rfc822_Address($jval->b);
         if (isset($jval->p)) {
             $addr_ob->personal = $jval->p;
         }
         $ob_add->add($addr_ob);
     }
     return $out;
 }
Exemplo n.º 5
0
 /**
  * TODO
  *
  * @param array $attendees
  *
  * @return Horde_Mail_Rfc822_List
  */
 public static function getAttendeeEmailList($attendees)
 {
     $a_list = new Horde_Mail_Rfc822_List();
     foreach ($attendees as $mail => $attendee) {
         $tmp = new Horde_Mail_Rfc822_Address($mail);
         if (!empty($attendee['name'])) {
             $tmp->personal = $attendee['name'];
         }
         $a_list->add($tmp);
     }
     return $a_list;
 }
Exemplo n.º 6
0
Arquivo: Api.php Projeto: Gomez/horde
 /**
  * Returns a contact search result.
  *
  * @param mixed $names  The search filter values.
  * @param array $opts   Optional parameters:
  *   - customStrict: (array) An array of fields that must match exactly.
  *                   DEFAULT: None
  *   - fields: (array) The fields to search on.
  *             DEFAULT: Search all configured search fields.
  *   - forceSource: (boolean) Whether to use the specified sources, even
  *                  if they have been disabled in the preferences?
  *                  DEFAULT: false
  *   - matchBegin: (boolean) Match word boundaries only?
  *                 DEFAULT: false
  *   - returnFields: Only return these fields.
  *                   DEFAULT: Return all fields.
  *   - rfc822Return: Return a Horde_Mail_Rfc822_List object.
  *                   DEFAULT: Returns an array of search results.
  *   - sources: (array) The sources to search in.
  *              DEFAULT: Search the user's default address book
  *   - count_only: (boolean) If true, only return the count of matching
  *                           results.
  *                 DEFAULT: false (Return the full data set).
  *
  * @return mixed  Either a hash containing the search results or a
  *                Rfc822 List object (if 'rfc822Return' is true).
  * @throws Turba_Exception
  */
 public function search($names = null, array $opts = array())
 {
     global $attributes, $cfgSources, $injector;
     $opts = array_merge(array('fields' => array(), 'forceSource' => false, 'matchBegin' => false, 'returnFields' => array(), 'rfc822Return' => false, 'sources' => array(), 'customStrict' => array(), 'count_only' => false), $opts);
     $results = !empty($opts['count_only']) ? 0 : (empty($opts['rfc822Return']) ? array() : new Horde_Mail_Rfc822_List());
     if (!isset($cfgSources) || !is_array($cfgSources) || !count($cfgSources) || is_null($names)) {
         return $results;
     }
     if (!is_array($names)) {
         $names = array($names);
     }
     if (!$opts['forceSource']) {
         // Make sure the selected source is activated in Turba.
         $addressbooks = array_keys(Turba::getAddressBooks());
         foreach (array_keys($opts['sources']) as $id) {
             if (!in_array($opts['sources'][$id], $addressbooks)) {
                 unset($opts['sources'][$id]);
             }
         }
     }
     // ...and ensure the default source is used as a default.
     if (!count($opts['sources'])) {
         $opts['sources'] = array(Turba::getDefaultAddressbook());
     }
     $driver = $injector->getInstance('Turba_Factory_Driver');
     foreach ($opts['sources'] as $source) {
         // Skip invalid sources -or-
         // skip sources that aren't browseable if the search is empty.
         if (!isset($cfgSources[$source]) || empty($cfgSources[$source]['browse']) && (!count($names) || count($names) == 1 && empty($names[0]))) {
             continue;
         }
         if (empty($opts['fields'][$source])) {
             $opts['fields'][$source] = $GLOBALS['cfgSources'][$source]['search'];
         }
         $sdriver = $driver->create($source);
         foreach ($names as $name) {
             $trimname = trim($name);
             $out = $criteria = array();
             unset($tname);
             if (strlen($trimname)) {
                 if (isset($opts['fields'][$source])) {
                     foreach ($opts['fields'][$source] as $field) {
                         $criteria[$field] = $trimname;
                     }
                 }
             }
             try {
                 $search = $sdriver->search($criteria, Turba::getPreferredSortOrder(), 'OR', $opts['returnFields'], $opts['customStrict'], $opts['matchBegin'], $opts['count_only']);
             } catch (Exception $e) {
                 continue;
             }
             if ($opts['count_only']) {
                 $results += $search;
                 continue;
             } elseif (!$search instanceof Turba_List) {
                 continue;
             }
             $rfc822 = new Horde_Mail_Rfc822();
             while ($ob = $search->next()) {
                 $emails = $seen = array();
                 if ($ob->isGroup()) {
                     /* Is a distribution list. */
                     $members = $ob->listMembers();
                     if (!$members instanceof Turba_List || !count($members)) {
                         continue;
                     }
                     $listatt = $ob->getAttributes();
                     $listName = $ob->getValue('name');
                     while ($ob = $members->next()) {
                         foreach (array_keys($ob->getAttributes()) as $key) {
                             $value = $ob->getValue($key);
                             if (empty($value)) {
                                 continue;
                             }
                             $seen_key = trim(Horde_String::lower($ob->getValue('name'))) . trim(Horde_String::lower(is_array($value) ? $value['load']['file'] : $value));
                             if (isset($attributes[$key]) && $attributes[$key]['type'] == 'email' && empty($seen[$seen_key])) {
                                 $emails[] = $value;
                                 $seen[$seen_key] = true;
                             }
                         }
                     }
                     if (empty($opts['rfc822Return'])) {
                         $out[] = array('email' => implode(', ', $emails), 'id' => $listatt['__key'], 'name' => $listName, 'source' => $source);
                     } else {
                         $results->add(new Horde_Mail_Rfc822_Group($listName, $emails));
                     }
                 } else {
                     /* Not a group. */
                     $att = array('__key' => $ob->getValue('__key'));
                     foreach (array_keys($ob->driver->getCriteria()) as $key) {
                         $att[$key] = $ob->getValue($key);
                     }
                     $email = new Horde_Mail_Rfc822_List();
                     $display_name = $ob->hasValue('name') || !isset($ob->driver->alternativeName) ? Turba::formatName($ob) : $ob->getValue($ob->driver->alternativeName);
                     unset($tdisplay_name);
                     foreach (array_keys($att) as $key) {
                         if ($ob->getValue($key) && isset($attributes[$key]) && $attributes[$key]['type'] == 'email') {
                             $e_val = $ob->getValue($key);
                             if (strlen($trimname)) {
                                 /* Ticket #12480: Don't return email if it
                                  * doesn't contain the search string, since
                                  * an entry can contain multiple e-mail
                                  * fields. Return all e-mails if it
                                  * occurs in the name. */
                                 if (!isset($tname)) {
                                     $tname = Horde_String_Transliterate::toAscii($name);
                                 }
                                 if (!isset($tdisplay_name)) {
                                     $tdisplay_name = Horde_String_Transliterate::toAscii($display_name);
                                 }
                                 $add = Horde_String::ipos(Horde_String_Transliterate::toAscii($e_val), $tname) !== false || Horde_String::ipos($tdisplay_name, $tname) !== false;
                             } else {
                                 $add = true;
                             }
                             if ($add) {
                                 // Multiple addresses support
                                 $email->add($rfc822->parseAddressList($e_val, array('limit' => isset($attributes[$key]['params']) && is_array($attributes[$key]['params']) && !empty($attributes[$key]['params']['allow_multi']) ? 0 : 1)));
                             }
                         }
                     }
                     if (count($email)) {
                         foreach ($email as $val) {
                             $seen_key = trim(Horde_String::lower($display_name)) . '/' . Horde_String::lower($val->bare_address);
                             if (empty($seen[$seen_key])) {
                                 $seen[$seen_key] = true;
                                 if (empty($opts['rfc822Return'])) {
                                     $emails[] = $val->bare_address;
                                 } else {
                                     $val->personal = $display_name;
                                     $results->add($val);
                                 }
                             }
                         }
                     } elseif (empty($opts['rfc822Return'])) {
                         $emails[] = null;
                     }
                     if (empty($opts['rfc822Return'])) {
                         foreach ($emails as $val) {
                             $out[] = array_merge($att, array('__type' => 'Object', 'email' => $val, 'id' => $att['__key'], 'name' => $display_name, 'source' => $source));
                         }
                     }
                 }
             }
             if (!empty($out)) {
                 $results[$name] = $out;
             }
         }
     }
     return $results;
 }
Exemplo n.º 7
0
Arquivo: Mail.php Projeto: horde/horde
 /**
  * Sends a SMART response.
  *
  * @throws Horde_ActiveSync_Exception
  */
 protected function _sendSmart()
 {
     $mime_message = $this->_raw->getMimeObject();
     // Need to remove content-type header from the incoming raw message
     // since in a smart request, we actually construct the full MIME msg
     // ourselves and the content-type in _headers only applies to the reply
     // text sent from the client, not the fully generated MIME message.
     $this->_headers->removeHeader('Content-Type');
     $this->_headers->removeHeader('Content-Transfer-Encoding');
     // Check for EAS 16.0 Forwardees
     if (!empty($this->_forwardees)) {
         $list = new Horde_Mail_Rfc822_List();
         foreach ($this->_forwardees as $forwardee) {
             $to = new Horde_Mail_Rfc822_Address($forwardee->email);
             $to->personal = $forwardee->name;
             $list->add($to);
         }
         $this->_headers->add('To', $list->writeAddress());
     }
     $mail = new Horde_Mime_Mail($this->_headers->toArray(array('charset' => 'UTF-8')));
     $base_part = $this->imapMessage->getStructure();
     $plain_id = $base_part->findBody('plain');
     $html_id = $base_part->findBody('html');
     try {
         $body_data = $this->imapMessage->getMessageBodyData(array('protocolversion' => $this->_version, 'bodyprefs' => array(Horde_ActiveSync::BODYPREF_TYPE_MIME => true)));
     } catch (Horde_Exception_NotFound $e) {
         throw new Horde_ActiveSync_Exception($e->getMessage());
     }
     if (!empty($html_id)) {
         $mail->setHtmlBody($this->_getHtmlPart($html_id, $mime_message, $body_data, $base_part));
     } elseif (!empty($plain_id)) {
         $mail->setBody($this->_getPlainPart($plain_id, $mime_message, $body_data, $base_part));
     }
     if ($this->_forward) {
         foreach ($base_part->contentTypeMap() as $mid => $type) {
             if ($this->imapMessage->isAttachment($mid, $type)) {
                 $mail->addMimePart($this->imapMessage->getMimePart($mid));
             }
         }
     }
     foreach ($mime_message->contentTypeMap() as $mid => $type) {
         if ($mid != 0 && $mid != $mime_message->findBody('plain') && $mid != $mime_message->findBody('html')) {
             $mail->addMimePart($mime_message->getPart($mid));
         }
     }
     try {
         $mail->send($GLOBALS['injector']->getInstance('Horde_Mail'));
         $this->_mailer = $mail;
     } catch (Horde_Mime_Exception $e) {
         throw new Horde_ActiveSync_Exception($e);
     }
 }
Exemplo n.º 8
0
 /**
  * @dataProvider matchProvider
  */
 public function testMatch($compare, $result)
 {
     $ob = new Horde_Mail_Rfc822_List(array('*****@*****.**', '*****@*****.**'));
     if ($result) {
         $this->assertTrue($ob->match($compare));
     } else {
         $this->assertFalse($ob->match($compare));
     }
 }
Exemplo n.º 9
0
 /**
  * Removes message recipients.
  *
  * @param string|array  List of recipients, either as a comma separated
  *                      list or as an array of email addresses.
  *
  * @throws Horde_Mime_Exception
  */
 public function removeRecipients($recipients)
 {
     $this->_recipients->remove($recipients);
 }
Exemplo n.º 10
0
 /**
  * Parse ENVELOPE data from a FETCH return (see RFC 3501 [7.4.2]).
  *
  * @param Horde_Imap_Client_Tokenize $data  Data returned from the server.
  *
  * @return Horde_Imap_Client_Data_Envelope  An envelope object.
  */
 protected function _parseEnvelope(Horde_Imap_Client_Tokenize $data)
 {
     // 'route', the 2nd element, is deprecated by RFC 2822.
     $addr_structure = array(0 => 'personal', 2 => 'mailbox', 3 => 'host');
     $env_data = array(0 => 'date', 1 => 'subject', 2 => 'from', 3 => 'sender', 4 => 'reply_to', 5 => 'to', 6 => 'cc', 7 => 'bcc', 8 => 'in_reply_to', 9 => 'message_id');
     $addr_ob = new Horde_Mail_Rfc822_Address();
     $env_addrs = $this->getParam('envelope_addrs');
     $env_str = $this->getParam('envelope_string');
     $key = 0;
     $ret = new Horde_Imap_Client_Data_Envelope();
     while (($val = $data->next()) !== false) {
         if (!isset($env_data[$key]) || is_null($val)) {
             ++$key;
             continue;
         }
         if (is_string($val)) {
             // These entries are text fields.
             $ret->{$env_data}[$key] = substr($val, 0, $env_str);
         } else {
             // These entries are address structures.
             $group = null;
             $key2 = 0;
             $tmp = new Horde_Mail_Rfc822_List();
             while ($data->next() !== false) {
                 $a_val = $data->flushIterator();
                 // RFC 3501 [7.4.2]: Group entry when host is NIL.
                 // Group end when mailbox is NIL; otherwise, this is
                 // mailbox name.
                 if (is_null($a_val[3])) {
                     if (is_null($a_val[2])) {
                         $group = null;
                     } else {
                         $group = new Horde_Mail_Rfc822_Group($a_val[2]);
                         $tmp->add($group);
                     }
                 } else {
                     $addr = clone $addr_ob;
                     foreach ($addr_structure as $add_key => $add_val) {
                         if (!is_null($a_val[$add_key])) {
                             $addr->{$add_val} = $a_val[$add_key];
                         }
                     }
                     if ($group) {
                         $group->addresses->add($addr);
                     } else {
                         $tmp->add($addr);
                     }
                 }
                 if (++$key2 >= $env_addrs) {
                     $data->flushIterator(false);
                     break;
                 }
             }
             $ret->{$env_data}[$key] = $tmp;
         }
         ++$key;
     }
     return $ret;
 }
Exemplo n.º 11
0
Arquivo: List.php Projeto: horde/horde
 /**
  * Returns a list of email address objects.
  *
  * @return Horde_Mail_Rfc822_List  This list of attendees.
  */
 public function getEmailList()
 {
     $a_list = new Horde_Mail_Rfc822_List();
     foreach ($this as $attendee) {
         $a_list->add($attendee->addressObject);
     }
     return $a_list;
 }
Exemplo n.º 12
0
 /**
  * Store a rule.
  *
  * @param integer $action  Storage action.
  * @param Ingo_Rule $rule  Rule the action affects.
  */
 protected function _store($action, $rule = null)
 {
     global $session;
     $this->_storeBackend($action, $rule);
     switch ($action) {
         case self::STORE_UPDATE:
             if ($rule instanceof Ingo_Rule_System_Blacklist) {
                 $tmp = $this->getSystemRule('Ingo_Rule_System_Whitelist');
             } elseif ($rule instanceof Ingo_Rule_System_Whitelist) {
                 $tmp = $this->getSystemRule('Ingo_Rule_System_Blacklist');
             } else {
                 $tmp = null;
             }
             if (!is_null($tmp)) {
                 /* Filter out the rule's addresses in the opposite filter. */
                 $ob = new Horde_Mail_Rfc822_List($tmp->addresses);
                 $ob->setIteratorFilter(0, $rule->addresses);
                 $tmp->addresses = $ob->bare_addresses;
                 $this->_storeBackend($action, $tmp);
             }
             break;
     }
     $session->set('ingo', 'change', time());
 }
Exemplo n.º 13
0
 /**
  * group           = display-name ":" [mailbox-list / CFWS] ";" [CFWS]
  * display-name    = phrase
  *
  * @return boolean  True if a group was parsed.
  *
  * @throws Horde_Mail_Exception
  */
 protected function _parseGroup()
 {
     $this->_rfc822ParsePhrase($groupname);
     if ($this->_curr(true) != ':') {
         return false;
     }
     $addresses = new Horde_Mail_Rfc822_GroupList();
     $this->_rfc822SkipLwsp();
     while (($chr = $this->_curr()) !== false) {
         if ($chr == ';') {
             ++$this->_ptr;
             if (count($addresses)) {
                 $this->_listob->add(new Horde_Mail_Rfc822_Group($groupname, $addresses));
             }
             return true;
         }
         /* mailbox-list = (mailbox *("," mailbox)) / obs-mbox-list */
         $addresses->add($this->_parseMailbox());
         switch ($this->_curr()) {
             case ',':
                 $this->_rfc822SkipLwsp(true);
                 break;
             case ';':
                 // No-op
                 break;
             default:
                 break 2;
         }
     }
     throw new Horde_Mail_Exception('Error when parsing group.');
 }
Exemplo n.º 14
0
 /**
  * Updates a list (blacklist/whitelist) filter.
  *
  * @param mixed $addresses  Addresses of the filter.
  * @param integer $type     Type of filter.
  *
  * @return Horde_Storage_Rule  The filter object.
  */
 public static function updateListFilter($addresses, $type)
 {
     global $injector;
     $storage = $injector->getInstance('Ingo_Factory_Storage')->create();
     $rule = $storage->retrieve($type);
     switch ($type) {
         case $storage::ACTION_BLACKLIST:
             $rule->setBlacklist($addresses);
             $addr = $rule->getBlacklist();
             $rule2 = $storage->retrieve($storage::ACTION_WHITELIST);
             $addr2 = $rule2->getWhitelist();
             break;
         case $storage::ACTION_WHITELIST:
             $rule->setWhitelist($addresses);
             $addr = $rule->getWhitelist();
             $rule2 = $storage->retrieve($storage::ACTION_BLACKLIST);
             $addr2 = $rule2->getBlacklist();
             break;
     }
     /* Filter out the rule's addresses in the opposite filter. */
     $ob = new Horde_Mail_Rfc822_List($addr2);
     $ob->setIteratorFilter(0, $addr);
     switch ($type) {
         case $storage::ACTION_BLACKLIST:
             $rule2->setWhitelist($ob->bare_addresses);
             break;
         case $storage::ACTION_WHITELIST:
             $rule2->setBlacklist($ob->bare_addresses);
             break;
     }
     $storage->store($rule);
     $storage->store($rule2);
     return $rule;
 }
Exemplo n.º 15
0
 /**
  */
 public function __set($name, $data)
 {
     switch ($name) {
         case 'days':
             $this->_days = intval($data);
             break;
         case 'end':
             $this->_end = intval($data);
             break;
         case 'exclude':
             $exclude = new Horde_Mail_Rfc822_List(is_array($data) ? $data : preg_split("/\\s+/", $data));
             $exclude->unique();
             $this->_exclude = $exclude->bare_addresses;
             break;
         case 'ignore_list':
             $this->_ignoreList = (bool) $data;
             break;
         case 'reason':
             $this->_reason = strval($data);
             break;
         case 'start':
             $this->_start = intval($data);
             break;
         case 'subject':
             $this->_subject = strval($data);
             break;
         default:
             parent::__set($name, $data);
             break;
     }
 }
Exemplo n.º 16
0
 /**
  * Function to manage an internal address list.
  *
  * @param mixed $data  The incoming data (array or string).
  *
  * @return array  The address list.
  */
 protected function _addressList($data)
 {
     $ob = new Horde_Mail_Rfc822_List(is_array($data) ? $data : preg_split("/\\s+/", $data));
     $ob->unique();
     return $ob->bare_addresses;
 }
Exemplo n.º 17
0
 /**
  * @param string $ownMail
  */
 public function getReplyCcList($ownMail)
 {
     $e = $this->getEnvelope();
     $list = new \Horde_Mail_Rfc822_List();
     $list->add($e->to);
     $list->add($e->cc);
     $list->unique();
     $list->remove($ownMail);
     return $this->convertAddressList($list);
 }
Exemplo n.º 18
0
 /**
  * Cleans up and returns the recipient list. Method designed to parse
  * user entered data; does not encode/validate addresses.
  *
  * @param array $hdr  An array of MIME headers and/or address list
  *                    objects. Recipients will be extracted from the 'to',
  *                    'cc', and 'bcc' entries.
  *
  * @return array  An array with the following entries:
  *   - has_input: (boolean) True if at least one of the headers contains
  *                user input.
  *   - header: (array) Contains the cleaned up 'to', 'cc', and 'bcc'
  *             address list (Horde_Mail_Rfc822_List objects).
  *   - list: (Horde_Mail_Rfc822_List) Recipient addresses.
  */
 public function recipientList($hdr)
 {
     $addrlist = new Horde_Mail_Rfc822_List();
     $has_input = false;
     $header = array();
     foreach (array('to', 'cc', 'bcc') as $key) {
         if (isset($hdr[$key])) {
             $ob = IMP::parseAddressList($hdr[$key]);
             if (count($ob)) {
                 $addrlist->add($ob);
                 $header[$key] = $ob;
                 $has_input = true;
             } else {
                 $header[$key] = null;
             }
         }
     }
     return array('has_input' => $has_input, 'header' => $header, 'list' => $addrlist);
 }
Exemplo n.º 19
0
 /**
  * Get all 'tie to' address/identity pairs.
  *
  * @return Horde_Mail_Rfc822_List  A list of e-mail addresses.
  */
 public function getAllTieAddresses()
 {
     $list = new Horde_Mail_Rfc822_List();
     foreach (array_keys($this->_identities) as $key) {
         $list->add($this->getTieAddresses($key));
     }
     return $list;
 }
Exemplo n.º 20
0
 /**
  * Return the CC addresses for this message.
  *
  * @return string  The Cc address string.
  * @throws Horde_ActiveSync_Exception @since 2.27.0
  */
 public function getCc()
 {
     try {
         $cc = new Horde_Mail_Rfc822_List($this->envelope->cc->addresses);
     } catch (Horde_Mail_Exception $e) {
         throw new Horde_ActiveSync_Exception($e);
     }
     return $cc->writeAddress();
 }
Exemplo n.º 21
0
Arquivo: Imap.php Projeto: horde/horde
 /**
  * Performs the filtering specified in the rules.
  *
  * @param integer $change  The timestamp of the latest rule change during
  *                         the current session.
  */
 protected function _perform($change)
 {
     $api = $this->_params['api'];
     $notification = $this->_params['notification'];
     /* Indices that will be ignored by subsequent rules. */
     $ignore_ids = array();
     /* Only do filtering if:
        1. We have not done filtering before -or-
        2. The mailbox has changed -or-
        3. The rules have changed. */
     $cache = $api->getCache();
     if ($cache !== false && $cache == $change) {
         return;
     }
     $filters = Ingo_Storage_FilterIterator_Skip::create($this->_params['storage'], $this->_params['skip']);
     /* Parse through the rules, one-by-one. */
     foreach ($filters as $rule) {
         /* Check to make sure this is a valid rule and that the rule is
            not disabled. */
         if (!$this->_validRule($rule) || $rule->disable) {
             continue;
         }
         switch ($class = get_class($rule)) {
             case 'Ingo_Rule_System_Blacklist':
             case 'Ingo_Rule_System_Whitelist':
                 $addr = $rule->addresses;
                 $bl_folder = $class === 'Ingo_Rule_System_Blacklist' ? $rule->mailbox : null;
                 /* If list is empty, move on. */
                 if (empty($addr)) {
                     continue;
                 }
                 $addr = new Horde_Mail_Rfc822_List($addr);
                 $query = $this->_getQuery();
                 $or_ob = new Horde_Imap_Client_Search_Query();
                 foreach ($addr->bare_addresses as $val) {
                     $ob = new Horde_Imap_Client_Search_Query();
                     $ob->charset('UTF-8', false);
                     $ob->headerText('from', $val);
                     $or_ob->orSearch(array($ob));
                 }
                 $query->andSearch(array($or_ob));
                 $indices = $api->search($query);
                 if (!($msgs = $api->fetchEnvelope($indices))) {
                     continue;
                 }
                 /* Remove any indices that got in there by way of partial
                  * address match. */
                 $remove = array();
                 foreach ($msgs as $v) {
                     foreach ($v->getEnvelope()->from as $v2) {
                         if (!$addr->contains($v2)) {
                             $remove[] = $v->getUid();
                             break;
                         }
                     }
                 }
                 if ($remove) {
                     $indices = array_diff($indices, $remove);
                 }
                 if ($class === 'Ingo_Rule_System_Blacklist') {
                     $indices = array_diff($indices, $ignore_ids);
                     if (!empty($indices)) {
                         if (!empty($bl_folder)) {
                             $api->moveMessages($indices, $bl_folder);
                         } else {
                             $api->deleteMessages($indices);
                         }
                         $notification->push(sprintf(_("Filter activity: %s message(s) that matched the blacklist were deleted."), count($indices)), 'horde.message');
                     }
                 } else {
                     $ignore_ids = $indices;
                 }
                 break;
             case 'Ingo_Rule_User_Discard':
             case 'Ingo_Rule_User_Keep':
             case 'Ingo_Rule_User_Move':
             case 'Ingo_Rule_User_MoveKeep':
                 $base_query = $this->_getQuery();
                 $query = new Horde_Imap_Client_Search_Query();
                 foreach ($rule->conditions as $val) {
                     $ob = new Horde_Imap_Client_Search_Query();
                     if (!empty($val['type']) && $val['type'] == Ingo_Rule_User::TEST_SIZE) {
                         $ob->size($val['value'], $val['match'] == 'greater than');
                     } elseif (!empty($val['type']) && $val['type'] == Ingo_Rule_User::TEST_BODY) {
                         $ob->charset('UTF-8', false);
                         $ob->text($val['value'], true, $val['match'] == 'not contain');
                     } else {
                         if (strpos($val['field'], ',') == false) {
                             $ob->charset('UTF-8', false);
                             $ob->headerText($val['field'], $val['value'], $val['match'] == 'not contain');
                         } else {
                             foreach (explode(',', $val['field']) as $header) {
                                 $hdr_ob = new Horde_Imap_Client_Search_Query();
                                 $hdr_ob->charset('UTF-8', false);
                                 $hdr_ob->headerText($header, $val['value'], $val['match'] == 'not contain');
                                 if ($val['match'] == 'contains') {
                                     $ob->orSearch(array($hdr_ob));
                                 } elseif ($val['match'] == 'not contain') {
                                     $ob->andSearch(array($hdr_ob));
                                 }
                             }
                         }
                     }
                     switch ($rule->combine) {
                         case Ingo_Rule_User::COMBINE_ALL:
                             $query->andSearch(array($ob));
                             break;
                         case Ingo_Rule_User::COMBINE_ANY:
                             $query->orSearch(array($ob));
                             break;
                     }
                 }
                 $base_query->andSearch(array($query));
                 $indices = $api->search($base_query);
                 if ($indices = array_diff($indices, $ignore_ids)) {
                     if ($rule->stop) {
                         /* If the stop action is set, add these
                          * indices to the list of ids that will be
                          * ignored by subsequent rules. */
                         $ignore_ids = array_unique($indices + $ignore_ids);
                     }
                     /* Set the flags. */
                     if ($class !== 'Ingo_Rule_User_Discard') {
                         $flags = array();
                         if ($rule->flags & Ingo_Rule_User::FLAG_ANSWERED) {
                             $flags[] = '\\answered';
                         }
                         if ($rule->flags & Ingo_Rule_User::FLAG_DELETED) {
                             $flags[] = '\\deleted';
                         }
                         if ($rule->flags & Ingo_Rule_User::FLAG_FLAGGED) {
                             $flags[] = '\\flagged';
                         }
                         if ($rule->flags & Ingo_Rule_User::FLAG_SEEN) {
                             $flags[] = '\\seen';
                         }
                         if (!empty($flags)) {
                             $api->setMessageFlags($indices, $flags);
                         }
                     }
                     switch ($class) {
                         case 'Ingo_Rule_User_Keep':
                             /* Add these indices to the ignore list. */
                             $ignore_ids = array_unique($indices + $ignore_ids);
                             break;
                         case 'Ingo_Rule_User_Move':
                             /* We need to grab the envelope first. */
                             if ($this->_params['show_filter_msg'] && !($fetch = $api->fetchEnvelope($indices))) {
                                 continue 2;
                             }
                             $mbox = new Horde_Imap_Client_Mailbox($rule->value);
                             /* Move the messages to the requested mailbox. */
                             $api->moveMessages($indices, strval($mbox));
                             /* Display notification message(s). */
                             if ($this->_params['show_filter_msg']) {
                                 foreach ($fetch as $msg) {
                                     $envelope = $msg->getEnvelope();
                                     $notification->push(sprintf(_("Filter activity: The message \"%s\" from \"%s\" has been moved to the folder \"%s\"."), !empty($envelope->subject) ? Horde_Mime::decode($envelope->subject) : _("[No Subject]"), !empty($envelope->from) ? strval($envelope->from) : _("[No Sender]"), $mbox), 'horde.message');
                                 }
                             } else {
                                 $notification->push(sprintf(_("Filter activity: %s message(s) have been moved to the folder \"%s\"."), count($indices), $mbox), 'horde.message');
                             }
                             break;
                         case 'Ingo_Rule_User_Discard':
                             /* We need to grab the envelope first. */
                             if ($this->_params['show_filter_msg'] && !($fetch = $api->fetchEnvelope($indices))) {
                                 continue;
                             }
                             /* Delete the messages now. */
                             $api->deleteMessages($indices);
                             /* Display notification message(s). */
                             if ($this->_params['show_filter_msg']) {
                                 foreach ($fetch as $msg) {
                                     $envelope = $msg->getEnvelope();
                                     $notification->push(sprintf(_("Filter activity: The message \"%s\" from \"%s\" has been deleted."), !empty($envelope->subject) ? Horde_Mime::decode($envelope->subject) : _("[No Subject]"), !empty($envelope->from) ? strval($envelope->from) : _("[No Sender]")), 'horde.message');
                                 }
                             } else {
                                 $notification->push(sprintf(_("Filter activity: %s message(s) have been deleted."), count($indices)), 'horde.message');
                             }
                             break;
                         case 'Ingo_Rule_User_MoveKeep':
                             $mbox = new Horde_Imap_Client_Mailbox($rule->value);
                             /* Copy the messages to the requested mailbox. */
                             $api->copyMessages($indices, strval($mbox));
                             /* Display notification message(s). */
                             if ($this->_params['show_filter_msg']) {
                                 if (!($fetch = $api->fetchEnvelope($indices))) {
                                     continue;
                                 }
                                 foreach ($fetch as $msg) {
                                     $envelope = $msg->getEnvelope();
                                     $notification->push(sprintf(_("Filter activity: The message \"%s\" from \"%s\" has been copied to the folder \"%s\"."), !empty($envelope->subject) ? Horde_Mime::decode($envelope->subject) : _("[No Subject]"), !empty($envelope->from) ? strval($envelope->from) : _("[No Sender]"), $mbox), 'horde.message');
                                 }
                             } else {
                                 $notification->push(sprintf(_("Filter activity: %s message(s) have been copied to the folder \"%s\"."), count($indices), $mbox), 'horde.message');
                             }
                     }
                 }
                 break;
         }
     }
     /* Set cache flag. */
     $api->storeCache($change);
 }
Exemplo n.º 22
0
 /**
  * Builds a string containing a list of addresses.
  *
  * @param Horde_Mail_Rfc822_List $addrlist  An address list.
  * @param Horde_Url $addURL                 The self URL.
  * @param boolean $link                     Link each address to the
  *                                          compose screen?
  *
  * @return string  String containing the formatted address list.
  */
 protected function _buildAddressLinks(Horde_Mail_Rfc822_List $addrlist, $addURL = null, $link = true)
 {
     global $prefs, $registry;
     $add_link = null;
     $addr_array = array();
     /* Set up the add address icon link if contact manager is
      * available. */
     if (!is_null($addURL) && $link && $prefs->getValue('add_source')) {
         try {
             $add_link = $registry->hasMethod('contacts/import') ? $addURL->copy()->add('actionID', 'add_address') : null;
         } catch (Horde_Exception $e) {
         }
     }
     $addrlist->setIteratorFilter();
     foreach ($addrlist->base_addresses as $ob) {
         if ($ob instanceof Horde_Mail_Rfc822_Group) {
             $group_array = array();
             foreach ($ob->addresses as $ad) {
                 $ret = htmlspecialchars(strval($ad));
                 if ($link) {
                     $clink = new IMP_Compose_Link(array('to' => strval($ad)));
                     $ret = Horde::link($clink->link(), sprintf(_("New Message to %s"), strval($ad))) . $ret . '</a>';
                 }
                 /* Append the add address icon to every address if contact
                  * manager is available. */
                 if ($add_link) {
                     $curr_link = $add_link->copy()->add(array('address' => $ad->bare_address, 'name' => $ad->personal));
                     $ret .= Horde::link($curr_link, sprintf(_("Add %s to my Address Book"), $ad->bare_address)) . '<span class="iconImg addrbookaddImg"></span></a>';
                 }
                 $group_array[] = $ret;
             }
             $addr_array[] = htmlspecialchars($ob->groupname) . ':' . (count($group_array) ? ' ' . implode(', ', $group_array) : '');
         } else {
             $ret = htmlspecialchars(strval($ob));
             if ($link) {
                 $clink = new IMP_Compose_Link(array('to' => strval($ob)));
                 $ret = Horde::link($clink->link(), sprintf(_("New Message to %s"), strval($ob))) . $ret . '</a>';
             }
             /* Append the add address icon to every address if contact
              * manager is available. */
             if ($add_link) {
                 $curr_link = $add_link->copy()->add(array('address' => $ob->bare_address, 'name' => $ob->personal));
                 $ret .= Horde::link($curr_link, sprintf(_("Add %s to my Address Book"), $ob->bare_address)) . '<span class="iconImg addrbookaddImg"></span></a>';
             }
             $addr_array[] = $ret;
         }
     }
     /* If left with an empty address list ($ret), inform the user that the
      * recipient list is purposely "undisclosed". */
     if (empty($addr_array)) {
         $ret = _("Undisclosed Recipients");
     } else {
         /* Build the address line. */
         $addr_count = count($addr_array);
         $ret = '<span class="nowrap">' . implode(',</span> <span class="nowrap">', $addr_array) . '</span>';
         if ($link && $addr_count > 15) {
             $ret = '<span>' . '<span onclick="[ this, this.next(), this.next(1) ].invoke(\'toggle\')" class="widget largeaddrlist">' . sprintf(_("Show Addresses (%d)"), $addr_count) . '</span>' . '<span onclick="[ this, this.previous(), this.next() ].invoke(\'toggle\')" class="widget largeaddrlist" style="display:none">' . _("Hide Addresses") . '</span>' . '<span style="display:none">' . $ret . '</span></span>';
         }
     }
     return $ret;
 }
Exemplo n.º 23
0
 /**
  * Internal function to handle adding addresses to [black|white]list.
  *
  * @param IMP_Indices $indices  An indices object.
  * @param string $descrip       The textual description to use.
  * @param string $reg1          The name of the mail/ registry call to use
  *                              for adding the addresses.
  * @param string $reg2          The name of the mail/ registry call to use
  *                              for linking to the filter management page.
  * @param boolean $link         Show link to the whitelist management in
  *                              the notification message?
  *
  * @return boolean  True on success.
  * @throws IMP_Exception
  */
 protected function _processBWlist($indices, $descrip, $reg1, $reg2, $link)
 {
     if (!count($indices)) {
         return false;
     }
     $addr = new Horde_Mail_Rfc822_List();
     foreach ($indices as $ob) {
         $ob->mbox->uidvalid;
         foreach ($ob->uids as $idx) {
             /* Get the list of from addresses. */
             $addr->add($GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create($ob->mbox->getIndicesOb($idx))->getHeader()->getOb('from'));
         }
     }
     $GLOBALS['registry']->call('mail/' . $reg1, array($addr->bare_addresses));
     /* Add link to filter management page. */
     if ($link && $GLOBALS['registry']->hasMethod('mail/' . $reg2)) {
         $manage_link = Horde::link(Horde::url($GLOBALS['registry']->link('mail/' . $reg2)), sprintf(_("Filters: %s management page"), $descrip)) . _("HERE") . '</a>';
         $GLOBALS['notification']->push(sprintf(_("Click %s to go to %s management page."), $manage_link, $descrip), 'horde.message', array('content.raw'));
     }
     return true;
 }
Exemplo n.º 24
0
 /**
  * Return the CC addresses for this message.
  *
  * @return string  The Cc address string.
  */
 public function getCc()
 {
     $cc = new Horde_Mail_Rfc822_List($this->_envelope->cc->addresses);
     return $cc->writeAddress();
 }