Add Identity binder in IMP
authorMichael M Slusarz <slusarz@curecanti.org>
Wed, 14 Apr 2010 09:55:33 +0000 (03:55 -0600)
committerMichael M Slusarz <slusarz@curecanti.org>
Wed, 14 Apr 2010 20:03:53 +0000 (14:03 -0600)
24 files changed:
imp/compose-dimp.php
imp/compose-mimp.php
imp/compose.php
imp/lib/Ajax/Application.php
imp/lib/Application.php
imp/lib/Compose.php
imp/lib/Crypt/Pgp.php
imp/lib/Crypt/Smime.php
imp/lib/IMP.php
imp/lib/Imap/Flags.php
imp/lib/Imap/Tree.php
imp/lib/Injector/Binder/Identity.php [new file with mode: 0644]
imp/lib/LoginTasks/Task/DeleteSentmailMonthly.php
imp/lib/LoginTasks/Task/PurgeSentmail.php
imp/lib/LoginTasks/Task/RenameSentmailMonthly.php
imp/lib/Mime/Viewer/Itip.php
imp/lib/Prefs/Ui.php
imp/lib/Spam.php
imp/lib/Ui/Compose.php
imp/lib/Ui/Mailbox.php
imp/lib/Views/Compose.php
imp/message-mimp.php
imp/message.php
imp/view.php

index 2c02791..109e61e 100644 (file)
@@ -51,7 +51,7 @@ if ($vars->popup) {
     $js[] = 'DIMP.conf_compose.popup = 1';
 }
 
-$identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+$identity = $injector->getInstance('IMP_Identity');
 if (!$prefs->isLocked('default_identity') && isset($vars->identity)) {
     $identity->setDefault($vars->identity);
 }
index 74304d2..29b0b41 100644 (file)
@@ -50,7 +50,7 @@ if ($prefs->getValue('compose_bcc')) {
 }
 
 /* Set the current identity. */
-$identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+$identity = $injector->getInstance('IMP_Identity');
 if (!$prefs->isLocked('default_identity') && isset($vars->identity)) {
     $identity->setDefault($vars->identity);
 }
index 5999fba..69044c7 100644 (file)
@@ -28,7 +28,7 @@ $oldrtemode = $rtemode = null;
 $vars = Horde_Variables::getDefaultVariables();
 
 /* Set the current identity. */
-$identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+$identity = $injector->getInstance('IMP_Identity');
 if (!$prefs->isLocked('default_identity')) {
     if (!is_null($vars->identity)) {
         $identity->setDefault($vars->identity);
index abfa4a8..8909cb8 100644 (file)
@@ -1497,7 +1497,7 @@ class IMP_Ajax_Application extends Horde_Ajax_Application_Base
         $result->success = 1;
 
         /* Set up identity. */
-        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
         if (isset($this->_vars->identity) &&
             !$GLOBALS['prefs']->isLocked('default_identity')) {
             $identity->setDefault($this->_vars->identity);
index ba8e502..5d430c7 100644 (file)
@@ -97,6 +97,7 @@ class IMP_Application extends Horde_Registry_Application
             'IMP_Crypt_Pgp' => new IMP_Injector_Binder_Pgp(),
             'IMP_Crypt_Smime' => new IMP_Injector_Binder_Smime(),
             'IMP_Folder' => new IMP_Injector_Binder_Folder(),
+            'IMP_Identity' => new IMP_Injector_Binder_Identity(),
             'IMP_Imap_Tree' => new IMP_Injector_Binder_Imaptree(),
             'IMP_Sentmail' => new IMP_Injector_Binder_Sentmail()
         );
index e302089..0306de8 100644 (file)
@@ -399,7 +399,7 @@ class IMP_Compose
         $identity_id = null;
         $headers = $contents->getHeaderOb();
         if (($fromaddr = Horde_Mime_Address::bareAddress($headers->getValue('from')))) {
-            $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+            $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
             $identity_id = $identity->getMatchingIdentity($fromaddr);
         }
 
@@ -1354,7 +1354,7 @@ class IMP_Compose
             }
 
             /* Filter out our own address from the addresses we reply to. */
-            $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+            $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
             $all_addrs = array_keys($identity->getAllFromAddresses(true));
 
             /* Build the To: header. It is either:
@@ -1627,7 +1627,7 @@ class IMP_Compose
         $recip = $this->recipientList(array('to' => $to));
         $recipients = implode(', ', $recip['list']);
 
-        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
         $from_addr = $identity->getFromAddress();
 
         $contents = $this->getContentsOb();
@@ -1681,7 +1681,7 @@ class IMP_Compose
             $msgAddresses[] = $h->getValue($val);
         }
 
-        return Horde_Prefs_Identity::singleton(array('imp', 'imp'))->getMatchingIdentity($msgAddresses);
+        return $GLOBALS['injector']->getInstance('IMP_Identity')->getMatchingIdentity($msgAddresses);
     }
 
     /**
index d6c115c..1d77a31 100644 (file)
@@ -184,7 +184,7 @@ class IMP_Crypt_Pgp extends Horde_Crypt_Pgp
             /* TODO: Retrieve by ID. */
 
             /* See if the address points to the user's public key. */
-            $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+            $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
             $personal_pubkey = $this->getPersonalPublicKey();
             if (!empty($personal_pubkey) && $identity->hasAddress($address)) {
                 $result = $personal_pubkey;
index 5b2b0fb..da172d7 100644 (file)
@@ -168,7 +168,7 @@ class IMP_Crypt_Smime extends Horde_Crypt_Smime
             $key = $GLOBALS['registry']->call('contacts/getField', array($address, self::PUBKEY_FIELD, $params['sources'], false, true));
         } catch (Horde_Exception $e) {
             /* See if the address points to the user's public key. */
-            $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+            $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
             $personal_pubkey = $this->getPersonalPublicKey();
             if (!empty($personal_pubkey) && $identity->hasAddress($address)) {
                 return $personal_pubkey;
index d2ed501..34d4964 100644 (file)
@@ -1017,7 +1017,7 @@ class IMP
     static public function isSpecialFolder($mbox)
     {
         /* Get the identities. */
-        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
 
         return (($mbox == self::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true)) || in_array($mbox, $identity->getAllSentmailFolders()));
     }
index f24826f..77f9222 100644 (file)
@@ -265,7 +265,7 @@ class IMP_Imap_Flags
 
         if (isset($options['personal'])) {
             if (is_array($options['personal'])) {
-                $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+                $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
                 foreach ($options['personal'] as $val) {
                     if ($identity->hasAddress($val['inner'])) {
                         $process['personal'] = $f['personal'];
index 87df48d..ddd2b3d 100644 (file)
@@ -1799,7 +1799,7 @@ class IMP_Imap_Tree
      */
     public function getSpecialMailboxes()
     {
-        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
         return array(
             'draft' => IMP::folderPref($GLOBALS['prefs']->getValue('drafts_folder'), true),
             'sent' => $identity->getAllSentmailFolders(),
diff --git a/imp/lib/Injector/Binder/Identity.php b/imp/lib/Injector/Binder/Identity.php
new file mode 100644 (file)
index 0000000..bf91a11
--- /dev/null
@@ -0,0 +1,29 @@
+<?php
+/**
+ * Binder for IMP's Identity object.
+ *
+ * Copyright 2010 The Horde Project (http://www.horde.org/)
+ *
+ * See the enclosed file COPYING for license information (GPL). If you
+ * did not receive this file, see http://www.fsf.org/copyleft/gpl.html.
+ *
+ * @author  Michael Slusarz <slusarz@horde.org>
+ * @package IMP
+ */
+class IMP_Injector_Binder_Identity implements Horde_Injector_Binder
+{
+    /**
+     */
+    public function create(Horde_Injector $injector)
+    {
+        return Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+    }
+
+    /**
+     */
+    public function equals(Horde_Injector_Binder $binder)
+    {
+        return false;
+    }
+
+}
index 78eef0f..a33884d 100644 (file)
@@ -34,7 +34,7 @@ class IMP_LoginTasks_Task_DeleteSentmailMonthly extends Horde_LoginTasks_Task
         /* Get list of all folders, parse through and get the list of all
            old sent-mail folders. Then sort this array according to
            the date. */
-        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
         $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
         $sent_mail_folders = $identity->getAllSentmailFolders();
 
index b3b2250..9f81531 100644 (file)
@@ -96,7 +96,7 @@ class IMP_LoginTasks_Task_PurgeSentmail extends Horde_LoginTasks_Task
      */
     protected function _getFolders()
     {
-        return Horde_Prefs_Identity::singleton(array('imp', 'imp'))->getAllSentmailfolders();
+        return $GLOBALS['injector']->getInstance('IMP_Identity')->getAllSentmailfolders();
     }
 
 }
index 0a04e0c..efa886a 100644 (file)
@@ -33,7 +33,7 @@ class IMP_LoginTasks_Task_RenameSentmailMonthly extends Horde_LoginTasks_Task
     {
         $success = true;
 
-        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
         $imp_folder = $GLOBALS['injector']->getInstance('IMP_Folder');
 
         foreach ($identity->getAllSentmailfolders() as $sent_folder) {
@@ -64,7 +64,7 @@ class IMP_LoginTasks_Task_RenameSentmailMonthly extends Horde_LoginTasks_Task
      */
     public function describe()
     {
-        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
 
         $new_folders = $old_folders = array();
         foreach ($identity->getAllSentmailfolders() as $folder) {
index 29e73bc..d45172e 100644 (file)
@@ -263,7 +263,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver
                     $vEvent_reply->setAttribute('ORGANIZER', $vEvent->getAttribute('ORGANIZER'), array_pop($organizer));
 
                     // Find out who we are and update status.
-                    $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+                    $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
                     $attendees = $vEvent->getAttribute('ATTENDEE');
                     if (!is_array($attendees)) {
                         $attendees = array($attendees);
@@ -401,7 +401,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver
                                                  array('startStamp' => $startStamp,
                                                        'endStamp' => $endStamp));
                     // Find out who we are and update status.
-                    $identity = Horde_Prefs_Identity::singleton();
+                    $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
                     $email = $identity->getFromAddress();
 
                     // Build the reply.
@@ -645,7 +645,7 @@ class IMP_Horde_Mime_Viewer_Itip extends Horde_Mime_Viewer_Driver
                 // Check that you are one of the attendees here.
                 $is_attendee = false;
                 if (!($attendees instanceof PEAR_Error) && !empty($attendees)) {
-                    $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+                    $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
                     for ($i = 0, $c = count($attendees); $i < $c; ++$i) {
                         $attendee = parse_url($attendees[$i]);
                         if (!empty($attendee['path']) &&
index 69eded8..01cac39 100644 (file)
@@ -401,7 +401,7 @@ class IMP_Prefs_Ui
             return false;
 
         case 'signature_html_select':
-            return Horde_Prefs_Identity::singleton(array('imp', 'imp'))->setValue('signature_html', $ui->vars->signature_html);
+            return $GLOBALS['injector']->getInstance('IMP_Identity')->setValue('signature_html', $ui->vars->signature_html);
 
         case 'soundselect':
             return $prefs->setValue('nav_audio', $ui->vars->nav_audio);
@@ -994,7 +994,7 @@ class IMP_Prefs_Ui
                 $t->set('deletekeypair', addslashes(_("Are you sure you want to delete your keypair? (This is NOT recommended!)")));
                 $t->set('personalkey-delete-help', Horde_Help::link('imp', 'pgp-personalkey-delete'));
             } else {
-                $imp_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+                $imp_identity = $GLOBALS['injector']->getInstance('IMP_Identity');
                 $t->set('fullname', $imp_identity->getFullname());
                 $t->set('personalkey-create-name-help', Horde_Help::link('imp', 'pgp-personalkey-create-name'));
                 $t->set('personalkey-create-comment-help', Horde_Help::link('imp', 'pgp-personalkey-create-comment'));
@@ -1140,7 +1140,7 @@ class IMP_Prefs_Ui
      */
     protected function _sentmail()
     {
-        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
 
         $js = array();
         foreach (array_keys($identity->getAll('id')) as $key) {
@@ -1200,8 +1200,7 @@ class IMP_Prefs_Ui
             $imp_folder->create($sent_mail_folder, $prefs->getValue('subscribe'));
         }
 
-        $imp_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
-        $imp_identity->setValue('sent_mail_folder', IMP::folderPref($sent_mail_folder, false));
+        $GLOBALS['injector']->getInstance('IMP_Identity')->setValue('sent_mail_folder', IMP::folderPref($sent_mail_folder, false));
 
         return true;
     }
@@ -1349,7 +1348,7 @@ class IMP_Prefs_Ui
      */
     protected function _signatureHtml()
     {
-        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
 
         $js = array();
         foreach (array_keys($identity->getAll('id')) as $key) {
index 2378e73..df21274 100644 (file)
@@ -110,9 +110,8 @@ class IMP_Spam
 
                     if (!isset($imp_compose)) {
                         $imp_compose = IMP_Compose::singleton();
-                        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
                         try {
-                            $from_line = $identity->getFromLine();
+                            $from_line = $GLOBALS['injector']->getInstance('IMP_Identity')->getFromLine();
                         } catch (Horde_Exception $e) {
                             $from_line = null;
                         }
index c6c6f57..d0ea5df 100644 (file)
@@ -271,7 +271,7 @@ class IMP_Ui_Compose
     public function identityJs()
     {
         $identities = array();
-        $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
 
         $html_sigs = $identity->getAllSignatures('html');
 
@@ -308,7 +308,7 @@ class IMP_Ui_Compose
      */
     public function convertComposeText($data, $to, $identity)
     {
-        $imp_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+        $imp_identity = $GLOBALS['injector']->getInstance('IMP_Identity');
         $replaced = 0;
 
         $html_sig = $imp_identity->getSignature('html', $identity);
index f3f290e..25334d3 100644 (file)
@@ -78,8 +78,7 @@ class IMP_Ui_Mailbox
             $ret['from'] = _("Invalid Address");
             $ret['error'] = true;
         } else {
-            $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
-            if ($identity->hasAddress($from['inner'])) {
+            if ($GLOBALS['injector']->getInstance('IMP_Identity')->hasAddress($from['inner'])) {
                 /* This message was sent by one of the user's identity
                  * addresses - show To: information instead. */
                 if (empty($ob['to'])) {
index 0dd89fd..1ae6c13 100644 (file)
@@ -47,7 +47,7 @@ class IMP_Views_Compose
 
         if (empty($args['redirect'])) {
             /* Load Identity. */
-            $identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+            $identity = $GLOBALS['injector']->getInstance('IMP_Identity');
             $selected_identity = $identity->getDefault();
 
             /* Generate identities list. */
index fa231c7..5a697b4 100644 (file)
@@ -166,7 +166,7 @@ if (($vars->a == 'pa') &&
 }
 
 /* Create the Identity object. */
-$user_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+$user_identity = $injector->getInstance('IMP_Identity');
 
 /* Develop the list of headers to display. */
 $basic_headers = $imp_ui->basicHeaders();
index 6da7b52..3a1166c 100644 (file)
@@ -43,7 +43,7 @@ if (!$imp_mailbox->isValidIndex(false)) {
 $imp_message = $injector->getInstance('IMP_Message');
 
 /* Initialize the user's identities. */
-$user_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+$user_identity = $injector->getInstance('IMP_Identity');
 
 /* Run through action handlers. */
 $vars = Horde_Variables::getDefaultVariables();
index 7f0d651..2d548c1 100644 (file)
@@ -234,7 +234,7 @@ case 'print_attach':
             }
 
             if (!empty($conf['print']['add_printedby'])) {
-                $user_identity = Horde_Prefs_Identity::singleton(array('imp', 'imp'));
+                $user_identity = $injector->getInstance('IMP_Identity');
                 $headers[] = array(
                     'header' => htmlspecialchars(_("Printed By")),
                     'value' => htmlspecialchars($user_identity->getFullname() ? $user_identity->getFullname() : Horde_Auth::getAuth())