parseAddressList() 공개 정적인 메소드

Wrapper around Horde_Mail_Rfc822#parseAddressList(). Ensures all addresses have a default mail domain appended.
public static parseAddressList ( mixed $in, array $opts = [] ) : Horde_Mail_Rfc822_List
$in mixed The address string or an address list object.
$opts array Options to override the default.
리턴 Horde_Mail_Rfc822_List See Horde_Mail_Rfc822#parseAddressList().
예제 #1
0
 /**
  * Constructor.
  *
  * @param string $from           The email address of the original sender.
  * @param Horde_Mime_Headers $h  The headers object for the message.
  */
 public function __construct($from, Horde_Mime_Headers $h)
 {
     global $prefs;
     $addressList = $nameList = array();
     /* First we'll get a comma separated list of email addresses
      * and a comma separated list of personal names out of $from
      * (there just might be more than one of each). */
     $addr_list = IMP::parseAddressList($from);
     foreach ($addr_list as $addr) {
         if (!is_null($addr->mailbox)) {
             $addressList[] = $addr->bare_address;
         }
         if (!is_null($addr->personal)) {
             $nameList[] = $addr->personal;
         } elseif (!is_null($addr->mailbox)) {
             $nameList[] = $addr->mailbox;
         }
     }
     /* Define the macros. */
     if (is_array($message_id = $h->getValue('message-id'))) {
         $message_id = reset($message_id);
     }
     if (!($subject = $h->getValue('subject'))) {
         $subject = _("[No Subject]");
     }
     $udate = strtotime($h->getValue('date'));
     $match = array('/%n/' => "\n", '/%%/' => '%', '/%f/' => $from, '/%a/' => implode(', ', $addressList), '/%p/' => implode(', ', $nameList), '/%r/' => $h->getValue('date'), '/%d/' => strftime("%a, %d %b %Y", $udate), '/%x/' => strftime("%x", $udate), '/%c/' => strftime("%c", $udate), '/%m/' => $message_id, '/%s/' => $subject);
     $this->_text = preg_replace(array_keys($match), array_values($match), $prefs->getValue('attrib_text'));
 }
예제 #2
0
 /**
  * Constructor.
  *
  * @param string|Horde_Mail_Rfc822_Object $from  The email address of the
  *                                               original sender.
  * @param Horde_Mime_Headers $h                  The headers object for
  *                                               the message.
  * @param string $attrib                         Use this for the
  *                                               attribution config
  *                                               instead of the default
  *                                               prefs version.
  */
 public function __construct($from, Horde_Mime_Headers $h, $attrib = null)
 {
     global $prefs;
     $this->_text = preg_replace_callback('/\\%./', function ($matches) use($from, $h) {
         switch ($matches[0]) {
             case '%n':
                 /* New line. */
                 return "\n";
             case '%%':
                 /* Percent character. */
                 return '%';
             case '%f':
                 /* Name and email address of original sender. */
                 if ($from) {
                     $from = new Horde_Mail_Rfc822_Address($from);
                     return $from->writeAddress(array('noquote' => true));
                 }
                 return _("Unknown Sender");
             case '%a':
                 /* Senders email address(es). */
             /* Senders email address(es). */
             case '%p':
                 /* Senders name(s). */
                 $out = array();
                 foreach (IMP::parseAddressList($from) as $addr) {
                     if ($matches[0] == '%a') {
                         if (!is_null($addr->mailbox)) {
                             $out[] = $addr->bare_address;
                         }
                     } else {
                         $out[] = $addr->label;
                     }
                 }
                 return count($out) ? implode(', ', $out) : _("Unknown Sender");
             case '%r':
                 /* RFC 822 date and time. */
                 return $h['Date'];
             case '%d':
                 /* Date as ddd, dd mmm yyyy. */
                 return strftime("%a, %d %b %Y", strtotime($h['Date']));
             case '%c':
                 /* Date and time in locale's default. */
             /* Date and time in locale's default. */
             case '%x':
                 /* Date in locale's default. */
                 return strftime($matches[0], strtotime($h['Date']));
             case '%m':
                 /* Message-ID. */
                 return strval($h['Message-Id']);
             case '%s':
                 /* Message subject. */
                 return strlen($subject = $h['Subject']) ? $subject : _("[No Subject]");
             default:
                 return '';
         }
     }, is_null($attrib) ? $prefs->getValue('attrib_text') : $attrib);
 }
예제 #3
0
 /**
  * Logs an attempt to send a message.
  *
  * @param integer $action           Why the message was sent (IMP_Sentmail
  *                                  constant).
  * @param string $message_id        The Message-ID.
  * @param string|array $recipients  The list of message recipients.
  * @param boolean $success          Whether the attempt was successful.
  */
 public function log($action, $message_id, $recipients, $success = true)
 {
     if (!is_array($recipients)) {
         $recipients = array($recipients);
     }
     foreach ($recipients as $addresses) {
         foreach (IMP::parseAddressList($addresses) as $recipient) {
             $this->_log($action, $message_id, $recipient->bare_address, $success);
         }
     }
 }
예제 #4
0
 /**
  */
 public function update(Horde_Core_Prefs_Ui $ui)
 {
     global $conf, $injector, $notification;
     $imp_pgp = $injector->getInstance('IMP_Crypt_Pgp');
     if (isset($ui->vars->delete_pgp_privkey)) {
         $imp_pgp->deletePersonalKeys();
         $notification->push(_("Personal PGP keys deleted successfully."), 'horde.success');
     } elseif (isset($ui->vars->create_pgp_key) && !empty($conf['pgp']['keylength'])) {
         /* Sanity checking for email address. */
         try {
             $email = IMP::parseAddressList($ui->vars->generate_email, array('validate' => true));
         } catch (Horde_Mail_Exception $e) {
             $notification->push($e);
             return false;
         }
         /* Check that fields are filled out (except for Comment) and that
          * the passphrases match. */
         if (empty($ui->vars->generate_realname) || empty($email)) {
             $notification->push(_("Name and/or email cannot be empty"), 'horde.error');
         } elseif (empty($ui->vars->generate_passphrase1) || empty($ui->vars->generate_passphrase2)) {
             $notification->push(_("Passphrases cannot be empty"), 'horde.error');
         } elseif ($ui->vars->generate_passphrase1 !== $ui->vars->generate_passphrase2) {
             $notification->push(_("Passphrases do not match"), 'horde.error');
         } else {
             /* Expire date is delivered in UNIX timestamp in
              * milliseconds, not seconds. */
             $expire_date = $ui->vars->generate_expire ? null : $ui->vars->generate_expire_date / 1000;
             try {
                 $imp_pgp->generatePersonalKeys($ui->vars->generate_realname, $email[0]->bare_address_idn, $ui->vars->generate_passphrase1, $ui->vars->generate_comment, $conf['pgp']['keylength'], $expire_date);
                 $notification->push(_("Personal PGP keypair generated successfully."), 'horde.success');
             } catch (Exception $e) {
                 $notification->push($e);
             }
         }
     } elseif (isset($ui->vars->send_pgp_key)) {
         try {
             $imp_pgp->sendToPublicKeyserver($imp_pgp->getPersonalPublicKey());
             $notification->push(_("Key successfully sent to the public keyserver."), 'horde.success');
         } catch (Exception $e) {
             $notification->push($e);
         }
     } elseif (isset($ui->vars->unset_pgp_passphrase)) {
         $imp_pgp->unsetPassphrase('personal');
         $notification->push(_("PGP passphrase successfully unloaded."), 'horde.success');
     }
     return false;
 }
예제 #5
0
 /**
  * Expand addresses in a string. Only the last address in the string will
  * be expanded.
  *
  * @param string $input  The input string.
  *
  * @return mixed  If a string, this value should be used as the new
  *                input string.  If an array, the first value is the
  *                input string without the search string; the second
  *                value is the search string; and the third value is
  *                the list of matching addresses.
  */
 protected function _expandAddresses($input)
 {
     $addr_list = IMP::parseAddressList($input, array('default_domain' => null));
     if (!($size = count($addr_list))) {
         return '';
     }
     $search = $addr_list[$size - 1];
     /* Don't search if the search string looks like an e-mail address. */
     if (!is_null($search->mailbox) && !is_null($search->host)) {
         return strval($search);
     }
     /* "Search" string will be in mailbox element. */
     $imple = new IMP_Ajax_Imple_ContactAutoCompleter();
     $res = $imple->getAddressList($search->mailbox);
     switch (count($res)) {
         case 0:
             $GLOBALS['notification']->push(sprintf(_("Search for \"%s\" failed: no address found."), $search->mailbox), 'horde.warning');
             return strval($addr_list);
         case 1:
             $addr_list[$size] = $res[0];
             return strval($addr_list);
         default:
             $GLOBALS['notification']->push(_("Ambiguous address found."), 'horde.warning');
             unset($addr_list[$size]);
             return array(strval($addr_list), $search->mailbox, $res);
     }
 }
예제 #6
0
 /**
  * Sets a property with a specified value.
  *
  * @see setValue()
  */
 public function setValue($key, $val, $identity = null)
 {
     switch ($key) {
         case 'alias_addr':
         case 'bcc_addr':
         case 'replyto_addr':
         case 'tieto_addr':
             if (is_string($val) && strpbrk($val, "\r\n") !== false) {
                 $val = preg_split("/[\r\n]+/", $val);
             }
             /* Validate Reply-To, Alias, Tie-to, and BCC addresses. */
             $val = IMP::parseAddressList($val, array('limit' => $val == 'replyto_addr' ? 1 : 0))->addresses;
             break;
         case IMP_Mailbox::MBOX_SENT:
             $GLOBALS['injector']->getInstance('IMP_Mailbox_SessionCache')->expire(IMP_Mailbox_SessionCache::CACHE_SPECIALMBOXES);
             $val = IMP_Mailbox::prefTo($val);
             break;
     }
     return parent::setValue($key, $val, $identity);
 }
예제 #7
0
파일: Compose.php 프로젝트: DSNS-LAB/Dmail
 /**
  * URL parameters:
  *   - bcc: BCC addresses.
  *   - bcc_json: JSON encoded addresses to send to. Overwrites 'bcc'.
  *   - body: Message body text.
  *   - cc: CC addresses.
  *   - cc_json: JSON encoded addresses to send to. Overwrites 'cc'.
  *   - identity: Force message to use this identity by default.
  *   - subject: Subject to use.
  *   - type: redirect, reply, reply_auto, reply_all, reply_list,
  *           forward_attach, forward_auto, forward_body, forward_both,
  *           forward_redirect, resume, new, new_to, editasnew, template,
  *           template_edit, template_new
  *   - to: Addresses to send to.
  *   - to_json: JSON encoded addresses to send to. Overwrites 'to'.
  */
 protected function _init()
 {
     global $injector, $notification, $page_output, $prefs, $session;
     $alist = $injector->getInstance('IMP_Dynamic_AddressList');
     $clink = new IMP_Compose_Link($this->vars);
     $addr = array();
     foreach (array('to', 'cc', 'bcc') as $val) {
         $var_name = $val . '_json';
         if (isset($this->vars->{$var_name})) {
             /* Check for JSON encoded information. */
             $addr[$val] = $alist->parseAddressList($this->vars->{$var_name});
         } elseif (isset($clink->args[$val])) {
             /* Non-JSON encoded address information. */
             $addr[$val] = IMP::parseAddressList($clink->args[$val]);
         }
     }
     $subject = isset($clink->args['subject']) ? $clink->args['subject'] : null;
     $identity = $injector->getInstance('IMP_Identity');
     if (!$prefs->isLocked('default_identity') && isset($this->vars->identity)) {
         $identity->setDefault($this->vars->identity);
     }
     /* Init objects. */
     $imp_compose = $injector->getInstance('IMP_Factory_Compose')->create();
     $compose_ajax = new IMP_Ajax_Application_Compose($imp_compose, $this->vars->type);
     $ajax_queue = $injector->getInstance('IMP_Ajax_Queue');
     $ajax_queue->compose($imp_compose);
     $compose_opts = array('title' => _("New Message"));
     switch ($this->vars->type) {
         case 'reply':
         case 'reply_all':
         case 'reply_auto':
         case 'reply_list':
             try {
                 $result = $imp_compose->replyMessage($compose_ajax->reply_map[$this->vars->type], $this->_getContents(), array('to' => isset($addr['to']) ? $addr['to'] : null));
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $onload = $compose_ajax->getResponse($result);
             switch ($result['type']) {
                 case IMP_Compose::REPLY_SENDER:
                     $compose_opts['title'] = _("Reply");
                     break;
                 case IMP_Compose::REPLY_ALL:
                     $compose_opts['title'] = _("Reply to All");
                     break;
                 case IMP_Compose::REPLY_LIST:
                     $compose_opts['title'] = _("Reply to List");
                     break;
             }
             $compose_opts['title'] .= ': ' . $result['subject'];
             break;
         case 'forward_attach':
         case 'forward_auto':
         case 'forward_body':
         case 'forward_both':
             try {
                 if (count($this->indices) > 1) {
                     if (!in_array($this->vars->type, array('forward_attach', 'forward_auto'))) {
                         $notification->push(_("Multiple messages can only be forwarded as attachments."), 'horde.warning');
                     }
                     $result = $imp_compose->forwardMultipleMessages($this->indices);
                 } else {
                     $result = $imp_compose->forwardMessage($compose_ajax->forward_map[$this->vars->type], $this->_getContents());
                 }
             } catch (IMP_Exception $e) {
                 $notification->push($e, 'horde.error');
                 break;
             }
             $onload = $compose_ajax->getResponse($result);
             $compose_opts['title'] = $result['title'];
             $ajax_queue->attachment($imp_compose, IMP_Compose::FORWARD_ATTACH);
             break;
         case 'forward_redirect':
             try {
                 $imp_compose->redirectMessage($this->indices);
                 $compose_opts['title'] = _("Redirect");
             } catch (IMP_Compose_Exception $e) {
                 $notification->push($e, 'horde.error');
             }
             $onload = $compose_ajax->getBaseResponse();
             break;
         case 'editasnew':
         case 'resume':
         case 'template':
         case 'template_edit':
             try {
                 switch ($this->vars->type) {
                     case 'editasnew':
                         $result = $imp_compose->editAsNew($this->indices);
                         break;
                     case 'resume':
                         $result = $imp_compose->resumeDraft($this->indices);
                         $compose_opts['resume'] = true;
                         break;
                     case 'template':
                         $result = $imp_compose->useTemplate($this->indices);
                         break;
                     case 'template_edit':
                         $result = $imp_compose->editTemplate($this->indices);
                         $compose_opts['template'] = true;
                         break;
                 }
                 $onload = $compose_ajax->getResponse($result);
                 $ajax_queue->attachment($imp_compose, $result['type']);
                 $show_editor = $result['format'] == 'html';
             } catch (IMP_Compose_Exception $e) {
                 $notification->push($e);
             }
             break;
         case 'new_to':
             $h = $this->_getContents()->getHeader();
             $addr['to'] = $h->getOb('reply-to') ?: $h->getOb('from');
             // Fall-through
         // Fall-through
         case 'new':
         case 'template_new':
         default:
             $show_editor = $prefs->getValue('compose_html') && $session->get('imp', 'rteavail');
             $onload = $compose_ajax->getBaseResponse();
             $onload->body = isset($clink->args['body']) ? strval($clink->args['body']) : '';
             if ($show_editor) {
                 $onload->format = 'html';
             }
             if ($this->vars->type == 'template_new') {
                 $compose_opts['template'] = true;
             }
             break;
     }
     $compose_opts['redirect'] = $this->vars->type == 'forward_redirect';
     if (isset($onload->addr) || !empty($addr)) {
         foreach (array('to', 'cc', 'bcc') as $val) {
             if (!isset($onload->addr[$val])) {
                 $onload->addr[$val] = array();
             }
             if (isset($addr[$val])) {
                 $onload->addr[$val] = array_merge($onload->addr[$val], array_map('strval', $addr[$val]->base_addresses));
             }
         }
     }
     if (!is_null($subject)) {
         $onload->subject = $subject;
     }
     $this->title = $compose_opts['title'];
     $this->view->compose = $injector->getInstance('IMP_Dynamic_Compose_Common')->compose($this, $compose_opts);
     $page_output->addInlineJsVars(array('DimpCompose.onload_show' => $onload, 'DimpCompose.tasks' => $injector->getInstance('Horde_Core_Factory_Ajax')->create('imp', $this->vars)->getTasks()));
     Horde::startBuffer();
     $notification->notify(array('listeners' => array('status', 'audio')));
     $this->view->status = Horde::endBuffer();
     $this->_pages[] = 'compose-base';
 }
예제 #8
0
파일: Compose.php 프로젝트: raz0rsdge/horde
 /**
  * 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);
 }
예제 #9
0
파일: Identity.php 프로젝트: DSNS-LAB/Dmail
 /**
  * Sets a property with a specified value.
  *
  * @see setValue()
  */
 public function setValue($key, $val, $identity = null)
 {
     switch ($key) {
         case 'alias_addr':
         case 'bcc_addr':
         case 'replyto_addr':
         case 'tieto_addr':
             if (is_string($val) && strpbrk($val, "\r\n") !== false) {
                 $val = preg_split("/[\r\n]+/", $val);
             }
             /* Validate Reply-To, Alias, Tie-to, and BCC addresses. */
             $ob = IMP::parseAddressList($val, array('limit' => $val == 'replyto_addr' ? 1 : 0));
             foreach ($ob as $address) {
                 try {
                     IMP::parseAddressList($address, array('validate' => true));
                 } catch (Horde_Mail_Exception $e) {
                     throw new Horde_Prefs_Exception(sprintf(_("\"%s\" is not a valid email address.", strval($address))));
                 }
             }
             $val = $ob->addresses;
             break;
         case IMP_Mailbox::MBOX_SENT:
             $GLOBALS['injector']->getInstance('IMP_Mailbox_SessionCache')->expire(IMP_Mailbox_SessionCache::CACHE_SPECIALMBOXES);
             $val = IMP_Mailbox::prefTo($val);
             break;
     }
     return parent::setValue($key, $val, $identity);
 }