1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15:
16: class IMP_Ui_Compose
17: {
18: 19: 20: 21: 22:
23: protected $_replaced;
24:
25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37:
38: public function expandAddresses($input, $imp_compose)
39: {
40: $addr_list = $this->getAddressList($input, array('addr_list' => true));
41: if (empty($addr_list)) {
42: return '';
43: }
44:
45: $search = array_pop($addr_list);
46:
47:
48: if ((strpos($search, '<') !== false) ||
49: (strpos($search, '@') !== false)) {
50: array_push($addr_list, $search);
51: return implode(', ', $addr_list);
52: }
53:
54: $res = $imp_compose->expandAddresses($search, array('levenshtein' => true));
55:
56: if (count($res) == 1) {
57: array_push($addr_list, reset($res));
58: return implode(', ', $addr_list);
59: } elseif (!count($res)) {
60: $GLOBALS['notification']->push(sprintf(_("Search for \"%s\" failed: no address found."), $search), 'horde.warning');
61: array_push($addr_list, $search);
62: return implode(', ', $addr_list);
63: }
64:
65: $GLOBALS['notification']->push(_("Ambiguous address found."), 'horde.warning');
66:
67: return array(
68: implode(', ', $addr_list),
69: $search,
70: $res
71: );
72: }
73:
74: 75: 76: 77: 78: 79:
80: public function attachAutoCompleter($fields)
81: {
82:
83: foreach ($fields as $val) {
84: $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(array('imp', 'ContactAutoCompleter'), array('triggerId' => $val));
85: }
86: }
87:
88: 89: 90:
91: public function attachSpellChecker()
92: {
93: $menu_view = $GLOBALS['prefs']->getValue('menu_view');
94: $spell_img = '<span class="iconImg spellcheckImg"></span>';
95:
96: if (IMP::getViewMode() == 'imp') {
97: $br = '<br />';
98: $id = 'IMP';
99: } else {
100: $br = '';
101: $id = 'DIMP';
102: }
103:
104: $args = array(
105: 'id' => $id . '.SpellChecker',
106: 'targetId' => 'composeMessage',
107: 'triggerId' => 'spellcheck',
108: 'states' => array(
109: 'CheckSpelling' => $spell_img . (($menu_view == 'text' || $menu_view == 'both') ? $br . _("Check Spelling") : ''),
110: 'Checking' => $spell_img . $br . _("Checking..."),
111: 'ResumeEdit' => $spell_img . $br . _("Resume Editing"),
112: 'Error' => $spell_img . $br . _("Spell Check Failed")
113: )
114: );
115:
116: $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('SpellChecker', $args);
117: }
118:
119: 120: 121: 122: 123: 124: 125: 126: 127: 128: 129: 130:
131: public function getAddressList($addr, $opts = array())
132: {
133: $addr = rtrim(trim($addr), ',');
134: $addr_list = array();
135:
136: if (!empty($addr)) {
137:
138:
139: foreach (Horde_Mime_Address::explode($addr, ',;') as $val) {
140: $addr_list[] = IMP_Compose::formatAddr(trim($val));
141: }
142: }
143:
144: return empty($opts['addr_list'])
145: ? implode(', ', $addr_list)
146: : $addr_list;
147: }
148:
149: 150: 151: 152: 153: 154: 155: 156:
157: public function getContents($vars = null)
158: {
159: $ob = null;
160:
161: $indices = $this->getIndices($vars);
162:
163: if (!is_null($indices)) {
164: try {
165: $ob = $GLOBALS['injector']->getInstance('IMP_Factory_Contents')->create($indices);
166: } catch (Horde_Exception $e) {}
167: }
168:
169: if (is_null($ob)) {
170: if (!is_null($vars)) {
171: $vars->uid = null;
172: $vars->type = 'new';
173: }
174:
175: throw new IMP_Exception(_("Could not retrieve message data from the mail server."));
176: }
177:
178: return $ob;
179: }
180:
181: 182: 183: 184: 185: 186: 187: 188:
189: public function getIndices($vars = null)
190: {
191: if (!is_null($vars) && isset($vars->msglist)) {
192: return new IMP_Indices($vars->msglist);
193: }
194:
195: return (is_null($vars) || !isset($vars->uids))
196: ? IMP::$thismailbox->getIndicesOb(IMP::$uid)
197: : new IMP_Indices_Form($vars->uids);
198: }
199:
200: 201: 202: 203: 204: 205: 206:
207: public function mailboxReturnUrl($url = null)
208: {
209: if (!$url) {
210: $url = Horde::url('mailbox.php');
211: }
212:
213: foreach (array('start', 'page', 'mailbox', 'thismailbox') as $key) {
214: if (($param = Horde_Util::getFormData($key))) {
215: $url->add($key, $param);
216: }
217: }
218:
219: return $url;
220: }
221:
222: 223: 224:
225: public function ()
226: {
227: $menu = new Horde_Menu(Horde_Menu::MASK_NONE);
228: $menu->add(Horde::url('compose.php'), _("New Message"), 'compose.png');
229: $menu->add(new Horde_Url(''), _("Close this window"), 'close.png', null, null, 'window.close();');
230: require IMP_TEMPLATES . '/common-header.inc';
231: $success_template = $GLOBALS['injector']->createInstance('Horde_Template');
232: $success_template->set('menu', $menu->render());
233: echo $success_template->fetch(IMP_TEMPLATES . '/imp/compose/success.html');
234: IMP::status();
235: require $GLOBALS['registry']->get('templates', 'horde') . '/common-footer.inc';
236: }
237:
238: 239: 240: 241: 242: 243:
244: public function passphraseDialog($type, $cacheid = null)
245: {
246: $params = array('onload' => true);
247:
248: switch ($type) {
249: case 'pgp':
250: $type = 'pgpPersonal';
251: break;
252:
253: case 'pgp_symm':
254: $params = array('symmetricid' => 'imp_compose_' . $cacheid);
255: $type = 'pgpSymmetric';
256: break;
257:
258: case 'smime':
259: $type = 'smimePersonal';
260: break;
261: }
262:
263: $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(array('imp', 'PassphraseDialog'), array(
264: 'onload' => true,
265: 'params' => $params,
266: 'type' => $type
267: ));
268: }
269:
270: 271: 272:
273: public function identityJs()
274: {
275: $identities = array();
276: $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
277:
278: $html_sigs = $identity->getAllSignatures('html');
279:
280: foreach ($identity->getAllSignatures() as $ident => $sig) {
281: $smf = $identity->getValue('sent_mail_folder', $ident);
282:
283: $identities[] = array(
284:
285: 'sig' => $sig,
286:
287: 'sig_html' => $html_sigs[$ident],
288:
289: 'sig_loc' => (bool)$identity->getValue('sig_first', $ident),
290:
291: 'smf_name' => $smf ? $smf->form_to : '',
292:
293: 'smf_save' => (bool)$identity->saveSentmail($ident),
294:
295: 'smf_display' => $smf ? $smf->display_html : '',
296:
297: 'bcc' => Horde_Mime_Address::addrArray2String($identity->getBccAddresses($ident), array('charset' => 'UTF-8'))
298: );
299: }
300:
301: return Horde::addInlineJsVars(array(
302: 'ImpComposeBase.identities' => $identities
303: ), array('ret_vars' => true));
304: }
305:
306: 307: 308: 309: 310: 311: 312: 313: 314:
315: public function convertComposeText($data, $to, $identity)
316: {
317: $imp_identity = $GLOBALS['injector']->getInstance('IMP_Identity');
318: $this->_replaced = false;
319:
320: $html_sig = $imp_identity->getSignature('html', $identity);
321: $txt_sig = $imp_identity->getSignature('text', $identity);
322:
323: 324:
325: switch ($to) {
326: case 'html':
327: if ($txt_sig) {
328: $data = preg_replace('/' . preg_replace('/(?<!^)\s+/', '\\s+', preg_quote($txt_sig, '/')) . '/', '###IMP_SIGNATURE###', $data, 1, $this->_replaced);
329: }
330: $data = IMP_Compose::text2html($data);
331: $sig = $html_sig;
332: break;
333:
334: case 'text':
335: $callback = $html_sig
336: ? array($this, 'htmlSigCallback')
337: : null;
338:
339: $data = $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($data, 'Html2text', array(
340: 'callback' => $callback,
341: 'wrap' => false
342: ));
343:
344: $sig = $txt_sig;
345: break;
346: }
347:
348: if ($this->_replaced) {
349: return str_replace('###IMP_SIGNATURE###', $sig, $data);
350: } elseif ($imp_identity->getValue('sig_first', $identity)) {
351: return $sig . $data;
352: }
353:
354: return $data . "\n" . $sig;
355: }
356:
357: 358: 359: 360: 361: 362: 363: 364: 365:
366: public function htmlSigCallback($doc, $node)
367: {
368: if ($node instanceof DOMElement &&
369: (strtolower($node->tagName) == 'div') &&
370: ($node->getAttribute('class') == 'impComposeSignature')) {
371: $this->_replaced = true;
372: return '###IMP_SIGNATURE###';
373: }
374:
375: return null;
376: }
377:
378: }
379: