/**
* Parse enveloped (encrypted) data.
*
* @return mixed See self::_getEmbeddedMimeParts().
*/
protected function _parseEnvelopedData()
{
$base_id = $this->_mimepart->getMimeId();
/* Initialize inline data. */
$status = new IMP_Mime_Status($this->_mimepart, _("The data in this part has been encrypted via S/MIME."));
$status->icon('mime/encryption.png', 'S/MIME');
$cache = $this->getConfigParam('imp_contents')->getViewCache();
$cache->smime[$base_id] = array('status' => $status, 'wrap' => '');
/* Is PGP active? */
$this->_initSmime();
if (empty($this->_impsmime)) {
$status->addText(_("S/MIME support is not currently enabled so the data is unable to be decrypted."));
return null;
}
if (!$this->_impsmime->getPersonalPrivateKey()) {
$status->addText(_("No personal private key exists so the data is unable to be decrypted."));
return null;
}
/* Make sure we have a passphrase. */
$passphrase = $this->_impsmime->getPassphrase();
if ($passphrase === false) {
$imple = $GLOBALS['injector']->getInstance('Horde_Core_Factory_Imple')->create('IMP_Ajax_Imple_PassphraseDialog', array('type' => 'smimePersonal'));
$status->addText(Horde::link('#', '', '', '', '', '', '', array('id' => $imple->getDomId())) . _("You must enter the passphrase for your S/MIME private key to view this data.") . '</a>');
return null;
}
$raw_text = $this->_getPartStream($this->_mimepart->getMimeId());
try {
$decrypted_data = $this->_impsmime->decryptMessage($this->_mimepart->replaceEOL($raw_text, Horde_Mime_Part::RFC_EOL));
} catch (Horde_Exception $e) {
$status->addText($e->getMessage());
return null;
}
$cache->smime[$base_id]['wrap'] = 'mimePartWrapValid';
$new_part = Horde_Mime_Part::parseMessage($decrypted_data, array('forcemime' => true));
switch ($new_part->getType()) {
case 'application/pkcs7-mime':
case 'application/x-pkcs7-mime':
$signed_data = $this->_getSmimeType($new_part) === 'signed-data';
break;
case 'multipart/signed':
$signed_data = true;
break;
default:
$signed_data = false;
break;
}
if ($signed_data) {
$hdrs = $this->getConfigParam('imp_contents')->getHeader();
$data = new Horde_Stream_Temp();
$data->add('From:' . $hdrs['From'] . "\n" . $decrypted_data);
$new_part->setMetadata('imp-smime-decrypt', $data);
$new_part->setContents($decrypted_data, array('encoding' => 'binary'));
}
return $new_part;
}