/** * Return data to build an address header. * * @param mixed $header The address header name (string) or a * Horde_Mime_Rfc822_List object. * @param integer $limit Limit display to this many addresses. If null, * shows all addresses. * * @return array An array with the following entries: * - addr: (array) List of addresses/groups. * Group keys: 'a' (list of addresses); 'g' (group name) * Address keys: 'b' (bare address); 'p' (personal part) * Both: 'v' (full value) * - limit: (integer) If limit was reached, the number of total * addresses. * - raw: (string) A raw string to display instead of addresses. */ public function getAddressHeader($header, $limit = 50) { if ($header instanceof Horde_Mail_Rfc822_List) { $addrlist = $header; } else { $addrlist = $this->_envelope->{strval($header)}; } $addrlist->unique(); $addr_ob = new IMP_Ajax_Addresses($addrlist); $addr_array = $addr_ob->toArray($limit); $out = array(); if ($addr_array->limit) { $out['limit'] = $addr_array->total; } if (!empty($addr_array->addr)) { $out['addr'] = $addr_array->addr; } elseif ($header == 'to') { $out['raw'] = _("Undisclosed Recipients"); } return $out; }
/** * AJAX Action: Do an autocomplete search. * * Variables used: * - limit: (integer) If set, limits to this many results. * - search: (string) Search string. * - type: (string) Autocomplete search type. * * @return object An object with a single property: 'results'. * The format of 'results' depends on the search type. * - type = 'email' * Results is an array with the following keys for each result: * - g: (array) List of addresses in the group (in same 'results' * format as type = 'email'). * - l: (string) Full label. * - s: (string) Short display string. * - v: (string) Value. */ public function autocompleteSearch() { $out = new stdClass(); $out->results = array(); switch ($this->vars->type) { case 'email': $addr = $GLOBALS['injector']->getInstance('IMP_Contacts')->searchEmail($this->vars->search, array('levenshtein' => true)); $ajax_addr = new IMP_Ajax_Addresses($addr); $out->results = $ajax_addr->toAutocompleteArray($this->vars->limit); break; } return $out; }
/** * 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. * - popup_link: Compose window generated via a popup link. * - 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; $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'); } // Not used in JS $onload = new stdClass(); 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(); $f = $h['reply-to'] ?: $h['from']; $addr['to'] = $f->getAddressList(true); // Fall-through // Fall-through case 'new': case 'template_new': default: $show_editor = $prefs->getValue('compose_html') && IMP_Compose::canHtmlCompose(); $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])) { $tmp = new IMP_Ajax_Addresses($addr[$val]); $onload->addr[$val] = array_merge($onload->addr[$val], $tmp->toAutocompleteArray()); } } } 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('ImpCompose.popup_link' => intval($this->vars->popup_link), 'ImpCompose.onload_show' => $onload, 'ImpCompose.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'; }
/** * Return data to build an address header. * * @param string $header The address header. * @param integer $limit Limit display to this many addresses. If null, * shows all addresses. * * @return array An array with the following entries: * - addr: (array) List of addresses/groups. * Group keys: 'a' (list of addresses); 'g' (group name) * Address keys: 'b' (bare address); 'p' (personal part) * - limit: (integer) If limit was reached, the number of total * addresses. * - raw: (string) A raw string to display instead of addresses. */ public function getAddressHeader($header, $limit = 50) { $addrlist = $header == 'reply-to' ? $this->_envelope->reply_to : $this->_envelope->{$header}; $addrlist->unique(); $addr_ob = new IMP_Ajax_Addresses($addrlist); $addr_array = $addr_ob->toArray($limit); $out = array(); if ($addr_array->limit) { $out['limit'] = $addr_array->total; } if (!empty($addr_array->addr)) { $out['addr'] = $addr_array->addr; } elseif ($header == 'to') { $out['raw'] = _("Undisclosed Recipients"); } return $out; }
/** */ public function getBaseResponse($result = array()) { $ob = new stdClass(); $ob->body = ''; $ob->opts = new stdClass(); $ob->subject = isset($result['subject']) ? $result['subject'] : ''; $ob->type = $this->_type; if (isset($result['addr'])) { $ob->addr = array(); foreach (array('to', 'cc', 'bcc') as $val) { $addr = new IMP_Ajax_Addresses($result['addr'][$val]); $ob->addr[$val] = $addr->toAutocompleteArray(); } } return $ob; }
/** * Obtains IMAP overview data for a given set of message UIDs. * * @param IMP_Mailbox $mbox The current mailbox. * @param array $msglist The list of message sequence numbers to * process. * * @return array TODO * @throws Horde_Exception */ private function _getOverviewData($mbox, $msglist) { global $injector; $msgs = array(); if (empty($msglist)) { return $msgs; } /* Get mailbox information. */ $flags = $mbox->access_flags; $imp_flags = $injector->getInstance('IMP_Flags'); $imp_ui = new IMP_Mailbox_Ui($mbox); $list_ob = $mbox->list_ob; $overview = $list_ob->getMailboxArray($msglist); /* Display message information. */ reset($overview['overview']); while (list(, $ob) = each($overview['overview'])) { /* Get all the flag information. */ $msg = array('flag' => $flags ? array_map('strval', $imp_flags->parse(array('flags' => $ob['flags'], 'headers' => $ob['headers'], 'personal' => $ob['envelope']->to, 'runhook' => $ob, 'structure' => $ob['structure']))) : array()); /* Format size information. */ $msg['size'] = IMP::sizeFormat($ob['size']); /* Format the Date: Header. */ $msg['date'] = strval(new IMP_Message_Date(isset($ob['envelope']->date) ? $ob['envelope']->date : null)); /* Format the From: Header. */ $getfrom = $imp_ui->getFrom($ob['envelope']); if (count($getfrom['from_list'])) { $from_ob = new IMP_Ajax_Addresses($getfrom['from_list']); $msg['from'] = $from_ob->toArray()->addr; if (isset($getfrom['from_label'])) { $msg['fromlabel'] = $getfrom['from_label']; } } else { $msg['from'] = array(); $msg['fromlabel'] = $getfrom['from']; } /* Format the Subject: Header. */ $msg['subject'] = $imp_ui->getSubject($ob['envelope']->subject); /* Check to see if this is a list message. Namely, we want to * check for 'List-Post' information because that is the header * that gives the e-mail address to reply to, which is all we * care about. */ if (isset($ob['headers']['List-Post'])) { $msg['listmsg'] = 1; } $msgs[$list_ob->getBuid($ob['mailbox'], $ob['uid'])] = $msg; } return $msgs; }