Bug #9514: Fix importing S/MIME key
authorMichael M Slusarz <slusarz@curecanti.org>
Tue, 18 Jan 2011 08:25:05 +0000 (01:25 -0700)
committerMichael M Slusarz <slusarz@curecanti.org>
Tue, 18 Jan 2011 08:25:05 +0000 (01:25 -0700)
imp/lib/Mime/Viewer/Smime.php
imp/smime.php

index cc45347..7169ff9 100644 (file)
@@ -295,7 +295,7 @@ class IMP_Mime_Viewer_Smime extends Horde_Mime_Viewer_Base
                     isset($sig_result->email) &&
                     $GLOBALS['registry']->hasMethod('contacts/addField') &&
                     $GLOBALS['prefs']->getValue('add_source')) {
-                    $status[] = '[' . $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', _("View Certificate"), array('params' => array('mode' => IMP_Contents::RENDER_INLINE, 'view_smime_key' => 1))) . '] [' . Horde::link('#', '', null, null, $this->_impsmime->savePublicKeyURL($this->getConfigParam('imp_contents')->getMailbox(), $this->getConfigParam('imp_contents')->getUid(), $sig_id) . ' return false;') . _("Save Certificate in your Address Book") . '</a>]';
+                    $status[] = '[' . $this->getConfigParam('imp_contents')->linkViewJS($this->_mimepart, 'view_attach', _("View Certificate"), array('params' => array('mode' => IMP_Contents::RENDER_INLINE, 'view_smime_key' => 1))) . '] [' . Horde::link('#', '', null, null, $this->_impsmime->savePublicKeyURL($this->getConfigParam('imp_contents')->getMailbox(), $this->getConfigParam('imp_contents')->getUid(), $base_id) . ' return false;') . _("Save Certificate in your Address Book") . '</a>]';
                 }
             } catch (Horde_Exception $e) {
                 self::$_cache[$base_id]['status'][0]['icon'] = Horde::img('alerts/error.png', _("Error"));
index 838b786..5ad54a1 100644 (file)
@@ -105,15 +105,21 @@ case 'save_attachment_public_key':
     $contents = $injector->getInstance('IMP_Injector_Factory_Contents')->create(new IMP_Indices($vars->mailbox, $vars->uid));
     $mime_part = $contents->getMIMEPart($vars->mime_id);
     if (empty($mime_part)) {
-        throw new IMP_Exception('Cannot retrieve public key from message.');
+        throw new IMP_Exception(_("Cannot retrieve public key from message."));
     }
 
     /* Add the public key to the storage system. */
     try {
-        $imp_smime->addPublicKey($mime_part);
+        $stream = $vars->mime_id
+            ? $contents->getBodyPart($vars->mime_id, array('mimeheaders' => true, 'stream' => true))
+            : $contents->fullMessageText();
+        $raw_text = $mime_part->replaceEOL($stream, Horde_Mime_Part::RFC_EOL);
+
+        $sig_result = $imp_smime->verifySignature($raw_text);
+        $imp_smime->addPublicKey($sig_result->cert);
         echo Horde::wrapInlineScript(array('window.close();'));
     } catch (Horde_Exception $e) {
-        $notification->push(_("No Certificate found"), 'horde.error');
+        throw new IMP_Exception(_("No certificate found."));
     }
     break;
 }