* @param array $opts An array of options w/the following keys:
* <pre>
* encrypt - (integer) A flag whether to encrypt or sign the message.
- * One of IMP::PGP_ENCRYPT, IMP::PGP_SIGNENC,
- * IMP::SMIME_ENCRYPT, or IMP::SMIME_SIGNENC.
+ * One of IMP_Crypt_Pgp::ENCRYPT, IMP_Crypt_Pgp::SIGNENC,
+ * IMP_Crypt_Smime::ENCRYPT, or IMP_Crypt_Smime::SIGNENC.
* html - (boolean) Whether this is an HTML message.
* DEFAULT: false
* identity - (IMP_Prefs_Identity) If set, checks for proper tie-to
/* Must encrypt & send the message one recipient at a time. */
if ($prefs->getValue('use_smime') &&
- in_array($encrypt, array(IMP::SMIME_ENCRYPT, IMP::SMIME_SIGNENC))) {
+ in_array($encrypt, array(IMP_Crypt_Smime::ENCRYPT, IMP_Crypt_Smime::SIGNENC))) {
foreach ($recip['list'] as $val) {
$send_msgs[] = $this->_createMimeMessage(array($val), $body, $msg_options);
}
$encrypt = empty($options['encrypt']) ? 0 : $options['encrypt'];
if ($GLOBALS['prefs']->getValue('use_pgp') &&
!empty($GLOBALS['conf']['gnupg']['path']) &&
- in_array($encrypt, array(IMP::PGP_ENCRYPT, IMP::PGP_SIGN, IMP::PGP_SIGNENC, IMP::PGP_SYM_ENCRYPT, IMP::PGP_SYM_SIGNENC))) {
+ in_array($encrypt, array(IMP_Crypt_Pgp::ENCRYPT, IMP_Crypt_Pgp::SIGN, IMP_Crypt_Pgp::SIGNENC, IMP_Crypt_Pgp::SYM_ENCRYPT, IMP_Crypt_Pgp::SYM_SIGNENC))) {
$imp_pgp = $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp');
$symmetric_passphrase = null;
switch ($encrypt) {
- case IMP::PGP_SIGN:
- case IMP::PGP_SIGNENC:
- case IMP::PGP_SYM_SIGNENC:
+ case IMP_Crypt_Pgp::SIGN:
+ case IMP_Crypt_Pgp::SIGNENC:
+ case IMP_Crypt_Pgp::SYM_SIGNENC:
/* Check to see if we have the user's passphrase yet. */
$passphrase = $imp_pgp->getPassphrase('personal');
if (empty($passphrase)) {
}
break;
- case IMP::PGP_SYM_ENCRYPT:
- case IMP::PGP_SYM_SIGNENC:
+ case IMP_Crypt_Pgp::SYM_ENCRYPT:
+ case IMP_Crypt_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);
/* Do the encryption/signing requested. */
try {
switch ($encrypt) {
- case IMP::PGP_SIGN:
+ case IMP_Crypt_Pgp::SIGN:
$base = $imp_pgp->IMPsignMIMEPart($base);
break;
- case IMP::PGP_ENCRYPT:
- case IMP::PGP_SYM_ENCRYPT:
+ case IMP_Crypt_Pgp::ENCRYPT:
+ case IMP_Crypt_Pgp::SYM_ENCRYPT:
$to_list = empty($options['from'])
? $to
: array_keys(array_flip(array_merge($to, array($options['from']))));
- $base = $imp_pgp->IMPencryptMIMEPart($base, $to_list, ($encrypt == IMP::PGP_SYM_ENCRYPT) ? $symmetric_passphrase : null);
+ $base = $imp_pgp->IMPencryptMIMEPart($base, $to_list, ($encrypt == IMP_Crypt_Pgp::SYM_ENCRYPT) ? $symmetric_passphrase : null);
break;
- case IMP::PGP_SIGNENC:
- case IMP::PGP_SYM_SIGNENC:
+ case IMP_Crypt_Pgp::SIGNENC:
+ case IMP_Crypt_Pgp::SYM_SIGNENC:
$to_list = empty($options['from'])
? $to
: array_keys(array_flip(array_merge($to, array($options['from']))));
- $base = $imp_pgp->IMPsignAndEncryptMIMEPart($base, $to_list, ($encrypt == IMP::PGP_SYM_SIGNENC) ? $symmetric_passphrase : null);
+ $base = $imp_pgp->IMPsignAndEncryptMIMEPart($base, $to_list, ($encrypt == IMP_Crypt_Pgp::SYM_SIGNENC) ? $symmetric_passphrase : null);
break;
}
} catch (Horde_Exception $e) {
throw new IMP_Compose_Exception(_("PGP Error: ") . $e->getMessage(), $e->getCode());
}
} elseif ($GLOBALS['prefs']->getValue('use_smime') &&
- in_array($encrypt, array(IMP::SMIME_ENCRYPT, IMP::SMIME_SIGN, IMP::SMIME_SIGNENC))) {
+ in_array($encrypt, array(IMP_Crypt_Smime::ENCRYPT, IMP_Crypt_Smime::SIGN, IMP_Crypt_Smime::SIGNENC))) {
$imp_smime = $GLOBALS['injector']->getInstance('IMP_Crypt_Smime');
/* Check to see if we have the user's passphrase yet. */
- if (in_array($encrypt, array(IMP::SMIME_SIGN, IMP::SMIME_SIGNENC))) {
+ if (in_array($encrypt, array(IMP_Crypt_Smime::SIGN, IMP_Crypt_Smime::SIGNENC))) {
$passphrase = $imp_smime->getPassphrase();
if ($passphrase === false) {
$e = new IMP_Compose_Exception(_("S/MIME Error: Need passphrase for personal private key."));
/* Do the encryption/signing requested. */
try {
switch ($encrypt) {
- case IMP::SMIME_SIGN:
+ case IMP_Crypt_Smime::SIGN:
$base = $imp_smime->IMPsignMIMEPart($base);
break;
- case IMP::SMIME_ENCRYPT:
+ case IMP_Crypt_Smime::ENCRYPT:
$base = $imp_smime->IMPencryptMIMEPart($base, $to[0]);
break;
- case IMP::SMIME_SIGNENC:
+ case IMP_Crypt_Smime::SIGNENC:
$base = $imp_smime->IMPsignAndEncryptMIMEPart($base, $to[0]);
break;
}
/* Name of PGP public key field in addressbook. */
const PUBKEY_FIELD = 'pgpPublicKey';
+ /* Encryption type constants. */
+ const ENCRYPT = 'pgp_encrypt';
+ const SIGN = 'pgp_sign';
+ const SIGNENC = 'pgp_signenc';
+ const SYM_ENCRYPT = 'pgp_sym_enc';
+ const SYM_SIGNENC = 'pgp_syn_sign';
+
+ /**
+ * Return the list of available encryption options for composing.
+ *
+ * @return array Keys are encryption type constants, values are gettext
+ * strings describing the encryption type.
+ */
+ public function encryptList()
+ {
+ $ret = array(
+ self::ENCRYPT => _("PGP Encrypt Message")
+ );
+
+ if ($this->getPersonalPrivateKey()) {
+ $ret += array(
+ self::SIGN => _("PGP Sign Message"),
+ self::SIGNENC => _("PGP Sign/Encrypt Message")
+ );
+ }
+
+ return $ret + array(
+ self::SYM_ENCRYPT => _("PGP Encrypt Message with passphrase"),
+ self::SYM_SIGNENC => _("PGP Sign/Encrypt Message with passphrase")
+ );
+ }
+
/**
* Generate the personal Public/Private keypair and store in prefs.
*
class IMP
{
/* Encrypt constants. */
- const ENCRYPT_NONE = 1;
- const PGP_ENCRYPT = 2;
- const PGP_SIGN = 3;
- const PGP_SIGNENC = 4;
- const SMIME_ENCRYPT = 5;
- const SMIME_SIGN = 6;
- const SMIME_SIGNENC = 7;
- const PGP_SYM_ENCRYPT = 8;
- const PGP_SYM_SIGNENC = 9;
+ const ENCRYPT_NONE = 'encrypt_none';
/* IMP Mailbox view constants. */
const MAILBOX_START_FIRSTUNSEEN = 1;
if (!empty($GLOBALS['conf']['gnupg']['path']) &&
$GLOBALS['prefs']->getValue('use_pgp')) {
- $enc_opts += array(
- self::PGP_ENCRYPT => _("PGP Encrypt Message"),
- self::PGP_SIGN => _("PGP Sign Message"),
- self::PGP_SIGNENC => _("PGP Sign/Encrypt Message"),
- self::PGP_SYM_ENCRYPT => _("PGP Encrypt Message with passphrase"),
- self::PGP_SYM_SIGNENC => _("PGP Sign/Encrypt Message with passphrase")
- );
+ $enc_opts += $GLOBALS['injector']->getInstance('IMP_Crypt_Pgp')->encryptList();
}
+
if ($GLOBALS['prefs']->getValue('use_smime')) {
- $enc_opts += array(
- self::SMIME_ENCRYPT => _("S/MIME Encrypt Message"),
- self::SMIME_SIGN => _("S/MIME Sign Message"),
- self::SMIME_SIGNENC => _("S/MIME Sign/Encrypt Message")
- );
+ $enc_opts += $GLOBALS['injector']->getInstance('IMP_Crypt_Smime')->encryptList();
}
if ($returnList) {