/** * 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); } } }
/** * @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; }
/** * 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; }
/** * 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; }
/** * 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; }
/** * 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.'); }
/** * 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; }
/** * Adds message recipients. * * Recipients specified by To:, Cc:, or Bcc: headers are added * automatically. * * @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 addRecipients($recipients) { $this->_recipients->add($recipients); }
/** * 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; }
/** * 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; }
/** * @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); }
/** * 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); }
/** * 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); } }
/** * 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; }