Overview

Packages

  • IMP
  • None

Classes

  • IMP
  • IMP_Ajax_Application
  • IMP_Ajax_Imple_ContactAutoCompleter
  • IMP_Ajax_Imple_PassphraseDialog
  • IMP_Ajax_Queue
  • IMP_Api
  • IMP_Auth
  • IMP_Block_Newmail
  • IMP_Block_Summary
  • IMP_Compose
  • IMP_Compose_Exception
  • IMP_Compose_Stationery
  • IMP_Contents
  • IMP_Crypt_Pgp
  • IMP_Crypt_Smime
  • IMP_Dimp
  • IMP_Exception
  • IMP_Factory_AuthImap
  • IMP_Factory_Compose
  • IMP_Factory_Contents
  • IMP_Factory_Flags
  • IMP_Factory_Identity
  • IMP_Factory_Imap
  • IMP_Factory_Imaptree
  • IMP_Factory_Mail
  • IMP_Factory_Mailbox
  • IMP_Factory_MailboxList
  • IMP_Factory_MimeViewer
  • IMP_Factory_Pgp
  • IMP_Factory_Quota
  • IMP_Factory_Search
  • IMP_Factory_Sentmail
  • IMP_Factory_Smime
  • IMP_Filter
  • IMP_Flag_Base
  • IMP_Flag_Imap
  • IMP_Flag_Imap_Answered
  • IMP_Flag_Imap_Deleted
  • IMP_Flag_Imap_Draft
  • IMP_Flag_Imap_Flagged
  • IMP_Flag_Imap_Forwarded
  • IMP_Flag_Imap_Junk
  • IMP_Flag_Imap_NotJunk
  • IMP_Flag_Imap_Seen
  • IMP_Flag_System_Attachment
  • IMP_Flag_System_Encrypted
  • IMP_Flag_System_HighPriority
  • IMP_Flag_System_List
  • IMP_Flag_System_LowPriority
  • IMP_Flag_System_Match_Address
  • IMP_Flag_System_Match_Flag
  • IMP_Flag_System_Match_Header
  • IMP_Flag_System_Personal
  • IMP_Flag_System_Signed
  • IMP_Flag_System_Unseen
  • IMP_Flag_User
  • IMP_Flags
  • IMP_Imap
  • IMP_Imap_Acl
  • IMP_Imap_Exception
  • IMP_Imap_PermanentFlags
  • IMP_Imap_Thread
  • IMP_Imap_Tree
  • IMP_Indices
  • IMP_Indices_Form
  • IMP_LoginTasks_SystemTask_GarbageCollection
  • IMP_LoginTasks_SystemTask_Upgrade
  • IMP_LoginTasks_SystemTask_UpgradeAuth
  • IMP_LoginTasks_Task_Autocreate
  • IMP_LoginTasks_Task_DeleteAttachmentsMonthly
  • IMP_LoginTasks_Task_DeleteSentmailMonthly
  • IMP_LoginTasks_Task_FilterOnLogin
  • IMP_LoginTasks_Task_PurgeSentmail
  • IMP_LoginTasks_Task_PurgeSpam
  • IMP_LoginTasks_Task_PurgeTrash
  • IMP_LoginTasks_Task_RecoverDraft
  • IMP_LoginTasks_Task_RenameSentmailMonthly
  • IMP_Mailbox
  • IMP_Mailbox_List
  • IMP_Mailbox_List_Track
  • IMP_Maillog
  • IMP_Menu_Dimp
  • IMP_Message
  • IMP_Mime_Status
  • IMP_Mime_Viewer_Alternative
  • IMP_Mime_Viewer_Appledouble
  • IMP_Mime_Viewer_Audio
  • IMP_Mime_Viewer_Enriched
  • IMP_Mime_Viewer_Externalbody
  • IMP_Mime_Viewer_Html
  • IMP_Mime_Viewer_Images
  • IMP_Mime_Viewer_Itip
  • IMP_Mime_Viewer_Mdn
  • IMP_Mime_Viewer_Partial
  • IMP_Mime_Viewer_Pdf
  • IMP_Mime_Viewer_Pgp
  • IMP_Mime_Viewer_Plain
  • IMP_Mime_Viewer_Related
  • IMP_Mime_Viewer_Rfc822
  • IMP_Mime_Viewer_Smil
  • IMP_Mime_Viewer_Smime
  • IMP_Mime_Viewer_Status
  • IMP_Mime_Viewer_Vcard
  • IMP_Mime_Viewer_Video
  • IMP_Mime_Viewer_Zip
  • IMP_Notification_Event_Status
  • IMP_Notification_Handler_Decorator_ImapAlerts
  • IMP_Notification_Handler_Decorator_NewmailNotify
  • IMP_Notification_Listener_AjaxStatus
  • Imp_Prefs_Identity
  • IMP_Prefs_Ui
  • IMP_Quota
  • IMP_Quota_Base
  • IMP_Quota_Command
  • IMP_Quota_Hook
  • IMP_Quota_Imap
  • IMP_Quota_Maildir
  • IMP_Quota_Mdaemon
  • IMP_Quota_Mercury32
  • IMP_Quota_Null
  • IMP_Quota_Sql
  • IMP_Search
  • IMP_Search_Element
  • IMP_Search_Element_Attachment
  • IMP_Search_Element_Autogenerated
  • IMP_Search_Element_Bulk
  • IMP_Search_Element_Contacts
  • IMP_Search_Element_Date
  • IMP_Search_Element_Flag
  • IMP_Search_Element_Header
  • IMP_Search_Element_Mailinglist
  • IMP_Search_Element_Or
  • IMP_Search_Element_Personal
  • IMP_Search_Element_Recipient
  • IMP_Search_Element_Size
  • IMP_Search_Element_Text
  • IMP_Search_Element_Within
  • IMP_Search_Filter
  • IMP_Search_Filter_Attachment
  • IMP_Search_Filter_Autogenerated
  • IMP_Search_Filter_Builtin
  • IMP_Search_Filter_Bulk
  • IMP_Search_Filter_Contacts
  • IMP_Search_Filter_Mailinglist
  • IMP_Search_Filter_Personal
  • IMP_Search_Query
  • IMP_Search_Vfolder
  • IMP_Search_Vfolder_Builtin
  • IMP_Search_Vfolder_Vinbox
  • IMP_Search_Vfolder_Vtrash
  • IMP_Sentmail
  • IMP_Sentmail_Base
  • IMP_Sentmail_Null
  • IMP_Sentmail_Sql
  • IMP_Spam
  • IMP_Test
  • IMP_Tree_Flist
  • IMP_Tree_Jquerymobile
  • IMP_Tree_Simplehtml
  • IMP_Ui_Compose
  • IMP_Ui_Editor
  • IMP_Ui_Folder
  • IMP_Ui_Headers
  • IMP_Ui_Imageview
  • IMP_Ui_Mailbox
  • IMP_Ui_Message
  • IMP_Ui_Mimp
  • IMP_Ui_Search
  • IMP_Views_Compose
  • IMP_Views_ListMessages
  • IMP_Views_ShowMessage
  • Overview
  • Package
  • Class
  • Tree
   1: <?php
   2: /**
   3:  * IMP-specific prefs handling.
   4:  *
   5:  * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
   6:  *
   7:  * See the enclosed file COPYING for license information (GPL). If you
   8:  * did not receive this file, see http://www.horde.org/licenses/gpl.
   9:  *
  10:  * @author   Michael Slusarz <slusarz@horde.org>
  11:  * @category Horde
  12:  * @license  http://www.horde.org/licenses/gpl GPL
  13:  * @package  IMP
  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:      * Cached folder list.
  23:      *
  24:      * @var array
  25:      */
  26:     protected $_cache = null;
  27: 
  28:     /**
  29:      * Run once on init when viewing prefs for an application.
  30:      *
  31:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
  32:      */
  33:     public function prefsInit($ui)
  34:     {
  35:         global $conf, $injector, $registry;
  36: 
  37:         $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
  38: 
  39:         /* Hide appropriate prefGroups. */
  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:      * Determine active prefs when displaying a group.
  74:      *
  75:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
  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:                 /* Set the timezone on this page so the output uses the
 315:                  * configured time zone's time, not the system's time zone. */
 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:      * Generate code used to display a special preference.
 336:      *
 337:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
 338:      * @param string $item             The preference name.
 339:      *
 340:      * @return string  The HTML code to display on the prefs page.
 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:      * Special preferences handling on update.
 434:      *
 435:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
 436:      * @param string $item             The preference name.
 437:      *
 438:      * @return boolean  True if preference was updated.
 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:      * Called when preferences are changed.
 513:      *
 514:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
 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:         /* Always check to make sure we have a valid trash folder if delete to
 525:          * trash is active. */
 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:     /* ACL management. */
 556: 
 557:     /**
 558:      * Create code for ACL management.
 559:      *
 560:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
 561:      *
 562:      * @return string  HTML UI code.
 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:                 /* Create table of each ACL option for each user granted
 610:                  * permissions; enabled indicates the right has been given to
 611:                  * the user. */
 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:      * Update ACL related preferences.
 661:      *
 662:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
 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:                 /* Check to see if ACL changed, but only compare rights we
 703:                  * understand. */
 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:                 /* If we dont see ANY form params, the user deleted all
 725:                  * rights. */
 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:     /* Drafts selection. */
 737: 
 738:     /**
 739:      * Create code for drafts selection.
 740:      *
 741:      * @return string  HTML UI code.
 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:     /* Message encryption selection. */
 762: 
 763:     /**
 764:      * Create code for message encryption selection.
 765:      *
 766:      * @return string  HTML UI code.
 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:     /* IMAP Flag (keyword) management. */
 779: 
 780:     /**
 781:      * Create code for flag management.
 782:      *
 783:      * @return string  HTML UI code.
 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:      * Update IMAP flag related preferences.
 830:      *
 831:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
 832:      *
 833:      * @return boolean  True if preferences were updated.
 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:         // Don't set updated on these actions. User may want to do more
 846:         // actions.
 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:                 /* Change labels for user-defined flags. */
 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:                 /* Change background for all flags. */
 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:     /* Initial page selection. */
 883: 
 884:     /**
 885:      * Create code for initial page selection.
 886:      *
 887:      * @return string  HTML UI code.
 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:     /* Mailto: handler. */
 917: 
 918:     /**
 919:      * Create code for the mailto handler link.
 920:      *
 921:      * @return string  HTML UI code.
 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:     /* Newmail audio selection. */
 947: 
 948:     /**
 949:      * Create code for newmail audio selection.
 950:      *
 951:      * @return string  HTML UI code.
 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:     /* PGP Private Key management. */
 977: 
 978:     /**
 979:      * Create code for personal PGP key management.
 980:      *
 981:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
 982:      *
 983:      * @return string  HTML UI code.
 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:      * Update personal PGP related preferences.
1052:      *
1053:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
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:             /* Check that fields are filled out (except for Comment) and that
1062:              * the passphrases match. */
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:     /* PGP Public Key management. */
1094: 
1095:     /**
1096:      * Create code for PGP public key management.
1097:      *
1098:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
1099:      *
1100:      * @return string  HTML UI code.
1101:      */
1102:     protected function _pgpPublicKey($ui)
1103:     {
1104:         $imp_pgp = $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp');
1105: 
1106:         /* Get list of Public Keys on keyring. */
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:      * Update PGP public key related preferences.
1153:      *
1154:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
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:     /* Saved Searches management. */
1169: 
1170:     /**
1171:      * Create code for saved searches management.
1172:      *
1173:      * @return string  HTML UI code.
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:      * Update Saved Searches related preferences.
1255:      *
1256:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
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:             /* Remove 'enable_' prefix. */
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:             /* Update enabled status for Virtual Folders. */
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:                 /* Only change enabled status for virtual folders displayed
1285:                  * on the preferences screen. */
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:             /* Update enabled status for Filters. */
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:     /* Sentmail selection. */
1308: 
1309:     /**
1310:      * Create code for sentmail selection.
1311:      *
1312:      * @return string  HTML UI code.
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:      * Update sentmail related preferences.
1345:      *
1346:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
1347:      *
1348:      * @return boolean  True if preferences were updated.
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:     /* Personal S/MIME certificate management. */
1381: 
1382:     /**
1383:      * Create code for personal S/MIME certificate management.
1384:      *
1385:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
1386:      *
1387:      * @return string  HTML UI code.
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:      * Update personal S/MIME certificate related preferences.
1436:      *
1437:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
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:     /* S/MIME public certificate management. */
1451: 
1452:     /**
1453:      * Create code for S/MIME public certificate management.
1454:      *
1455:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
1456:      *
1457:      * @return string  HTML UI code.
1458:      */
1459:     protected function _smimePublicKey($ui)
1460:     {
1461:         $imp_smime = $GLOBALS['injector']->getInstance('IMP_Crypt_Smime');
1462: 
1463:         /* Get list of Public Keys on keyring. */
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:      * Update S/MIME public key related preferences.
1510:      *
1511:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
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:     /* HTML Signature editing. */
1526: 
1527:     /**
1528:      * Create code for HTML Signature editing.
1529:      *
1530:      * @return string  HTML UI code.
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:     /* Addressbook selection. */
1554: 
1555:     /**
1556:      * Update address book related preferences.
1557:      *
1558:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
1559:      *
1560:      * @return boolean  True if preferences were updated.
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:     /* Spam selection. */
1584: 
1585:     /**
1586:      * Create code for spam selection.
1587:      *
1588:      * @return string  HTML UI code.
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:     /* Stationery management. */
1609: 
1610:     /**
1611:      * Create code for stationery management.
1612:      *
1613:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
1614:      *
1615:      * @return string  HTML UI code.
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:      * Update stationery related preferences.
1655:      *
1656:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
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:             /* Delete stationery. */
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:             /* Saving stationery. */
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:      * Parse the variables for the stationery management screen.
1694:      *
1695:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
1696:      *
1697:      * @return object  Object with the following properties:
1698:      * <pre>
1699:      * 'content' - (string) Content.
1700:      * 'name' - (string) Name.
1701:      * 'selected' - (integer) The currently selected value.
1702:      * 'type' - (string) Type.
1703:      * </pre>
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:     /* Trash selection. */
1745: 
1746:     /**
1747:      * Create code for trash selection.
1748:      *
1749:      * @return string  HTML UI code.
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:      * Update trash related preferences.
1781:      *
1782:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
1783:      *
1784:      * @return boolean  True if preferences were updated.
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:     /* Utility functions. */
1806: 
1807:     /**
1808:      * Update special folder preferences.
1809:      *
1810:      * @param string $pref             The pref name to update.
1811:      * @param string $folder           The old name.
1812:      * @param string $new              The new name.
1813:      * @param string $type             Special use attribute (RFC 6154).
1814:      * @param Horde_Core_Prefs_Ui $ui  The UI object.
1815:      *
1816:      * @return boolean  True if preferences were updated.
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:      * Get the list of special use mailboxes of a certain type.
1854:      *
1855:      * @param string $use  The special-use flag.
1856:      *
1857:      * @return string  HTML code.
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: 
API documentation generated by ApiGen