1: <?php
2: /**
3: * Copyright 2006-2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2006-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Common UI code for IMP's various mailbox views.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2006-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Mailbox_Ui
24: {
25: /**
26: * Cached drafts sent-mail mailbox..
27: *
28: * @var array
29: */
30: private $_draftsSent = array();
31:
32: /**
33: * The current mailbox.
34: *
35: * @var IMP_Mailbox
36: */
37: private $_mailbox;
38:
39: /**
40: * Constructor.
41: *
42: * @param IMP_Mailbox $mailbox The current mailbox.
43: */
44: public function __construct($mailbox = null)
45: {
46: $this->_mailbox = $mailbox;
47: }
48:
49: /**
50: * Get From address information for display on mailbox page.
51: *
52: * @param Horde_Imap_Client_Data_Envelope $ob An envelope object.
53: *
54: * @return array An array of information:
55: * - from: (string) The label(s) of the From address (personal part;
56: * fallback to address).
57: * - from_addr: (string) The bare address(es) of the From address.
58: * - from_list: (Horde_Mail_Rfc822_List) From address list.
59: * - to: (boolean) True if this is who the message was sent to.
60: */
61: public function getFrom($ob)
62: {
63: $ret = array(
64: 'from' => '',
65: 'from_addr' => '',
66: 'to' => false
67: );
68:
69: if (!isset($this->_draftsSent)) {
70: $this->_draftsSent = $this->_mailbox->special_outgoing;
71: }
72:
73: if ($GLOBALS['injector']->getInstance('IMP_Identity')->hasAddress($ob->from)) {
74: if (!$this->_draftsSent) {
75: $ret['from'] = _("To:") . ' ';
76: }
77: $ret['to'] = true;
78: $addrs = $ob->to;
79:
80: if (!count($addrs)) {
81: $ret['from'] .= _("Undisclosed Recipients");
82: $ret['from_list'] = new Horde_Mail_Rfc822_List();
83: return $ret;
84: }
85: } else {
86: $addrs = $ob->from;
87: if ($this->_draftsSent) {
88: $ret['from'] = _("From:") . ' ';
89: }
90:
91: if (!count($addrs)) {
92: $ret['from'] = _("Invalid Address");
93: $ret['from_list'] = new Horde_Mail_Rfc822_List();
94: return $ret;
95: }
96: }
97:
98: $bare = $parts = array();
99:
100: $addrs->unique();
101: foreach ($addrs->base_addresses as $val) {
102: $bare[] = $val->bare_address;
103: $parts[] = $val->label;
104: }
105:
106: $ret['from'] .= implode(', ', $parts);
107: $ret['from_addr'] = implode(', ', $bare);
108: $ret['from_list'] = $addrs;
109:
110: return $ret;
111: }
112:
113: /**
114: * Formats the subject header.
115: *
116: * @param string $subject The subject header.
117: * @param string $htmlspaces HTML-ize spaces?
118: *
119: * @return string The formatted subject header.
120: */
121: public function getSubject($subject, $htmlspaces = false)
122: {
123: if (!strlen($subject)) {
124: return _("[No Subject]");
125: }
126:
127: $new_subject = $subject = IMP::filterText(preg_replace("/\s+/", ' ', $subject));
128:
129: if ($htmlspaces) {
130: $new_subject = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($subject, 'space2html', array('encode' => true));
131: if (empty($new_subject)) {
132: $new_subject = htmlspecialchars($subject);
133: }
134: }
135:
136: return empty($new_subject) ? $subject : $new_subject;
137: }
138:
139: }
140: