Ticket #5388 - S/MIME now fully works in DIMP
authorMichael M Slusarz <slusarz@curecanti.org>
Mon, 8 Dec 2008 07:22:37 +0000 (00:22 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Mon, 8 Dec 2008 07:24:14 +0000 (00:24 -0700)
imp/compose.php
imp/docs/CHANGES
imp/imp-dimp.php
imp/lib/Crypt/smime.php
imp/lib/IMP.php
imp/lib/Mime/Viewer/smime.php
imp/smime.php
imp/templates/smime/passphrase.html [deleted file]

index 9b75879..e17d66a 100644 (file)
@@ -710,17 +710,13 @@ if ($get_sig && isset($msg) && !empty($sig)) {
 
 /* Open the passphrase window here. */
 if ($pgp_passphrase_dialog || $pgp_symmetric_passphrase_dialog) {
-    $imp_pgp = &Horde_Crypt::singleton(array('imp', 'pgp'));
-    Horde::addScriptFile('popup.js', 'imp', true);
     if ($pgp_passphrase_dialog) {
         $notification->push(IMP::passphraseDialogJS('PGPPersonal', 'uniqSubmit(\'send_message\')'), 'javascript');
     } else {
         $notification->push(IMP::passphraseDialogJS('PGPSymmetric', 'uniqSubmit(\'send_message\')', array('symmetricid' => 'imp_compose_' . $composeCacheID)), 'javascript');
     }
 } elseif ($smime_passphrase_dialog) {
-    $imp_smime = &Horde_Crypt::singleton(array('imp', 'smime'));
-    Horde::addScriptFile('popup.js', 'imp', true);
-    $notification->push($imp_smime->getJSOpenWinCode('open_passphrase_dialog', "opener.focus();opener.uniqSubmit('send_message');"), 'javascript');
+    $notification->push(IMP::passphraseDialogJS('SMIMEPersonal', 'uniqSubmit(\'send_message\')'), 'javascript');
 }
 
 /* If PGP encryption is set by default, and we have a recipient list on first
index d7061f0..711b068 100644 (file)
@@ -6,7 +6,7 @@ v5.0-cvs
       the PGP public key (Bug #4221).
 [mms] Removed Special Characters menu.
 [mms] Add 'undelete' to Other Actions menu (Bug #7496) (DIMP).
-[mms] PGP functions now work in DIMP (Bug #5388).
+[mms] All PGP & S/MIME functions now work in DIMP (Bug #5388).
 [mms] Encrypted bodytext now appears when replying/forwarding a message
       (Request #1345).
 [mms] When deleting/emptying a folder, display message count (Request #7424).
index 0dde335..a7bce41 100644 (file)
@@ -688,25 +688,34 @@ case 'SendMDN':
 
 case 'PGPSymmetric':
 case 'PGPPersonal':
-    $imp_pgp = &Horde_Crypt::singleton(array('imp', 'pgp'));
-    $secure_check = $imp_pgp->requireSecureConnection();
+case 'SMIMEPersonal':
+    $result = new stdClass;
+    $result->success = false;
 
-    $symmetricid = Util::getFormData('symmetricid');
     $passphrase = Util::getFormData('passphrase');
 
-    $result = new stdClass;
-    $result->success = false;
+    if ($action == 'SMIMEPersonal') {
+        $imp_smime = &Horde_Crypt::singleton(array('imp', 'smime'));
+        $secure_check = $imp_smime->requireSecureConnection();
+        if (!is_a($secure_check, 'PEAR_Error') && $passphrase) {
+            $res = $imp_smime->storePassphrase($passphrase);
+        }
+    } else {
+        $imp_pgp = &Horde_Crypt::singleton(array('imp', 'pgp'));
+        $secure_check = $imp_pgp->requireSecureConnection();
+        if (is_a($secure_check, 'PEAR_Error') && $passphrase) {
+            $res = $imp_pgp->storePassphrase(($action == 'PGPSymmetric') ? 'symmetric' : 'personal', $passphrase, Util::getFormData('symmetricid'));
+        }
+    }
 
     if (is_a($secure_check, 'PEAR_Error')) {
         $result->error = $secure_check->getMessage();
-    } elseif ($passphrase) {
-        if ($imp_pgp->storePassphrase(($action == 'PGPSymmetric') ? 'symmetric' : 'personal', $passphrase, $symmetricid)) {
-            $result->success = true;
-        } else {
-            $result->error = _("Invalid passphrase entered.");
-        }
-    } else {
+    } elseif (!$passphrase) {
         $result->error = _("No passphrase entered.");
+    } elseif ($res) {
+        $result->success = true;
+    } else {
+        $result->error = _("Invalid passphrase entered.");
     }
 
     /* TODO - This code will eventually be moved to the API. But this function
@@ -714,7 +723,6 @@ case 'PGPPersonal':
     require_once IMP_BASE . '/lib/DIMP.php';
     $notify = false;
 
-    print_r($_SESSION['imp']['cache']);
     break;
 }
 
index 5ba5c08..c8f3352 100644 (file)
@@ -330,35 +330,11 @@ class IMP_Horde_Crypt_smime extends Horde_Crypt_smime
      */
     public function savePublicKeyURL($mailbox, $uid, $id)
     {
-        return $this->getJSOpenWinCode('save_attachment_public_key', false, array('mailbox' => $mailbox, 'uid' => $uid, 'mime_id' => $id));
-    }
-
-    /**
-     * Print out the link for the javascript S/MIME popup.
-     *
-     * @param integer $actionid  The actionID to perform.
-     * @param mixed $reload      If true, reload base window on close. If text,
-     *                           run this JS on close. If false, don't do
-     *                           anything on close.
-     * @param array $params      Additional parameters needed for the reload
-     *                           page.
-     *
-     * @return string  The javascript link.
-     */
-    public function getJSOpenWinCode($actionid, $reload = true,
-                                     $params = array())
-    {
-        $params['actionID'] = $actionid;
-        if (!empty($reload)) {
-            if (is_bool($reload)) {
-                $params['reload'] = html_entity_decode(Util::removeParameter(Horde::selfUrl(true), array('actionID')));
-            } else {
-                require_once 'Horde/SessionObjects.php';
-                $cacheSess = &Horde_SessionObjects::singleton();
-                $params['passphrase_action'] = $cacheSess->storeOid($reload, false);
-            }
-        }
-
+        $params = array(
+            'actionID' => 'save_attachment_public_key',
+            'uid' => $uid,
+            'mime_id' => $id
+        );
         return IMP::popupIMPString('smime.php', $params, 450, 200);
     }
 
index 7b52b7a..0ac0036 100644 (file)
@@ -1960,6 +1960,10 @@ class IMP
         case 'PGPSymmetric':
             $text = _("Enter the passphrase used to encrypt this message.");
             break;
+
+        case 'SMIMEPersonal':
+            $text = _("Enter your personal S/MIME passphrase.");
+            break;
         }
 
         $js_params = array(
index aa4ee2d..65461b3 100644 (file)
@@ -138,9 +138,18 @@ class IMP_Horde_Mime_Viewer_smime extends Horde_Mime_Viewer_Driver
         /* Make sure we have a passphrase. */
         $passphrase = $this->_impsmime->getPassphrase();
         if ($passphrase === false) {
-            if ($_SESSION['imp']['view'] == 'imp') {
-                // TODO: Fix to work with DIMP
-                $status[] = Horde::link('#', _("You must enter the passphrase for your S/MIME private key to view this message"), null, null, $this->_impsmime->getJSOpenWinCode('open_passphrase_dialog') . 'return false;') . _("You must enter the passphrase for your S/MIME private key to view this message.") . '</a>';
+            $js_action = '';
+            $status[] = _("The message has been encrypted via S/MIME.");
+
+            switch ($_SESSION['imp']['view'] == 'imp') {
+            case 'dimp':
+                $js_action = 'DimpCore.reloadMessage({});';
+                // Fall through
+
+            case 'imp':
+                $status[] = _("The message below has been encrypted via S/MIME.");
+                $status[] = Horde::link('#', '', null, null, IMP::passphraseDialogJS('SMIMEPersonal', $js_action) . ';return false;') . _("You must enter the passphrase for your S/MIME private key to view this message.") . '</a>';
+                break;
             }
             return null;
         }
index a683a58..38d14df 100644 (file)
@@ -43,29 +43,6 @@ function _getImportKey()
     }
 }
 
-function _outputPassphraseDialog($secure_check)
-{
-    if (is_a($secure_check, 'PEAR_Error')) {
-        $GLOBALS['notification']->push($secure_check, 'horde.warning');
-    }
-
-    $title = _("S/MIME Passphrase Input");
-    require IMP_TEMPLATES . '/common-header.inc';
-    IMP::status();
-
-    if (is_a($secure_check, 'PEAR_Error')) {
-        return;
-    }
-
-    $t = new IMP_Template();
-    $t->setOption('gettext', true);
-    $t->set('submit_url', Util::addParameter(Horde::applicationUrl('smime.php'), 'actionID', 'process_passphrase_dialog'));
-    $t->set('reload', htmlspecialchars(html_entity_decode(Util::getFormData('reload'))));
-    $t->set('action', Util::getFormData('passphrase_action'));
-    $t->set('locked_img', Horde::img('locked.png', _("S/MIME"), null, $GLOBALS['registry']->getImageDir('horde')));
-    echo $t->fetch(IMP_TEMPLATES . '/smime/passphrase.html');
-}
-
 function _actionWindow()
 {
     $oid = Util::getFormData('passphrase_action');
@@ -106,36 +83,6 @@ $secure_check = $imp_smime->requireSecureConnection();
 /* Run through the action handlers */
 $actionID = Util::getFormData('actionID');
 switch ($actionID) {
-case 'open_passphrase_dialog':
-    if ($imp_smime->getPassphrase() !== false) {
-        Util::closeWindowJS();
-    } else {
-        _outputPassphraseDialog($secure_check);
-    }
-    exit;
-
-case 'process_passphrase_dialog':
-    if (is_a($secure_check, 'PEAR_Error')) {
-        _outputPassphraseDialog($secure_check);
-    } elseif (Util::getFormData('passphrase')) {
-        if ($imp_smime->storePassphrase(Util::getFormData('passphrase'))) {
-            if (Util::getFormData('passphrase_action')) {
-                _actionWindow();
-            } elseif (Util::getFormData('reload')) {
-                _reloadWindow();
-            } else {
-                Util::closeWindowJS();
-            }
-        } else {
-            $notification->push("Invalid passphrase entered.", 'horde.error');
-            _outputPassphraseDialog($secure_check);
-        }
-    } else {
-        $notification->push("No passphrase entered.", 'horde.error');
-        _outputPassphraseDialog($secure_check);
-    }
-    exit;
-
 case 'delete_key':
     $imp_smime->deletePersonalKeys();
     $notification->push(_("Personal S/MIME keys deleted successfully."), 'horde.success');
@@ -287,7 +234,6 @@ $t->set('use_smime_help', Help::link('imp', 'smime-overview'));
 if (!is_a($openssl_check, 'PEAR_Error') && $prefs->getValue('use_smime')) {
     Horde::addScriptFile('popup.js', 'imp', true);
     $t->set('smimeactive', true);
-    $opensmimewin = $imp_smime->getJSOpenWinCode('open_passphrase_dialog');
     $t->set('manage_pubkey-help', Help::link('imp', 'smime-manage-pubkey'));
 
     $t->set('verify_notlocked', !$prefs->isLocked('smime_verify'));
@@ -332,7 +278,7 @@ if (!is_a($openssl_check, 'PEAR_Error') && $prefs->getValue('use_smime')) {
             $t->set('viewpublic', Horde::link(Util::addParameter($selfURL, 'actionID', 'view_personal_public_key'), _("View Personal Public Key"), null, 'view_key'));
             $t->set('infopublic', Horde::link(Util::addParameter($selfURL, 'actionID', 'info_personal_public_key'), _("Information on Personal Public Key"), null, 'info_key'));
             $passphrase = $imp_smime->getPassphrase();
-            $t->set('passphrase', (empty($passphrase)) ? Horde::link('#', _("Enter Passphrase"), null, null, htmlspecialchars($imp_smime->getJSOpenWinCode('open_passphrase_dialog')) . ' return false;') . _("Enter Passphrase") : Horde::link(Util::addParameter($selfURL, 'actionID', 'unset_passphrase'), _("Unload Passphrase")) . _("Unload Passphrase"));
+            $t->set('passphrase', (empty($passphrase)) ? Horde::link('#', _("Enter Passphrase"), null, null, IMP::passphraseDialogJS('SMIMEPersonal') . ';return false;') . ' return false;') . _("Enter Passphrase") : Horde::link(Util::addParameter($selfURL, 'actionID', 'unset_passphrase'), _("Unload Passphrase")) . _("Unload Passphrase"));
             $t->set('viewprivate', Horde::link(Util::addParameter($selfURL, 'actionID', 'view_personal_private_key'), _("View Personal Private Key"), null, 'view_key'));
             $t->set('deletekeypair', addslashes(_("Are you sure you want to delete your keypair? (This is NOT recommended!)")));
             $t->set('personalkey-delete-help', Help::link('imp', 'smime-delete-personal-certs'));
diff --git a/imp/templates/smime/passphrase.html b/imp/templates/smime/passphrase.html
deleted file mode 100644 (file)
index 8848423..0000000
+++ /dev/null
@@ -1,31 +0,0 @@
-<form method="post" name="passphrase_dialog" action="<tag:submit_url />">
-<if:reload>
-<input type="hidden" name="reload" value="<tag:reload />" />
-</if:reload>
-<if:action>
-<input type="hidden" name="passphrase_action" value="<tag:action />" />
-</if:action>
-
-<table class="smallheader">
- <tr>
-  <td>
-   <tag:locked_img />
-  </td>
-  <td>
-   <gettext>Please enter the passphrase for your S/MIME private key. You will only need to enter this passphrase once per session.</gettext>
-  </td>
- </tr>
-</table>
-
-<div class="nowrap padded">
- <label for="passphrase"><strong><gettext>Passphrase:</gettext></strong></label>&nbsp;
- <input type="password" id="passphrase" name="passphrase" size="15" maxlength="60" />&nbsp;
- <input type="submit" name="submit" class="button" value="<gettext>Submit</gettext>" />
- <input type="button" class="button" onclick="window.close();" value="<gettext>Cancel</gettext>" />
-</p>
-
-</form>
-
-<script type="text/javascript">
-document.passphrase_dialog.passphrase.focus();
-</script>