protected function _encryptMessage(Horde_Mime_Part $msg, $encrypt, Horde_Mail_Rfc822_List $recip, Horde_Mail_Rfc822_Address $from)
{
global $injector;
/* Add personal address to encrypted message. */
switch ($encrypt) {
case IMP_Pgp::ENCRYPT:
case IMP_Pgp::SIGNENC:
case IMP_Pgp::SYM_ENCRYPT:
case IMP_Pgp::SYM_SIGNENC:
case IMP_Smime::ENCRYPT:
case IMP_Smime::SIGNENC:
$recip2 = clone $recip;
$recip2->add($from);
break;
}
switch ($encrypt) {
case IMP_Pgp::ENCRYPT:
case IMP_Pgp::SIGN:
case IMP_Pgp::SIGNENC:
case IMP_Pgp::SYM_ENCRYPT:
case IMP_Pgp::SYM_SIGNENC:
if (!IMP_Pgp::enabled()) {
break;
}
$imp_pgp = $injector->getInstance('IMP_Pgp');
switch ($encrypt) {
case IMP_Pgp::SIGN:
case IMP_Pgp::SIGNENC:
case IMP_Pgp::SYM_SIGNENC:
/* Check to see if we have the user's passphrase yet. */
$passphrase = $imp_pgp->getPassphrase('personal');
if (empty($passphrase)) {
$e = new IMP_Compose_Exception(_("PGP: Need passphrase for personal private key."));
$e->encrypt = 'pgp_passphrase_dialog';
throw $e;
}
break;
case IMP_Pgp::SYM_ENCRYPT:
case IMP_Pgp::SYM_SIGNENC:
/* Check to see if we have the user's symmetric passphrase
* yet. */
$symmetric_passphrase = $imp_pgp->getPassphrase('symmetric', 'imp_compose_' . $this->_cacheid);
if (empty($symmetric_passphrase)) {
$e = new IMP_Compose_Exception(_("PGP: Need passphrase to encrypt your message with."));
$e->encrypt = 'pgp_symmetric_passphrase_dialog';
throw $e;
}
break;
}
/* Do the encryption/signing requested. */
try {
switch ($encrypt) {
case IMP_Pgp::SIGN:
$msg2 = $imp_pgp->signMimePart($msg);
$this->_setMetadata('encrypt_sign', true);
return $msg2;
case IMP_Pgp::ENCRYPT:
case IMP_Pgp::SYM_ENCRYPT:
return $imp_pgp->encryptMimePart($msg, $recip2, $encrypt == IMP_Pgp::SYM_ENCRYPT ? $symmetric_passphrase : null);
case IMP_Pgp::SIGNENC:
case IMP_Pgp::SYM_SIGNENC:
return $imp_pgp->signAndEncryptMimePart($msg, $recip2, $encrypt == IMP_Pgp::SYM_SIGNENC ? $symmetric_passphrase : null);
break;
}
} catch (Horde_Exception $e) {
throw new IMP_Compose_Exception(_("PGP Error: ") . $e->getMessage(), $e->getCode());
}
break;
case IMP_Smime::ENCRYPT:
case IMP_Smime::SIGN:
case IMP_Smime::SIGNENC:
if (!IMP_Smime::enabled()) {
break;
}
$imp_smime = $injector->getInstance('IMP_Smime');
/* Check to see if we have the user's passphrase yet. */
switch ($encrypt) {
case IMP_Smime::SIGN:
case IMP_Smime::SIGNENC:
$passphrase_required = $imp_smime->getPassphrase(IMP_Smime::KEY_SECONDARY_OR_PRIMARY) === false;
if ($encrypt == IMP_Smime::SIGNENC) {
$passphrase_required |= $imp_smime->getPassphrase(IMP_Smime::KEY_PRIMARY) === false;
}
if ($passphrase_required) {
$e = new IMP_Compose_Exception(_("S/MIME Error: Need passphrase for personal private key."));
$e->encrypt = 'smime_passphrase_dialog';
throw $e;
}
break;
}
/* Do the encryption/signing requested. */
try {
switch ($encrypt) {
case IMP_Smime::SIGN:
$msg2 = $imp_smime->signMimePart($msg);
$this->_setMetadata('encrypt_sign', true);
return $msg2;
case IMP_Smime::ENCRYPT:
return $imp_smime->encryptMimePart($msg, $recip2);
case IMP_Smime::SIGNENC:
return $imp_smime->signAndEncryptMimePart($msg, $recip2);
}
} catch (Horde_Exception $e) {
throw new IMP_Compose_Exception(_("S/MIME Error: ") . $e->getMessage(), $e->getCode());
}
break;
}
return $msg;
}