1: <?php
2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12:
13:
14: 15: 16: 17: 18: 19: 20: 21: 22:
23: class IMP_Prefs_Special_Sentmail extends IMP_Prefs_Special_SpecialMboxes implements Horde_Core_Prefs_Ui_Special
24: {
25: 26:
27: public function init(Horde_Core_Prefs_Ui $ui)
28: {
29: }
30:
31: 32:
33: public function display(Horde_Core_Prefs_Ui $ui)
34: {
35: global $injector, $page_output;
36:
37: $page_output->addScriptFile('folderprefs.js');
38:
39: $identity = $injector->getInstance('IMP_Identity');
40:
41: $js = array();
42: foreach ($identity->getAllSentmail(false) as $key => $val) {
43: $js[$key] = $val->form_to;
44: };
45:
46: $page_output->addInlineJsVars(array(
47: 'ImpFolderPrefs.mboxes' => array('sent_mail' => _("Create a new sent-mail mailbox")),
48: 'ImpFolderPrefs.sentmail' => $js
49: ));
50:
51: $view = new Horde_View(array(
52: 'templatePath' => IMP_TEMPLATES . '/prefs'
53: ));
54: $view->addHelper('Horde_Core_View_Helper_Label');
55:
56: $view->default = IMP_Mailbox::formTo(self::PREF_DEFAULT);
57:
58: $iterator = new IMP_Ftree_IteratorFilter(
59: $injector->getInstance('IMP_Ftree')
60: );
61: $iterator->add($iterator::NONIMAP);
62: $iterator->mboxes = array('INBOX');
63:
64: $view->flist = new IMP_Ftree_Select(array(
65: 'basename' => true,
66: 'iterator' => $iterator,
67: 'new_mbox' => true
68: ));
69: $view->special_use = $this->_getSpecialUse(Horde_Imap_Client::SPECIALUSE_SENT);
70:
71: return $view->render('sentmail');
72: }
73:
74: 75:
76: public function update(Horde_Core_Prefs_Ui $ui)
77: {
78: global $injector, $prefs;
79:
80: $imp_imap = $injector->getInstance('IMP_Factory_Imap')->create();
81:
82: if (!$imp_imap->access(IMP_Imap::ACCESS_FOLDERS) ||
83: $prefs->isLocked(IMP_Mailbox::MBOX_SENT)) {
84: return false;
85: }
86:
87: if (!$ui->vars->sent_mail && $ui->vars->sent_mail_new) {
88: $sent_mail = IMP_Mailbox::get($ui->vars->sent_mail_new)->namespace_append;
89: } else {
90: $sent_mail = IMP_Mailbox::formFrom($ui->vars->sent_mail);
91: if (strpos($sent_mail, self::PREF_SPECIALUSE) === 0) {
92: $sent_mail = IMP_Mailbox::get(substr($sent_mail, strlen(self::PREF_SPECIALUSE)));
93: } elseif (($sent_mail == self::PREF_DEFAULT) &&
94: ($sm_default = $prefs->getDefault(IMP_Mailbox::MBOX_SENT))) {
95: $sent_mail = IMP_Mailbox::get($sm_default)->namespace_append;
96: }
97: }
98:
99: if ($sent_mail && !$sent_mail->create()) {
100: return false;
101: }
102:
103: return $injector->getInstance('IMP_Identity')->setValue(IMP_Mailbox::MBOX_SENT, $sent_mail);
104: }
105:
106: }
107: