1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14:
15: class IMP_Prefs_Ui
16: {
17: const PREF_DEFAULT = "default\0";
18: const PREF_NO_FOLDER = "nofolder\0";
19: const PREF_SPECIALUSE = "specialuse\0";
20:
21: 22: 23: 24: 25:
26: protected $_cache = null;
27:
28: 29: 30: 31: 32:
33: public function prefsInit($ui)
34: {
35: global $conf, $injector, $registry;
36:
37: $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
38:
39:
40: if (!$imp_imap->access(IMP_Imap::ACCESS_FLAGS)) {
41: $ui->suppressGroups[] = 'flags';
42: }
43: if (!$imp_imap->access(IMP_Imap::ACCESS_SEARCH)) {
44: $ui->suppressGroups[] = 'searches';
45: }
46:
47: try {
48: $injector->getInstance('IMP_Imap_Acl');
49: } catch (IMP_Exception $e) {
50: $ui->suppressGroups[] = 'acl';
51: }
52:
53: $contacts_app = $registry->hasInterface('contacts');
54: if (!$contacts_app || !$registry->hasPermission($contacts_app)) {
55: $ui->suppressGroups[] = 'addressbooks';
56: }
57:
58: if (!isset($conf['gnupg']['path'])) {
59: $ui->suppressGroups[] = 'pgp';
60: }
61:
62: if (!Horde_Util::extensionExists('openssl') ||
63: !isset($conf['openssl']['path'])) {
64: $ui->suppressGroups[] = 'smime';
65: }
66:
67: if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
68: $ui->suppressGroups[] = 'searches';
69: }
70: }
71:
72: 73: 74: 75: 76:
77: public function prefsGroup($ui)
78: {
79: global $conf, $injector, $prefs, $registry, $session;
80:
81: $cprefs = $ui->getChangeablePrefs();
82: $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
83:
84: switch ($ui->group) {
85: case 'identities':
86: if ($prefs->isLocked('sent_mail_folder')) {
87: $ui->suppress[] = 'sentmailselect';
88: }
89:
90: if ($prefs->isLocked('signature_html') ||
91: !$session->get('imp', 'rteavail')) {
92: $ui->suppress[] = 'signature_html_select';
93: }
94: break;
95:
96: case 'traditional':
97: if (!isset($cprefs['preview_enabled'])) {
98: $ui->suppress[] = 'traditional_mailbox';
99: }
100: if (!isset($cprefs['compose_popup'])) {
101: $ui->suppress[] = 'traditional_compose';
102: }
103: break;
104: }
105:
106: foreach ($cprefs as $val) {
107: switch ($val) {
108: case 'add_source':
109: try {
110: $ui->override['add_source'] = $registry->call('contacts/sources', array(true));
111: } catch (Horde_Exception $e) {
112: $ui->suppress[] = $val;
113: }
114: break;
115:
116: case 'alternative_display':
117: $mock_part = new Horde_Mime_Part();
118: $mock_part->setType('text/html');
119: $v = $injector->getInstance('IMP_Factory_MimeViewer')->create($mock_part);
120:
121: if (!$v->canRender('inline')) {
122: $ui->suppress[] = $val;
123: }
124: break;
125:
126: case 'compose_html_font_family':
127: case 'compose_html_font_size':
128: if (!$prefs->getValue('compose_html')) {
129: $ui->suppress[] = $val;
130: }
131: break;
132:
133: case 'compose_confirm':
134: if (!$prefs->getValue('compose_popup')) {
135: $ui->suppress[] = $val;
136: }
137: break;
138:
139: case 'delete_attachments_monthly_keep':
140: if (empty($conf['compose']['link_attachments'])) {
141: $ui->suppress[] = $val;
142: }
143: break;
144:
145: case 'delete_sentmail_monthly_keep':
146: case 'empty_spam_menu':
147: case 'initialpageselect':
148: case 'move_ham_after_report':
149: case 'nav_expanded':
150: case 'nav_poll_all':
151: case 'purge_sentmail_interval':
152: case 'purge_sentmail_keep':
153: case 'purge_spam_interval':
154: case 'purge_spam_keep':
155: case 'rename_sentmail_monthly':
156: case 'tree_view':
157: if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
158: $ui->suppress[] = $val;
159: }
160: break;
161:
162: case 'delete_spam_after_report':
163: if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS)) {
164: $tmp = $ui->prefs['delete_spam_after_report']['enum'];
165: unset($tmp[2]);
166: $ui->override['delete_spam_after_report'] = $tmp;
167: }
168: break;
169:
170: case 'draftsselect':
171: if ($prefs->isLocked('drafts_folder')) {
172: $ui->suppress[] = $val;
173: }
174: break;
175:
176: case 'dynamic_view':
177: if (!empty($conf['user']['force_view'])) {
178: $ui->suppress[] = $val;
179: }
180: break;
181:
182: case 'empty_trash_menu':
183: case 'purge_trash_interval':
184: case 'purge_trash_keep':
185: case 'trashselect':
186: if (!$imp_imap->access(IMP_Imap::ACCESS_TRASH) ||
187: $prefs->isLocked('use_trash') ||
188: !$prefs->getValue('use_trash')) {
189: $ui->suppress[] = $val;
190: }
191: break;
192:
193: case 'encryptselect':
194: if ($prefs->isLocked('default_encrypt')) {
195: $ui->suppress[] = $val;
196: }
197: break;
198:
199: case 'filter_any_mailbox':
200: case 'filter_on_display':
201: case 'filter_on_login':
202: if (!$session->get('imp', 'filteravail')) {
203: $ui->suppress[] = $val;
204: }
205: break;
206:
207: case 'filters_blacklist_link':
208: try {
209: $ui->prefs[$val]['url'] = $registry->link('mail/showBlacklist');
210: } catch (Horde_Exception $e) {
211: $ui->suppress[] = $val;
212: }
213: break;
214:
215: case 'filters_link':
216: try {
217: $ui->prefs[$val]['url'] = $registry->link('mail/showFilters');
218: } catch (Horde_Exception $e) {
219: $ui->suppress[] = $val;
220: }
221: break;
222:
223: case 'filters_whitelist_link':
224: try {
225: $ui->prefs[$val]['url'] = $registry->link('mail/showWhitelist');
226: } catch (Horde_Exception $e) {
227: $ui->suppress[] = $val;
228: }
229: break;
230:
231: case 'flagmanagement':
232: if ($prefs->isLocked('msgflags') &&
233: $prefs->isLocked('msgflags_user')) {
234: $ui->nobuttons = true;
235: }
236: break;
237:
238: case 'initialpageselect':
239: if ($prefs->isLocked('initial_page')) {
240: $ui->suppress[] = $val;
241: }
242: break;
243:
244: case 'newmail_soundselect':
245: if (!$prefs->getValue('newmail_notify') ||
246: $prefs->isLocked('newmail_audio')) {
247: $ui->suppress[] = $val;
248: }
249: break;
250:
251: case 'pgp_attach_pubkey':
252: case 'use_pgp_text':
253: case 'pgp_reply_pubkey':
254: case 'pgp_scan_body':
255: case 'pgp_verify':
256: case 'pgpprivatekey':
257: case 'pgppublickey':
258: if (!$prefs->getValue('use_pgp')) {
259: $ui->suppress[] = $val;
260: }
261: break;
262:
263: case 'preview_maxlen':
264: case 'preview_show_unread':
265: case 'preview_show_tooltip':
266: case 'preview_strip_nl':
267: if (!$prefs->getValue('preview_enabled')) {
268: $ui->suppress[] = $val;
269: }
270: break;
271:
272: case 'reply_lang':
273: $langs = Horde_Nls::getLanguageISO();
274: asort($langs);
275: $ui->override['reply_lang'] = $langs;
276: break;
277:
278: case 'send_mdn':
279: if (empty($conf['maillog']['use_maillog'])) {
280: $ui->suppress[] = $val;
281: }
282: break;
283:
284: case 'smime_verify':
285: case 'smimeprivatekey':
286: case 'smimepublickey':
287: case 'use_smime_text':
288: if (!$prefs->getValue('use_smime')) {
289: $ui->suppress[] = $val;
290: }
291: break;
292:
293: case 'sourceselect':
294: Horde_Core_Prefs_Ui_Widgets::addressbooksInit();
295: break;
296:
297: case 'spamselect':
298: if ($prefs->isLocked('spam_folder')) {
299: $ui->suppress[] = $val;
300: }
301: break;
302:
303: case 'stationery':
304: $ui->nobuttons = true;
305: break;
306:
307: case 'stationerymanagement':
308: if ($prefs->isLocked('stationery')) {
309: $ui->suppress[] = 'stationerymanagement';
310: }
311: break;
312:
313: case 'time_format':
314: 315:
316: $registry->setTimeZone();
317: break;
318:
319: case 'trashselect':
320: if ($prefs->isLocked('trash_folder')) {
321: $ui->suppress[] = $val;
322: }
323: break;
324:
325: case 'use_trash':
326: if (!$imp_imap->access(IMP_Imap::ACCESS_TRASH)) {
327: $ui->suppress[] = $val;
328: }
329: break;
330: }
331: }
332: }
333:
334: 335: 336: 337: 338: 339: 340: 341:
342: public function prefsSpecial($ui, $item)
343: {
344: switch ($item) {
345: case 'aclmanagement':
346: Horde::addScriptFile('acl.js', 'imp');
347: return $this->_aclManagement($ui);
348:
349: case 'draftsselect':
350: Horde::addScriptFile('folderprefs.js', 'imp');
351: Horde::addInlineJsVars(array(
352: 'ImpFolderPrefs.folders.drafts' => _("Enter the name for your new drafts folder.")
353: ));
354: return $this->_drafts();
355:
356: case 'encryptselect':
357: return $this->_encrypt();
358:
359: case 'flagmanagement':
360: if (!$ui->nobuttons) {
361: Horde::addScriptFile('colorpicker.js', 'horde');
362: Horde::addScriptFile('flagprefs.js', 'imp');
363: }
364: return $this->_flagManagement();
365:
366: case 'initialpageselect':
367: return $this->_initialPage();
368:
369: case 'mailto_handler':
370: return $this->_mailtoHandler();
371:
372: case 'newmail_soundselect':
373: return $this->_newmailAudio();
374:
375: case 'pgpprivatekey':
376: Horde::addScriptFile('imp.js', 'imp');
377: return $this->_pgpPrivateKey($ui);
378:
379: case 'pgppublickey':
380: Horde::addScriptFile('imp.js', 'imp');
381: return $this->_pgpPublicKey($ui);
382:
383: case 'searchesmanagement':
384: Horde::addScriptFile('searchesprefs.js', 'imp');
385: return $this->_searchesManagement();
386:
387: case 'sentmailselect':
388: Horde::addScriptFile('folderprefs.js', 'imp');
389: return $this->_sentmail();
390:
391: case 'smimeprivatekey':
392: Horde::addScriptFile('imp.js', 'imp');
393: return $this->_smimePrivateKey($ui);
394:
395: case 'smimepublickey':
396: Horde::addScriptFile('imp.js', 'imp');
397: return $this->_smimePublicKey($ui);
398:
399: case 'signature_html_select':
400: Horde::addScriptFile('signaturehtml.js', 'imp');
401: IMP_Ui_Editor::init(false, 'signature_html');
402: return $this->_signatureHtml();
403:
404: case 'sourceselect':
405: $search = IMP::getAddressbookSearchParams();
406: return Horde_Core_Prefs_Ui_Widgets::addressbooks(array(
407: 'fields' => $search['fields'],
408: 'sources' => $search['sources']
409: ));
410:
411: case 'spamselect':
412: Horde::addScriptFile('folderprefs.js', 'imp');
413: Horde::addInlineJsVars(array(
414: 'ImpFolderPrefs.folders.spam' => _("Enter the name for your new spam folder.")
415: ));
416: return $this->_spam();
417:
418: case 'stationerymanagement':
419: return $this->_stationeryManagement($ui);
420:
421: case 'trashselect':
422: Horde::addScriptFile('folderprefs.js', 'imp');
423: Horde::addInlineJsVars(array(
424: 'ImpFolderPrefs.folders.trash' => _("Enter the name for your new trash folder.")
425: ));
426: return $this->_trash();
427: }
428:
429: return '';
430: }
431:
432: 433: 434: 435: 436: 437: 438: 439:
440: public function prefsSpecialUpdate($ui, $item)
441: {
442: global $injector, $prefs;
443:
444: switch ($item) {
445: case 'aclmanagement':
446: $this->_updateAclManagement($ui);
447: return false;
448:
449: case 'draftsselect':
450: return $this->_updateSpecialFolders('drafts_folder', IMP_Mailbox::formFrom($ui->vars->drafts), $ui->vars->drafts_new, Horde_Imap_Client::SPECIALUSE_DRAFTS, $ui);
451:
452: case 'encryptselect':
453: return $prefs->setValue('default_encrypt', $ui->vars->default_encrypt);
454:
455: case 'flagmanagement':
456: return $this->_updateFlagManagement($ui);
457:
458: case 'initialpageselect':
459: return $prefs->setValue('initial_page', strval(IMP_Mailbox::formFrom($ui->vars->initial_page)));
460:
461: case 'newmail_soundselect':
462: return $prefs->setValue('newmail_audio', $ui->vars->newmail_audio);
463:
464: case 'pgpprivatekey':
465: $this->_updatePgpPrivateKey($ui);
466: return false;
467:
468: case 'pgppublickey':
469: $this->_updatePgpPublicKey($ui);
470: return false;
471:
472: case 'searchesmanagement':
473: $this->_updateSearchesManagement($ui);
474: return false;
475:
476: case 'sentmailselect':
477: return $this->_updateSentmail($ui);
478:
479: case 'smimeprivatekey':
480: $this->_updateSmimePrivateKey($ui);
481: return false;
482:
483: case 'smimepublickey':
484: $this->_updateSmimePublicKey($ui);
485: return false;
486:
487: case 'signature_html_select':
488: return $injector->getInstance('IMP_Identity')->setValue('signature_html', $ui->vars->signature_html);
489:
490: case 'sourceselect':
491: return $this->_updateSource($ui);
492:
493: case 'spamselect':
494: if ($this->_updateSpecialFolders('spam_folder', IMP_Mailbox::formFrom($ui->vars->spam), $ui->vars->spam_new, Horde_Imap_Client::SPECIALUSE_JUNK, $ui)) {
495: $injector->getInstance('IMP_Factory_Imap')->create()->updateFetchIgnore();
496: return true;
497: }
498:
499: return false;
500:
501: case 'stationerymanagement':
502: return $this->_updateStationeryManagement($ui);
503:
504: case 'trashselect':
505: return $this->_updateTrash($ui);
506: }
507:
508: return false;
509: }
510:
511: 512: 513: 514: 515:
516: public function prefsCallback($ui)
517: {
518: global $browser, $notification, $prefs, $registry, $session;
519:
520: if ($prefs->isDirty('use_trash')) {
521: IMP_Mailbox::getPref('trash_folder')->expire(IMP_Mailbox::CACHE_SPECIALMBOXES);
522: }
523:
524: 525:
526: if (($prefs->isDirty('use_trash') || $prefs->isDirty('trash_folder')) &&
527: $prefs->getValue('use_trash') &&
528: !$prefs->getValue('trash_folder')) {
529: $notification->push(_("You have activated move to Trash but no Trash folder is defined. You will be unable to delete messages until you set a Trash folder in the preferences."), 'horde.warning');
530: }
531:
532: if ($prefs->isDirty('mail_domain')) {
533: $maildomain = preg_replace('/[^-\.a-z0-9]/i', '', $prefs->getValue('mail_domain'));
534: $prefs->setValue('mail_domain', $maildomain);
535: if (!empty($maildomain)) {
536: $session->set('imp', 'maildomain', $maildomain);
537: }
538: }
539:
540: if ($prefs->isDirty('dynamic_view')) {
541: $session->set(
542: 'imp',
543: 'view',
544: ($prefs->getValue('dynamic_view') && $session->get('horde', 'mode') != 'traditional')
545: ? 'dimp'
546: : ($browser->isMobile() ? 'mimp' : 'imp')
547: );
548: }
549:
550: if ($prefs->isDirty('subscribe') || $prefs->isDirty('tree_view')) {
551: $registry->getApiInstance('imp', 'application')->mailboxesChanged();
552: }
553: }
554:
555:
556:
557: 558: 559: 560: 561: 562: 563:
564: protected function _aclManagement($ui)
565: {
566: $acl = $GLOBALS['injector']->getInstance('IMP_Imap_Acl');
567:
568: $folder = isset($ui->vars->folder)
569: ? IMP_Mailbox::formFrom($ui->vars->folder)
570: : IMP_Mailbox::get('INBOX');
571:
572: try {
573: $curr_acl = $acl->getACL($folder);
574: } catch (IMP_Exception $e) {
575: $GLOBALS['notification']->push($e);
576: $curr_acl = array();
577: }
578:
579: if (!($canEdit = $acl->canEdit($folder))) {
580: $GLOBALS['notification']->push(_("You do not have permission to change access to this folder."), 'horde.warning');
581: }
582:
583: $rightslist = $acl->getRights();
584:
585: $t = $GLOBALS['injector']->createInstance('Horde_Template');
586: $t->setOption('gettext', true);
587:
588: $t->set('options', IMP::flistSelect(array(
589: 'basename' => true,
590: 'selected' => $folder
591: )));
592: $t->set('current', sprintf(_("Current access to %s"), $folder->display_html));
593: $t->set('folder', $folder->form_to);
594: $t->set('hasacl', count($curr_acl));
595:
596: if ($t->get('hasacl')) {
597: $cval = array();
598:
599: foreach ($curr_acl as $index => $rule) {
600: $entry = array(
601: 'index' => htmlspecialchars($index),
602: 'rule' => array()
603: );
604:
605: if ($rule instanceof Horde_Imap_Client_Data_AclNegative) {
606: $entry['negative'] = htmlspecialchars(substr($index, 1));
607: }
608:
609: 610: 611:
612: $rightsmbox = $acl->getRightsMbox($folder, $index);
613: foreach (array_keys($rightslist) as $val) {
614: $entry['rule'][] = array(
615: 'disable' => !$canEdit || !$rightsmbox[$val],
616: 'on' => $rule[$val],
617: 'val' => $val
618: );
619: }
620: $cval[] = $entry;
621: }
622:
623: $t->set('curr_acl', $cval);
624: }
625:
626: $t->set('canedit', $canEdit);
627:
628: if ($GLOBALS['session']->get('imp', 'imap_admin')) {
629: $current_users = array_keys($curr_acl);
630: $new_user = array();
631:
632: try {
633: foreach (array('anyone') + $GLOBALS['registry']->callAppMethod('imp', 'authUserList') as $user) {
634: if (!in_array($user, $current_users)) {
635: $new_user[] = htmlspecialchars($user);
636: }
637: }
638: } catch (Horde_Exception $e) {
639: $GLOBALS['notification']->push($e);
640: return;
641: }
642: $t->set('new_user', $new_user);
643: } else {
644: $t->set('noadmin', true);
645: }
646:
647: $rights = array();
648: foreach ($rightslist as $key => $val) {
649: $val['val'] = $key;
650: $rights[] = $val;
651: }
652: $t->set('rights', $rights);
653:
654: $t->set('width', round(100 / (count($rights) + 1)) . '%');
655:
656: return $t->fetch(IMP_TEMPLATES . '/prefs/acl.html');
657: }
658:
659: 660: 661: 662: 663:
664: protected function _updateAclManagement($ui)
665: {
666: global $injector, $notification;
667:
668: if ($ui->vars->change_acl_folder) {
669: return;
670: }
671:
672: $acl = $injector->getInstance('IMP_Imap_Acl');
673: $folder = IMP_Mailbox::formFrom($ui->vars->folder);
674:
675: try {
676: $curr_acl = $acl->getACL($folder);
677: } catch (IMP_Exception $e) {
678: $notification->push($e);
679: return;
680: }
681:
682: if (!($acl_list = $ui->vars->acl)) {
683: $acl_list = array();
684: }
685: $new_user = $ui->vars->new_user;
686:
687: if (strlen($new_user) && $ui->vars->new_acl) {
688: if (isset($acl_list[$new_user])) {
689: $acl_list[$new_user] = $ui->vars->new_acl;
690: } else {
691: try {
692: $acl->addRights($folder, $new_user, implode('', $ui->vars->new_acl));
693: $notification->push(sprintf(_("ACL for \"%s\" successfully created for the mailbox \"%s\"."), $new_user, $folder->label), 'horde.success');
694: } catch (IMP_Exception $e) {
695: $notification->push($e);
696: }
697: }
698: }
699:
700: foreach ($curr_acl as $index => $rule) {
701: if (isset($acl_list[$index])) {
702: 703:
704: $acldiff = $rule->diff(implode('', $acl_list[$index]));
705: $update = false;
706:
707: try {
708: if ($acldiff['added']) {
709: $acl->addRights($folder, $index, $acldiff['added']);
710: $update = true;
711: }
712: if ($acldiff['removed']) {
713: $acl->removeRights($folder, $index, $acldiff['removed']);
714: $update = true;
715: }
716:
717: if ($update) {
718: $notification->push(sprintf(_("ACL rights for \"%s\" updated for the mailbox \"%s\"."), $index, $folder->label), 'horde.success');
719: }
720: } catch (IMP_Exception $e) {
721: $notification->push($e);
722: }
723: } else {
724: 725:
726: try {
727: $acl->removeRights($folder, $index, null);
728: $notification->push(sprintf(_("All rights on mailbox \"%s\" successfully removed for \"%s\"."), $folder->label, $index), 'horde.success');
729: } catch (IMP_Exception $e) {
730: $notification->push($e);
731: }
732: }
733: }
734: }
735:
736:
737:
738: 739: 740: 741: 742:
743: protected function _drafts()
744: {
745: $t = $GLOBALS['injector']->createInstance('Horde_Template');
746: $t->setOption('gettext', true);
747:
748: $t->set('label', Horde::label('drafts', _("Drafts folder:")));
749: $t->set('nofolder', IMP_Mailbox::formTo(self::PREF_NO_FOLDER));
750: $t->set('flist', IMP::flistSelect(array(
751: 'basename' => true,
752: 'filter' => array('INBOX'),
753: 'new_folder' => true,
754: 'selected' => IMP_Mailbox::getPref('drafts_folder')
755: )));
756: $t->set('special_use', $this->_getSpecialUse(Horde_Imap_Client::SPECIALUSE_DRAFTS));
757:
758: return $t->fetch(IMP_TEMPLATES . '/prefs/drafts.html');
759: }
760:
761:
762:
763: 764: 765: 766: 767:
768: protected function _encrypt()
769: {
770: $t = $GLOBALS['injector']->createInstance('Horde_Template');
771:
772: $t->set('label', Horde::label('default_encrypt', _("Your default encryption method for sending messages:")));
773: $t->set('elist', IMP::encryptList());
774:
775: return $t->fetch(IMP_TEMPLATES . '/prefs/encrypt.html');
776: }
777:
778:
779:
780: 781: 782: 783: 784:
785: protected function _flagManagement()
786: {
787: Horde::addInlineJsVars(array(
788: 'ImpFlagPrefs.new_prompt' => _("Please enter the label for the new flag:"),
789: 'ImpFlagPrefs.confirm_delete' => _("Are you sure you want to delete this flag?")
790: ));
791:
792: $t = $GLOBALS['injector']->createInstance('Horde_Template');
793: $t->setOption('gettext', true);
794: $t->set('locked', $GLOBALS['prefs']->isLocked('msgflags'));
795:
796: $out = array();
797: $flaglist = $GLOBALS['injector']->getInstance('IMP_Flags')->getList();
798: foreach ($flaglist as $val) {
799: $hash = hash('md5', $val->id);
800: $bgid = 'bg_' . $hash;
801: $color = htmlspecialchars($val->bgcolor);
802: $label = htmlspecialchars($val->label);
803: $bgstyle = 'background-color:' . $color;
804: $tmp = array();
805:
806: if ($val instanceof IMP_Flag_User) {
807: $tmp['label'] = $label;
808: $tmp['user'] = true;
809: $tmp['label_name'] = 'label_' . $hash;
810: } else {
811: $tmp['label'] = Horde::label($bgid, $label);
812: $tmp['icon'] = $val->span;
813: }
814:
815: $tmp['colorstyle'] = $bgstyle . ';color:' . htmlspecialchars($val->fgcolor);
816: $tmp['colorid'] = $bgid;
817: $tmp['color'] = $color;
818:
819: $out[] = $tmp;
820: }
821: $t->set('flags', $out);
822:
823: $t->set('picker_img', Horde::img('colorpicker.png', _("Color Picker")));
824:
825: return $t->fetch(IMP_TEMPLATES . '/prefs/flags.html');
826: }
827:
828: 829: 830: 831: 832: 833: 834:
835: protected function _updateFlagManagement($ui)
836: {
837: $imp_flags = $GLOBALS['injector']->getInstance('IMP_Flags');
838:
839: if ($ui->vars->flag_action == 'add') {
840: $GLOBALS['notification']->push(sprintf(_("Added flag \"%s\"."), $ui->vars->flag_data), 'horde.success');
841: $imp_flags->addFlag($ui->vars->flag_data);
842: return;
843: }
844:
845:
846:
847: $update = false;
848: foreach ($imp_flags->getList() as $val) {
849: $md5 = hash('md5', $val->id);
850:
851: switch ($ui->vars->flag_action) {
852: case 'delete':
853: if ($ui->vars->flag_data == ('bg_' . $md5)) {
854: unset($imp_flags[$val->id]);
855: $GLOBALS['notification']->push(sprintf(_("Deleted flag \"%s\"."), $val->label), 'horde.success');
856: }
857: break;
858:
859: default:
860:
861: if ($val instanceof IMP_Flag_User) {
862: $label = $ui->vars->get('label_' . $md5);
863: if (strlen($label) && ($label != $val->label)) {
864: $imp_flags->updateFlag($val->id, 'label', $label);
865: $update = true;
866: }
867: }
868:
869:
870: $bg = strtolower($ui->vars->get('bg_' . $md5));
871: if ($bg != $val->bgcolor) {
872: $imp_flags->updateFlag($val->id, 'bgcolor', $bg);
873: $update = true;
874: }
875: break;
876: }
877: }
878:
879: return $update;
880: }
881:
882:
883:
884: 885: 886: 887: 888:
889: protected function _initialPage()
890: {
891: global $injector, $prefs;
892:
893: $t = $injector->createInstance('Horde_Template');
894: $t->setOption('gettext', true);
895:
896: if (!$injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_FOLDERS)) {
897: $t->set('nofolder', true);
898: } else {
899: if (!($initial_page = $prefs->getValue('initial_page'))) {
900: $initial_page = 'INBOX';
901: }
902: $t->set('folder_page', IMP_Mailbox::formTo(IMP::INITIAL_FOLDERS));
903: $t->set('folder_sel', $initial_page == IMP::INITIAL_FOLDERS);
904: $t->set('flist', IMP::flistSelect(array(
905: 'basename' => true,
906: 'inc_vfolder' => true,
907: 'selected' => $initial_page
908: )));
909: }
910:
911: $t->set('label', Horde::label('initial_page', _("View or mailbox to display after login:")));
912:
913: return $t->fetch(IMP_TEMPLATES . '/prefs/initialpage.html');
914: }
915:
916:
917:
918: 919: 920: 921: 922:
923: protected function _mailtoHandler()
924: {
925: Horde::addInlineScript(array(
926: 'if (!Object.isUndefined(navigator.registerProtocolHandler))' .
927: '$("mailto_handler").show().down("A").observe("click", function() {' .
928: 'navigator.registerProtocolHandler("mailto","' .
929: Horde::url('compose.php', true)->setRaw(true)->add(array(
930: 'actionID' => 'mailto_link',
931: 'to' => ''
932: )) .
933: '=%s","' . $GLOBALS['registry']->get('name') . '");' .
934: '})'
935: ), 'dom');
936:
937: $t = $GLOBALS['injector']->createInstance('Horde_Template');
938: $t->setOption('gettext', true);
939:
940: $t->set('desc', sprintf(_("Click here to open all mailto: links using %s."), $GLOBALS['registry']->get('name')));
941: $t->set('img', Horde::img('compose.png'));
942:
943: return $t->fetch(IMP_TEMPLATES . '/prefs/mailto.html');
944: }
945:
946:
947:
948: 949: 950: 951: 952:
953: protected function _newmailAudio()
954: {
955: $t = $GLOBALS['injector']->createInstance('Horde_Template');
956: $t->setOption('gettext', true);
957:
958: $newmail_audio = $GLOBALS['prefs']->getValue('newmail_audio');
959:
960: $t->set('newmail_audio', $newmail_audio);
961:
962: $sounds = array();
963: foreach (Horde_Themes::soundList() as $key => $val) {
964: $sounds[] = array(
965: 'c' => ($newmail_audio == $key),
966: 'l' => htmlspecialchars($key),
967: 's' => htmlspecialchars($val->uri),
968: 'v' => htmlspecialchars($key)
969: );
970: }
971: $t->set('sounds', $sounds);
972:
973: return $t->fetch(IMP_TEMPLATES . '/prefs/newmailaudio.html');
974: }
975:
976:
977:
978: 979: 980: 981: 982: 983: 984:
985: protected function _pgpPrivateKey($ui)
986: {
987: $t = $GLOBALS['injector']->createInstance('Horde_Template');
988: $t->setOption('gettext', true);
989:
990: $t->set('personalkey-help', Horde_Help::link('imp', 'pgp-overview-personalkey'));
991:
992: if (!Horde::isConnectionSecure()) {
993: $t->set('notsecure', true);
994: } else {
995: $pgp_url = Horde::url('pgp.php');
996:
997: $t->set('has_key', $GLOBALS['prefs']->getValue('pgp_public_key') && $GLOBALS['prefs']->getValue('pgp_private_key'));
998: if ($t->get('has_key')) {
999: $t->set('viewpublic', Horde::link($pgp_url->copy()->add('actionID', 'view_personal_public_key'), _("View Personal Public Key"), null, 'view_key'));
1000: $t->set('infopublic', Horde::link($pgp_url->copy()->add('actionID', 'info_personal_public_key'), _("Information on Personal Public Key"), null, 'info_key'));
1001: $t->set('sendkey', Horde::link($ui->selfUrl(array('special' => true, 'token' => true))->add('send_pgp_key', 1), _("Send Key to Public Keyserver")));
1002: $t->set('personalkey-public-help', Horde_Help::link('imp', 'pgp-personalkey-public'));
1003:
1004: if ($passphrase = $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp')->getPassphrase('personal')) {
1005: $t->set('passphrase', Horde::link($ui->selfUrl(array('special' => true, 'token' => true))->add('unset_pgp_passphrase', 1), _("Unload Passphrase")) . _("Unload Passphrase"));
1006: } else {
1007: $imple = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(array('imp', 'PassphraseDialog'), array(
1008: 'reloadurl' => $ui->selfUrl()->setRaw(true),
1009: 'type' => 'pgpPersonal'
1010: ));
1011: $t->set('passphrase', Horde::link('#', _("Enter Passphrase"), null, null, null, null, null, array('id' => $imple->getPassphraseId())) . _("Enter Passphrase"));
1012: }
1013:
1014: $t->set('viewprivate', Horde::link($pgp_url->copy()->add('actionID', 'view_personal_private_key'), _("View Personal Private Key"), null, 'view_key'));
1015: $t->set('infoprivate', Horde::link($pgp_url->copy()->add('actionID', 'info_personal_private_key'), _("Information on Personal Private Key"), null, 'info_key'));
1016: $t->set('personalkey-private-help', Horde_Help::link('imp', 'pgp-personalkey-private'));
1017: $t->set('personalkey-delete-help', Horde_Help::link('imp', 'pgp-personalkey-delete'));
1018:
1019: Horde::addInlineScript(array(
1020: '$("delete_pgp_privkey").observe("click", function(e) { if (!window.confirm(' . Horde_Serialize::serialize(_("Are you sure you want to delete your keypair? (This is NOT recommended!)"), Horde_Serialize::JSON, 'UTF-8') . ')) { e.stop(); } })'
1021: ), 'dom');
1022: } else {
1023: $imp_identity = $GLOBALS['injector']->getInstance('IMP_Identity');
1024: $t->set('fullname', $imp_identity->getFullname());
1025: $t->set('personalkey-create-name-help', Horde_Help::link('imp', 'pgp-personalkey-create-name'));
1026: $t->set('personalkey-create-comment-help', Horde_Help::link('imp', 'pgp-personalkey-create-comment'));
1027: $t->set('fromaddr', $imp_identity->getFromAddress());
1028: $t->set('personalkey-create-email-help', Horde_Help::link('imp', 'pgp-personalkey-create-email'));
1029: $t->set('personalkey-create-keylength-help', Horde_Help::link('imp', 'pgp-personalkey-create-keylength'));
1030: $t->set('personalkey-create-passphrase-help', Horde_Help::link('imp', 'pgp-personalkey-create-passphrase'));
1031:
1032: Horde::addInlineScript(array(
1033: '$("create_pgp_key").observe("click", function(e) { if (!window.confirm(' . Horde_Serialize::serialize(_("Key generation may take a long time to complete. Continue with key generation?"), Horde_Serialize::JSON, 'UTF-8') . ')) { e.stop(); } })'
1034: ), 'dom');
1035:
1036: if ($GLOBALS['session']->get('imp', 'file_upload')) {
1037: $t->set('import_pgp_private', true);
1038: Horde::addInlineScript(array(
1039: '$("import_pgp_personal").observe("click", function(e) { ' . Horde::popupJs($pgp_url, array('params' => array('actionID' => 'import_personal_public_key', 'reload' => $GLOBALS['session']->store($ui->selfUrl()->setRaw(true), false)), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
1040: ), 'dom');
1041: }
1042:
1043: $t->set('personalkey-create-actions-help', Horde_Help::link('imp', 'pgp-personalkey-create-actions'));
1044: }
1045: }
1046:
1047: return $t->fetch(IMP_TEMPLATES . '/prefs/pgpprivatekey.html');
1048: }
1049:
1050: 1051: 1052: 1053: 1054:
1055: protected function _updatePgpPrivateKey($ui)
1056: {
1057: if (isset($ui->vars->delete_pgp_privkey)) {
1058: $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp')->deletePersonalKeys();
1059: $GLOBALS['notification']->push(_("Personal PGP keys deleted successfully."), 'horde.success');
1060: } elseif (isset($ui->vars->create_pgp_key)) {
1061: 1062:
1063: if (empty($ui->vars->generate_realname) ||
1064: empty($ui->vars->generate_email)) {
1065: $GLOBALS['notification']->push(_("Name and/or email cannot be empty"), 'horde.error');
1066: } elseif (empty($ui->vars->generate_passphrase1) ||
1067: empty($ui->vars->generate_passphrase2)) {
1068: $GLOBALS['notification']->push(_("Passphrases cannot be empty"), 'horde.error');
1069: } elseif ($ui->vars->generate_passphrase1 !== $ui->vars->generate_passphrase2) {
1070: $GLOBALS['notification']->push(_("Passphrases do not match"), 'horde.error');
1071: } else {
1072: try {
1073: $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp')->generatePersonalKeys($ui->vars->generate_realname, $ui->vars->generate_email, $ui->vars->generate_passphrase1, $ui->vars->_generate_comment, $ui->vars->generate_keylength);
1074: $GLOBALS['notification']->push(_("Personal PGP keypair generated successfully."), 'horde.success');
1075: } catch (Exception $e) {
1076: $GLOBALS['notification']->push($e);
1077: }
1078: }
1079: } elseif (isset($ui->vars->send_pgp_key)) {
1080: try {
1081: $imp_pgp = $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp');
1082: $imp_pgp->sendToPublicKeyserver($imp_pgp->getPersonalPublicKey());
1083: $GLOBALS['notification']->push(_("Key successfully sent to the public keyserver."), 'horde.success');
1084: } catch (Exception $e) {
1085: $GLOBALS['notification']->push($e);
1086: }
1087: } elseif (isset($ui->vars->unset_pgp_passphrase)) {
1088: $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp')->unsetPassphrase('personal');
1089: $GLOBALS['notification']->push(_("PGP passphrase successfully unloaded."), 'horde.success');
1090: }
1091: }
1092:
1093:
1094:
1095: 1096: 1097: 1098: 1099: 1100: 1101:
1102: protected function _pgpPublicKey($ui)
1103: {
1104: $imp_pgp = $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp');
1105:
1106:
1107: try {
1108: $pubkey_list = $imp_pgp->listPublicKeys();
1109: } catch (Horde_Exception $e) {
1110: $pubkey_list = array();
1111: }
1112:
1113: $pgp_url = Horde::url('pgp.php');
1114:
1115: $t = $GLOBALS['injector']->createInstance('Horde_Template');
1116: $t->setOption('gettext', true);
1117:
1118: $t->set('manage_pubkey-help', Horde_Help::link('imp', 'pgp-manage-pubkey'));
1119:
1120: if (!empty($pubkey_list)) {
1121: $plist = array();
1122: $self_url = $ui->selfUrl(array('special' => true, 'token' => true));
1123:
1124: foreach ($pubkey_list as $val) {
1125: $plist[] = array(
1126: 'name' => $val['name'],
1127: 'email' => $val['email'],
1128: 'view' => Horde::link($pgp_url->copy()->add(array('actionID' => 'view_public_key', 'email' => $val['email'])), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
1129: 'info' => Horde::link($pgp_url->copy()->add(array('actionID' => 'info_public_key', 'email' => $val['email'])), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
1130: 'delete' => Horde::link($self_url->copy()->add(array('delete_pgp_pubkey' => 1, 'email' => $val['email'])), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "window.confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')")
1131: );
1132: }
1133: $t->set('pubkey_list', $plist);
1134: }
1135:
1136: if ($GLOBALS['session']->get('imp', 'file_upload')) {
1137: $t->set('can_import', true);
1138: $t->set('no_source', !$GLOBALS['prefs']->getValue('add_source'));
1139: if (!$t->get('no_source')) {
1140: $t->set('import_pubkey-help', Horde_Help::link('imp', 'pgp-import-pubkey'));
1141:
1142: Horde::addInlineScript(array(
1143: '$("import_pgp_public").observe("click", function(e) { ' . Horde::popupJs($pgp_url, array('params' => array('actionID' => 'import_public_key', 'reload' => $GLOBALS['session']->store($ui->selfUrl()->setRaw(true), false)), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
1144: ), 'dom');
1145: }
1146: }
1147:
1148: return $t->fetch(IMP_TEMPLATES . '/prefs/pgppublickey.html');
1149: }
1150:
1151: 1152: 1153: 1154: 1155:
1156: protected function _updatePgpPublicKey($ui)
1157: {
1158: if (isset($ui->vars->delete_pgp_pubkey)) {
1159: try {
1160: $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp')->deletePublicKey($ui->vars->email);
1161: $GLOBALS['notification']->push(sprintf(_("PGP Public Key for \"%s\" was successfully deleted."), $ui->vars->email), 'horde.success');
1162: } catch (Horde_Exception $e) {
1163: $GLOBALS['notification']->push($e);
1164: }
1165: }
1166: }
1167:
1168:
1169:
1170: 1171: 1172: 1173: 1174:
1175: protected function _searchesManagement()
1176: {
1177: global $injector, $prefs;
1178:
1179: $t = $injector->createInstance('Horde_Template');
1180: $t->setOption('gettext', true);
1181:
1182: $imp_search = $injector->getInstance('IMP_Search');
1183: $fout = $mailboxids = $vout = array();
1184: $view_mode = IMP::getViewMode();
1185:
1186: $imp_search->setIteratorFilter(IMP_Search::LIST_VFOLDER | IMP_Search::LIST_DISABLED);
1187: $vfolder_locked = $prefs->isLocked('vfolder');
1188:
1189: foreach ($imp_search as $key => $val) {
1190: if (!$val->prefDisplay) {
1191: continue;
1192: }
1193:
1194: $editable = !$vfolder_locked && $imp_search->isVFolder($val, true);
1195: $m_url = ($val->enabled && ($view_mode == 'imp'))
1196: ? $val->mbox_ob->url('mailbox.php')->link(array('class' => 'vfolderenabled'))
1197: : null;
1198:
1199: if ($view_mode == 'dimp') {
1200: $mailboxids['enable_' . $key] = $val->formid;
1201: }
1202:
1203: $vout[] = array(
1204: 'description' => Horde_String::truncate($val->querytext, 200),
1205: 'edit' => ($editable ? $imp_search->editUrl($val) : null),
1206: 'enabled' => $val->enabled,
1207: 'enabled_locked' => $vfolder_locked,
1208: 'key' => $key,
1209: 'label' => htmlspecialchars($val->label),
1210: 'm_url' => $m_url
1211: );
1212: }
1213: $t->set('vfolders', $vout);
1214:
1215: $imp_search->setIteratorFilter(IMP_Search::LIST_FILTER | IMP_Search::LIST_DISABLED);
1216: $filter_locked = $prefs->isLocked('filter');
1217:
1218: foreach ($imp_search as $key => $val) {
1219: if (!$val->prefDisplay) {
1220: continue;
1221: }
1222:
1223: $editable = !$filter_locked && $imp_search->isFilter($val, true);
1224:
1225: if ($editable && ($view_mode == 'dimp')) {
1226: $mailboxids['enable_' . $key] = $val->formid;
1227: }
1228:
1229: $fout[] = array(
1230: 'description' => Horde_String::truncate($val->querytext, 200),
1231: 'edit' => ($editable ? $imp_search->editUrl($val) : null),
1232: 'enabled' => $val->enabled,
1233: 'enabled_locked' => $filter_locked,
1234: 'key' => $key,
1235: 'label' => htmlspecialchars($val->label)
1236: );
1237: }
1238: $t->set('filters', $fout);
1239:
1240: if (empty($fout) && empty($vout)) {
1241: $t->set('nosearches', true);
1242: } else {
1243: Horde::addInlineJsVars(array(
1244: 'ImpSearchesPrefs.confirm_delete_filter' => _("Are you sure you want to delete this filter?"),
1245: 'ImpSearchesPrefs.confirm_delete_vfolder' => _("Are you sure you want to delete this virtual folder?"),
1246: 'ImpSearchesPrefs.mailboxids' => $mailboxids
1247: ));
1248: }
1249:
1250: return $t->fetch(IMP_TEMPLATES . '/prefs/searches.html');
1251: }
1252:
1253: 1254: 1255: 1256: 1257:
1258: protected function _updateSearchesManagement($ui)
1259: {
1260: $imp_search = $GLOBALS['injector']->getInstance('IMP_Search');
1261:
1262: switch ($ui->vars->searches_action) {
1263: case 'delete':
1264:
1265: $key = substr($ui->vars->searches_data, 7);
1266: if ($ob = $imp_search[$key]) {
1267: if ($imp_search->isVFolder($ob)) {
1268: $GLOBALS['notification']->push(sprintf(_("Virtual Folder \"%s\" deleted."), $ob->label), 'horde.success');
1269: } elseif ($imp_search->isFilter($ob)) {
1270: $GLOBALS['notification']->push(sprintf(_("Filter \"%s\" deleted."), $ob->label), 'horde.success');
1271: }
1272: unset($imp_search[$key]);
1273: }
1274: break;
1275:
1276: default:
1277:
1278: $imp_search->setIteratorFilter(IMP_Search::LIST_VFOLDER | IMP_Search::LIST_DISABLED);
1279: $vfolders = array();
1280:
1281: foreach ($imp_search as $key => $val) {
1282: $form_key = 'enable_' . $key;
1283:
1284: 1285:
1286: if ($val->prefDisplay) {
1287: $val->enabled = !empty($ui->vars->$form_key);
1288: $vfolders[$key] = $val;
1289: }
1290: }
1291: $imp_search->setVFolders($vfolders);
1292:
1293:
1294: $imp_search->setIteratorFilter(IMP_Search::LIST_FILTER | IMP_Search::LIST_DISABLED);
1295: $filters = array();
1296:
1297: foreach ($imp_search as $key => $val) {
1298: $form_key = 'enable_' . $key;
1299: $val->enabled = !empty($ui->vars->$form_key);
1300: $filters[$key] = $val;
1301: }
1302: $imp_search->setFilters($filters);
1303: break;
1304: }
1305: }
1306:
1307:
1308:
1309: 1310: 1311: 1312: 1313:
1314: protected function _sentmail()
1315: {
1316: $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
1317:
1318: $js = array();
1319: foreach (array_keys($identity->getAll('id')) as $key) {
1320: $js[$key] = $identity->getValue('sent_mail_folder', $key)->form_to;
1321: };
1322:
1323: Horde::addInlineJsVars(array(
1324: 'ImpFolderPrefs.folders' => array('sent_mail_folder' => _("Create a new sent-mail folder")),
1325: 'ImpFolderPrefs.sentmail' => $js
1326: ));
1327:
1328: $t = $GLOBALS['injector']->createInstance('Horde_Template');
1329: $t->setOption('gettext', true);
1330:
1331: $t->set('default', IMP_Mailbox::formTo(self::PREF_DEFAULT));
1332: $t->set('label', Horde::label('sent_mail_folder', _("Sent mail folder:")));
1333: $t->set('flist', IMP::flistSelect(array(
1334: 'basename' => true,
1335: 'filter' => array('INBOX'),
1336: 'new_folder' => true
1337: )));
1338: $t->set('special_use', $this->_getSpecialUse(Horde_Imap_Client::SPECIALUSE_SENT));
1339:
1340: return $t->fetch(IMP_TEMPLATES . '/prefs/sentmail.html');
1341: }
1342:
1343: 1344: 1345: 1346: 1347: 1348: 1349:
1350: protected function _updateSentmail($ui)
1351: {
1352: global $injector, $prefs;
1353:
1354: $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
1355:
1356: if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS) ||
1357: $prefs->isLocked('sent_mail_folder')) {
1358: return false;
1359: }
1360:
1361: if (!$ui->vars->sent_mail_folder && $ui->vars->sent_mail_folder_new) {
1362: $sent_mail_folder = IMP_Mailbox::get(Horde_String::convertCharset($ui->vars->sent_mail_folder_new, 'UTF-8', 'UTF7-IMAP'))->namespace_append;
1363: } else {
1364: $sent_mail_folder = IMP_Mailbox::formFrom($ui->vars->sent_mail_folder);
1365: if (strpos($sent_mail_folder, self::PREF_SPECIALUSE) === 0) {
1366: $sent_mail_folder = IMP_Mailbox::get(substr($folder, strlen(self::PREF_SPECIALUSE)));
1367: } elseif (($sent_mail_folder == self::PREF_DEFAULT) &&
1368: ($sm_default = $prefs->getDefault('sent_mail_folder'))) {
1369: $sent_mail_folder = IMP_Mailbox::get($sm_default)->namespace_append;
1370: }
1371: }
1372:
1373: if ($sent_mail_folder && !$sent_mail_folder->create()) {
1374: return false;
1375: }
1376:
1377: return $injector->getInstance('IMP_Identity')->setValue('sent_mail_folder', $sent_mail_folder);
1378: }
1379:
1380:
1381:
1382: 1383: 1384: 1385: 1386: 1387: 1388:
1389: protected function _smimePrivateKey($ui)
1390: {
1391: $t = $GLOBALS['injector']->createInstance('Horde_Template');
1392: $t->setOption('gettext', true);
1393:
1394: $t->set('personalkey-help', Horde_Help::link('imp', 'smime-overview-personalkey'));
1395:
1396: if (!Horde::isConnectionSecure()) {
1397: $t->set('notsecure', true);
1398: } else {
1399: $smime_url = Horde::url('smime.php');
1400:
1401: $t->set('has_key', $GLOBALS['prefs']->getValue('smime_public_key') && $GLOBALS['prefs']->getValue('smime_private_key'));
1402: if ($t->get('has_key')) {
1403: $t->set('viewpublic', Horde::link($smime_url->copy()->add('actionID', 'view_personal_public_key'), _("View Personal Public Certificate"), null, 'view_key'));
1404: $t->set('infopublic', Horde::link($smime_url->copy()->add('actionID', 'info_personal_public_key'), _("Information on Personal Public Certificate"), null, 'info_key'));
1405:
1406: if ($passphrase = $GLOBALS['injector']->getInstance('IMP_Crypt_Smime')->getPassphrase()) {
1407: $t->set('passphrase', Horde::link($ui->selfUrl(array('special' => true, 'token' => true))->add('unset_smime_passphrase', 1), _("Unload Passphrase")) . _("Unload Passphrase"));
1408: } else {
1409: $imple = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create(array('imp', 'PassphraseDialog'), array(
1410: 'reloadurl' => $ui->selfUrl()->setRaw(true),
1411: 'type' => 'smimePersonal'
1412: ));
1413: $t->set('passphrase', Horde::link('#', _("Enter Passphrase"), null, null, null, null, null, array('id' => $imple->getPassphraseId())) . _("Enter Passphrase"));
1414: }
1415:
1416: $t->set('viewprivate', Horde::link($smime_url->copy()->add('actionID', 'view_personal_private_key'), _("View Personal Private Key"), null, 'view_key'));
1417: $t->set('personalkey-delete-help', Horde_Help::link('imp', 'smime-delete-personal-certs'));
1418:
1419: Horde::addInlineScript(array(
1420: '$("delete_smime_personal").observe("click", function(e) { if (!window.confirm(' . Horde_Serialize::serialize(_("Are you sure you want to delete your keypair? (This is NOT recommended!)"), Horde_Serialize::JSON, 'UTF-8') . ')) { e.stop(); } })'
1421: ), 'dom');
1422: } elseif ($GLOBALS['session']->get('imp', 'file_upload')) {
1423: $t->set('import-cert-help', Horde_Help::link('imp', 'smime-import-personal-certs'));
1424:
1425: Horde::addInlineScript(array(
1426: '$("import_smime_personal").observe("click", function(e) { ' . Horde::popupJs($smime_url, array('params' => array('actionID' => 'import_personal_certs', 'reload' => $GLOBALS['session']->store($ui->selfUrl()->setRaw(true), false)), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
1427: ), 'dom');
1428: }
1429: }
1430:
1431: return $t->fetch(IMP_TEMPLATES . '/prefs/smimeprivatekey.html');
1432: }
1433:
1434: 1435: 1436: 1437: 1438:
1439: protected function _updateSmimePrivateKey($ui)
1440: {
1441: if (isset($ui->vars->delete_smime_personal)) {
1442: $GLOBALS['injector']->getInstance('IMP_Crypt_Smime')->deletePersonalKeys();
1443: $GLOBALS['notification']->push(_("Personal S/MIME keys deleted successfully."), 'horde.success');
1444: } elseif (isset($ui->vars->unset_smime_passphrase)) {
1445: $GLOBALS['injector']->getInstance('IMP_Crypt_Smime')->unsetPassphrase();
1446: $GLOBALS['notification']->push(_("S/MIME passphrase successfully unloaded."), 'horde.success');
1447: }
1448: }
1449:
1450:
1451:
1452: 1453: 1454: 1455: 1456: 1457: 1458:
1459: protected function _smimePublicKey($ui)
1460: {
1461: $imp_smime = $GLOBALS['injector']->getInstance('IMP_Crypt_Smime');
1462:
1463:
1464: try {
1465: $pubkey_list = $imp_smime->listPublicKeys();
1466: } catch (Horde_Exception $e) {
1467: $pubkey_list = array();
1468: }
1469:
1470: $smime_url = Horde::url('smime.php');
1471:
1472: $t = $GLOBALS['injector']->createInstance('Horde_Template');
1473: $t->setOption('gettext', true);
1474:
1475: $t->set('manage_pubkey-help', Horde_Help::link('imp', 'smime-manage-pubkey'));
1476:
1477: if (!empty($pubkey_list)) {
1478: $plist = array();
1479: $self_url = $ui->selfUrl(array('special' => true, 'token' => true));
1480:
1481: foreach ($pubkey_list as $val) {
1482: $plist[] = array(
1483: 'name' => $val['name'],
1484: 'email' => $val['email'],
1485: 'view' => Horde::link($smime_url->copy()->add(array('actionID' => 'view_public_key', 'email' => $val['email'])), sprintf(_("View %s Public Key"), $val['name']), null, 'view_key'),
1486: 'info' => Horde::link($smime_url->copy()->add(array('actionID' => 'info_public_key', 'email' => $val['email'])), sprintf(_("Information on %s Public Key"), $val['name']), null, 'info_key'),
1487: 'delete' => Horde::link($self_url->copy()->add(array('delete_smime_pubkey' => 1, 'email' => $val['email'])), sprintf(_("Delete %s Public Key"), $val['name']), null, null, "window.confirm('" . addslashes(_("Are you sure you want to delete this public key?")) . "')")
1488: );
1489: }
1490: $t->set('pubkey_list', $plist);
1491: }
1492:
1493: if ($GLOBALS['session']->get('imp', 'file_upload')) {
1494: $t->set('can_import', true);
1495: $t->set('no_source', !$GLOBALS['prefs']->getValue('add_source'));
1496: if (!$t->get('no_source')) {
1497: $t->set('import_pubkey-help', Horde_Help::link('imp', 'smime-import-pubkey'));
1498:
1499: Horde::addInlineScript(array(
1500: '$("import_smime_public").observe("click", function(e) { ' . Horde::popupJs($smime_url, array('params' => array('actionID' => 'import_public_key', 'reload' => $GLOBALS['session']->store($ui->selfUrl()->setRaw(true), false)), 'height' => 275, 'width' => 750, 'urlencode' => true)) . '; e.stop(); })'
1501: ), 'dom');
1502: }
1503: }
1504:
1505: return $t->fetch(IMP_TEMPLATES . '/prefs/smimepublickey.html');
1506: }
1507:
1508: 1509: 1510: 1511: 1512:
1513: protected function _updateSmimePublicKey($ui)
1514: {
1515: if (isset($ui->vars->delete_smime_pubkey)) {
1516: try {
1517: $GLOBALS['injector']->getInstance('IMP_Crypt_Smime')->deletePublicKey($ui->vars->email);
1518: $GLOBALS['notification']->push(sprintf(_("S/MIME Public Key for \"%s\" was successfully deleted."), $ui->vars->email), 'horde.success');
1519: } catch (Horde_Exception $e) {
1520: $GLOBALS['notification']->push($e);
1521: }
1522: }
1523: }
1524:
1525:
1526:
1527: 1528: 1529: 1530: 1531:
1532: protected function _signatureHtml()
1533: {
1534: $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
1535:
1536: $js = array();
1537: foreach (array_keys($identity->getAll('id')) as $key) {
1538: $js[$key] = $identity->getValue('signature_html', $key);
1539: };
1540:
1541: Horde::addInlineJsVars(array(
1542: 'ImpHtmlSignaturePrefs.sigs' => $js
1543: ));
1544:
1545: $t = $GLOBALS['injector']->createInstance('Horde_Template');
1546: $t->setOption('gettext', true);
1547: $t->set('signature', htmlspecialchars($GLOBALS['prefs']->getValue('signature_html')));
1548:
1549: return $t->fetch(IMP_TEMPLATES . '/prefs/signaturehtml.html');
1550: }
1551:
1552:
1553:
1554:
1555: 1556: 1557: 1558: 1559: 1560: 1561:
1562: protected function _updateSource($ui)
1563: {
1564: global $prefs;
1565:
1566: $data = Horde_Core_Prefs_Ui_Widgets::addressbooksUpdate($ui);
1567: $updated = false;
1568:
1569: if (isset($data['sources'])) {
1570: $prefs->setValue('search_sources', $data['sources']);
1571: $GLOBALS['session']->remove('imp', 'ac_ajax');
1572: $updated = true;
1573: }
1574:
1575: if (isset($data['fields'])) {
1576: $prefs->setValue('search_fields', $data['fields']);
1577: $updated = true;
1578: }
1579:
1580: return $updated;
1581: }
1582:
1583:
1584:
1585: 1586: 1587: 1588: 1589:
1590: protected function _spam()
1591: {
1592: $t = $GLOBALS['injector']->createInstance('Horde_Template');
1593: $t->setOption('gettext', true);
1594:
1595: $t->set('label', Horde::label('spam', _("Spam folder:")));
1596: $t->set('nofolder', IMP_Mailbox::formTo(self::PREF_NO_FOLDER));
1597: $t->set('flist', IMP::flistSelect(array(
1598: 'basename' => true,
1599: 'filter' => array('INBOX'),
1600: 'new_folder' => true,
1601: 'selected' => IMP_Mailbox::getPref('spam_folder')
1602: )));
1603: $t->set('special_use', $this->_getSpecialUse(Horde_Imap_Client::SPECIALUSE_JUNK));
1604:
1605: return $t->fetch(IMP_TEMPLATES . '/prefs/spam.html');
1606: }
1607:
1608:
1609:
1610: 1611: 1612: 1613: 1614: 1615: 1616:
1617: protected function _stationeryManagement($ui)
1618: {
1619: $ob = $this->_parseStationeryVars($ui);
1620: $stationery = $GLOBALS['injector']->getInstance('IMP_Compose_Stationery');
1621:
1622: if ($ob->type == 'html') {
1623: IMP_Ui_Editor::init(false, 'content');
1624: }
1625:
1626: $t = $GLOBALS['injector']->createInstance('Horde_Template');
1627: $t->setOption('gettext', true);
1628:
1629: $slist = array();
1630: foreach ($stationery as $key => $choice) {
1631: $slist[] = array(
1632: 'selected' => ($ob->selected === $key),
1633: 'text' => $choice['n'] . ' ' . ($choice['t'] == 'html' ? _("(HTML)") : _("(Plain Text)")),
1634: 'val' => $key
1635: );
1636: }
1637: $t->set('slist', $slist);
1638:
1639: $t->set('selected', $ob->selected);
1640: $t->set('show_delete', ($ob->selected != -1));
1641: $t->set('last_type', $ob->type);
1642: $t->set('name_label', Horde::label('name', _("Stationery name:")));
1643: $t->set('name', $ob->name);
1644: $t->set('type_label', Horde::label('name', _("Stationery type:")));
1645: $t->set('plain', $ob->type == 'plain');
1646: $t->set('html', $ob->type == 'html');
1647: $t->set('content_label', Horde::label('content', _("Stationery:")));
1648: $t->set('content', $ob->content);
1649:
1650: return $t->fetch(IMP_TEMPLATES . '/prefs/stationery.html');
1651: }
1652:
1653: 1654: 1655: 1656: 1657:
1658: protected function _updateStationeryManagement($ui)
1659: {
1660: $ob = $this->_parseStationeryVars($ui);
1661: $stationery = $GLOBALS['injector']->getInstance('IMP_Compose_Stationery');
1662: $updated = false;
1663:
1664: if ($ui->vars->delete) {
1665:
1666: if (isset($stationery[$ob->selected])) {
1667: $updated = sprintf(_("The stationery \"%s\" has been deleted."), $stationery[$ob->selected]['n']);
1668: unset($stationery[$ob->selected]);
1669: }
1670: } elseif ($ui->vars->save) {
1671:
1672: $entry = array(
1673: 'c' => $ob->content,
1674: 'n' => $ob->name,
1675: 't' => $ob->type
1676: );
1677:
1678: if ($ob->selected == -1) {
1679: $stationery[] = $entry;
1680: $updated = sprintf(_("The stationery \"%s\" has been added."), $ob->name);
1681: } else {
1682: $stationery[$ob->selected] = $entry;
1683: $updated = sprintf(_("The stationery \"%s\" has been updated."), $ob->name);
1684: }
1685: }
1686:
1687: if ($updated) {
1688: $GLOBALS['notification']->push($updated, 'horde.success');
1689: }
1690: }
1691:
1692: 1693: 1694: 1695: 1696: 1697: 1698: 1699: 1700: 1701: 1702: 1703: 1704:
1705: protected function _parseStationeryVars($ui)
1706: {
1707: $selected = strlen($ui->vars->stationery)
1708: ? intval($ui->vars->stationery)
1709: : -1;
1710: $stationery = $GLOBALS['injector']->getInstance('IMP_Compose_Stationery');
1711:
1712: if ($ui->vars->last_selected == $selected) {
1713: $content = strval($ui->vars->content);
1714: $name = strval($ui->vars->name);
1715: $type = isset($ui->vars->type)
1716: ? $ui->vars->type
1717: : 'plain';
1718:
1719: if ($content && ($ui->vars->last_type != $type)) {
1720: $content = ($type == 'plain')
1721: ? $GLOBALS['injector']->getInstance('Horde_Core_Factory_TextFilter')->filter($content, 'Html2text')
1722: : IMP_Compose::text2html($content);
1723: }
1724: } elseif ($selected == -1) {
1725: $content = $name = '';
1726: $type = 'plain';
1727: } else {
1728: $entry = $stationery[$selected];
1729: $content = $entry['c'];
1730: $name = $entry['n'];
1731: $type = $entry['t'];
1732: }
1733:
1734:
1735: $ob = new stdClass;
1736: $ob->content = $content;
1737: $ob->name = $name;
1738: $ob->selected = $selected;
1739: $ob->type = $type;
1740:
1741: return $ob;
1742: }
1743:
1744:
1745:
1746: 1747: 1748: 1749: 1750:
1751: protected function _trash()
1752: {
1753: global $injector, $prefs;
1754:
1755: $imp_search = $injector->getInstance('IMP_Search');
1756: $trash_folder = IMP_Mailbox::getPref('trash_folder');
1757:
1758: $t = $injector->createInstance('Horde_Template');
1759: $t->setOption('gettext', true);
1760:
1761: $t->set('label', Horde::label('trash', _("Trash folder:")));
1762: $t->set('nofolder', IMP_Mailbox::formTo(self::PREF_NO_FOLDER));
1763: $t->set('flist', IMP::flistSelect(array(
1764: 'basename' => true,
1765: 'filter' => array('INBOX'),
1766: 'new_folder' => true,
1767: 'selected' => $trash_folder
1768: )));
1769: $t->set('special_use', $this->_getSpecialUse(Horde_Imap_Client::SPECIALUSE_TRASH));
1770:
1771: if (!$prefs->isLocked('vfolder') || $imp_search['vtrash']->enabled) {
1772: $t->set('vtrash', IMP_Mailbox::formTo($imp_search->createSearchId('vtrash')));
1773: $t->set('vtrash_select', $trash_folder->vtrash);
1774: }
1775:
1776: return $t->fetch(IMP_TEMPLATES . '/prefs/trash.html');
1777: }
1778:
1779: 1780: 1781: 1782: 1783: 1784: 1785:
1786: protected function _updateTrash($ui)
1787: {
1788: $imp_search = $GLOBALS['injector']->getInstance('IMP_Search');
1789: $trash = IMP_Mailbox::formFrom($ui->vars->trash);
1790:
1791: if (!$GLOBALS['prefs']->isLocked('vfolder')) {
1792: $vtrash = $imp_search['vtrash'];
1793: $vtrash->enabled = $trash->vtrash;
1794: $imp_search['vtrash'] = $vtrash;
1795: }
1796:
1797: if ($this->_updateSpecialFolders('trash_folder', $trash, $ui->vars->trash_new, Horde_Imap_Client::SPECIALUSE_TRASH, $ui)) {
1798: $GLOBALS['injector']->getInstance('IMP_Factory_Imap')->create()->updateFetchIgnore();
1799: return true;
1800: }
1801:
1802: return false;
1803: }
1804:
1805:
1806:
1807: 1808: 1809: 1810: 1811: 1812: 1813: 1814: 1815: 1816: 1817:
1818: protected function _updateSpecialFolders($pref, $folder, $new, $type, $ui)
1819: {
1820: global $injector, $prefs;
1821:
1822: $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
1823:
1824: if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS) ||
1825: $prefs->isLocked($pref)) {
1826: return false;
1827: }
1828:
1829: if ($mbox_ob = IMP_Mailbox::getPref($pref)) {
1830: $mbox_ob->expire(IMP_Mailbox::CACHE_SPECIALMBOXES);
1831: }
1832:
1833: if ($folder == self::PREF_NO_FOLDER) {
1834: return $prefs->setValue($pref, '');
1835: }
1836:
1837: if (strpos($folder, self::PREF_SPECIALUSE) === 0) {
1838: $folder = IMP_Mailbox::get(substr($folder, strlen(self::PREF_SPECIALUSE)));
1839: } elseif (!empty($new)) {
1840: $new = Horde_String::convertCharset($new, 'UTF-8', 'UTF7-IMAP');
1841: $folder = IMP_Mailbox::get($new)->namespace_append;
1842: if (!$folder->create(array('special_use' => array($type)))) {
1843: $folder = null;
1844: }
1845: }
1846:
1847: return $folder
1848: ? $prefs->setValue($pref, $folder->pref_to)
1849: : false;
1850: }
1851:
1852: 1853: 1854: 1855: 1856: 1857: 1858:
1859: protected function _getSpecialUse($use)
1860: {
1861: global $injector;
1862:
1863: if (is_null($this->_cache)) {
1864: $this->_cache = $injector->getInstance('IMP_Factory_Imap')->create()->listMailboxes('*', Horde_Imap_Client::MBOX_ALL, array(
1865: 'attributes' => true,
1866: 'special_use' => true,
1867: 'sort' => true
1868: ));
1869: }
1870:
1871: $special_use = array();
1872: foreach ($this->_cache as $val) {
1873: if (in_array($use, $val['attributes'])) {
1874: $mbox_ob = IMP_Mailbox::get($val['mailbox']);
1875: $special_use[] = array(
1876: 'l' => htmlspecialchars($mbox_ob->label),
1877: 'v' => IMP_Mailbox::formTo(self::PREF_SPECIALUSE . $mbox_ob)
1878: );
1879: }
1880: }
1881:
1882: if (empty($special_use)) {
1883: return '';
1884: }
1885:
1886: $t = $injector->createInstance('Horde_Template');
1887: $t->setOption('gettext', true);
1888: $t->set('special_use', $special_use);
1889:
1890: return $t->fetch(IMP_TEMPLATES . '/prefs/specialuse.html');
1891: }
1892:
1893: }
1894: