/**
  * Handler for message_compose_body hook
  * Display error when the message cannot be encrypted
  * and provide a way to try again with a password.
  */
 function message_compose($p)
 {
     $engine = $this->enigma->load_engine();
     // skip: message has no signed/encoded content
     if (!$this->enigma->engine) {
         return $p;
     }
     $engine = $this->enigma->engine;
     // Decryption status
     foreach ($engine->decryptions as $status) {
         if ($status instanceof enigma_error) {
             $code = $status->getCode();
             if ($code == enigma_error::KEYNOTFOUND) {
                 $msg = rcube::Q(str_replace('$keyid', enigma_key::format_id($status->getData('id')), $this->enigma->gettext('decryptnokey')));
             } else {
                 if ($code == enigma_error::BADPASS) {
                     $this->password_prompt($status, array('compose-init' => true));
                     return $p;
                 } else {
                     $msg = rcube::Q($this->enigma->gettext('decrypterror'));
                 }
             }
         }
     }
     if ($msg) {
         $this->rc->output->show_message($msg, 'error');
     }
     // Check sign/ecrypt options for signed/encrypted drafts
     $this->rc->output->set_env('enigma_force_encrypt', !empty($engine->decryptions));
     $this->rc->output->set_env('enigma_force_sign', !empty($engine->signatures));
     return $p;
 }
 /**
  * Getter for formatted fingerprint
  *
  * @return string Formatted fingerprint
  */
 function get_fingerprint()
 {
     return enigma_key::format_fingerprint($this->fingerprint);
 }
Beispiel #3
0
 /**
  * Handler for message_body_prefix hook.
  * Called for every displayed (content) part of the message.
  * Adds infobox about signature verification and/or decryption
  * status above the body.
  *
  * @param array Original parameters
  *
  * @return array Modified parameters
  */
 function status_message($p)
 {
     $part_id = $p['part']->mime_id;
     // skip: not a message part
     if ($p['part'] instanceof rcube_message) {
         return $p;
     }
     // skip: message has no signed/encoded content
     if (!$this->engine) {
         return $p;
     }
     // Decryption status
     if (isset($this->engine->decryptions[$part_id])) {
         // get decryption status
         $status = $this->engine->decryptions[$part_id];
         // Load UI and add css script
         $this->load_ui();
         $this->ui->add_css();
         // display status info
         $attrib['id'] = 'enigma-message';
         if ($status instanceof enigma_error) {
             $attrib['class'] = 'enigmaerror';
             $code = $status->getCode();
             if ($code == enigma_error::E_KEYNOTFOUND) {
                 $msg = rcube::Q(str_replace('$keyid', enigma_key::format_id($status->getData('id')), $this->gettext('decryptnokey')));
             } else {
                 if ($code == enigma_error::E_BADPASS) {
                     $msg = rcube::Q($this->gettext('decryptbadpass'));
                 } else {
                     $msg = rcube::Q($this->gettext('decrypterror'));
                 }
             }
         } else {
             $attrib['class'] = 'enigmanotice';
             $msg = rcube::Q($this->gettext('decryptok'));
         }
         $p['prefix'] .= html::div($attrib, $msg);
     }
     // Signature verification status
     if (isset($this->engine->signed_parts[$part_id]) && ($sig = $this->engine->signatures[$this->engine->signed_parts[$part_id]])) {
         // add css script
         $this->load_ui();
         $this->ui->add_css();
         // display status info
         $attrib['id'] = 'enigma-message';
         if ($sig instanceof enigma_signature) {
             if ($sig->valid) {
                 $attrib['class'] = 'enigmanotice';
                 $sender = ($sig->name ? $sig->name . ' ' : '') . '<' . $sig->email . '>';
                 $msg = rcube::Q(str_replace('$sender', $sender, $this->gettext('sigvalid')));
             } else {
                 $attrib['class'] = 'enigmawarning';
                 $sender = ($sig->name ? $sig->name . ' ' : '') . '<' . $sig->email . '>';
                 $msg = rcube::Q(str_replace('$sender', $sender, $this->gettext('siginvalid')));
             }
         } else {
             if ($sig->getCode() == enigma_error::E_KEYNOTFOUND) {
                 $attrib['class'] = 'enigmawarning';
                 $msg = rcube::Q(str_replace('$keyid', enigma_key::format_id($sig->getData('id')), $this->gettext('signokey')));
             } else {
                 $attrib['class'] = 'enigmaerror';
                 $msg = rcube::Q($this->gettext('sigerror'));
             }
         }
         /*
                     $msg .= '&nbsp;' . html::a(array('href' => "#sigdetails",
                         'onclick' => rcmail_output::JS_OBJECT_NAME.".command('enigma-sig-details')"),
                         rcube::Q($this->gettext('showdetails')));
         */
         // test
         //            $msg .= '<br /><pre>'.$sig->body.'</pre>';
         $p['prefix'] .= html::div($attrib, $msg);
         // Display each signature message only once
         unset($this->engine->signatures[$this->engine->signed_parts[$part_id]]);
     }
     return $p;
 }
Beispiel #4
0
 /**
  * Handler for attaching public key to a message
  *
  * @param Mail_mime Original message
  *
  * @return bool True on success, False on failure
  */
 function attach_public_key(&$message)
 {
     $headers = $message->headers();
     $from = rcube_mime::decode_address_list($headers['From'], 1, false, null, true);
     $from = $from[1];
     // find my key
     if ($from && ($key = $this->find_key($from))) {
         $pubkey_armor = $this->export_key($key->id);
         if (!$pubkey_armor instanceof enigma_error) {
             $pubkey_name = '0x' . enigma_key::format_id($key->id) . '.asc';
             $message->addAttachment($pubkey_armor, 'application/pgp-keys', $pubkey_name, false, '7bit');
             return true;
         }
     }
     return false;
 }