| | |
| | | |
| | | public $decryptions = array(); |
| | | public $signatures = array(); |
| | | public $signed_parts = array(); |
| | | public $encrypted_parts = array(); |
| | | |
| | | const SIGN_MODE_BODY = 1; |
| | |
| | | // in this mode we'll replace text part |
| | | // with the one containing signature |
| | | $body = $message->getTXTBody(); |
| | | |
| | | $text_charset = $message->getParam('text_charset'); |
| | | $line_length = $this->rc->config->get('line_length', 72); |
| | | |
| | | // We can't use format=flowed for signed messages |
| | | if (strpos($text_charset, 'format=flowed')) { |
| | | list($charset, $params) = explode(';', $text_charset); |
| | | $body = rcube_mime::unfold_flowed($body); |
| | | $body = rcube_mime::wordwrap($body, $line_length, "\r\n", false, $charset); |
| | | |
| | | $text_charset = str_replace(";\r\n format=flowed", '', $text_charset); |
| | | } |
| | | } |
| | | else { |
| | | // here we'll build PGP/MIME message |
| | |
| | | if ($result !== true) { |
| | | if ($result->getCode() == enigma_error::BADPASS) { |
| | | // ask for password |
| | | $error = array('missing' => array($key->id => $key->name)); |
| | | $error = array('bad' => array($key->id => $key->name)); |
| | | return new enigma_error(enigma_error::BADPASS, '', $error); |
| | | } |
| | | |
| | |
| | | // replace message body |
| | | if ($pgp_mode == Crypt_GPG::SIGN_MODE_CLEAR) { |
| | | $message->setTXTBody($body); |
| | | $message->setParam('text_charset', $text_charset); |
| | | } |
| | | else { |
| | | $mime->addPGPSignature($body); |
| | |
| | | // including a set of appropriate content headers describing the data. |
| | | // The second body MUST contain the PGP digital signature. It MUST be |
| | | // labeled with a content type of "application/pgp-signature". |
| | | else if ($struct->ctype_parameters['protocol'] == 'application/pgp-signature' |
| | | && count($struct->parts) == 2 |
| | | else if (count($struct->parts) == 2 |
| | | && $struct->parts[1] && $struct->parts[1]->mimetype == 'application/pgp-signature' |
| | | ) { |
| | | $this->parse_pgp_signed($p, $body); |
| | |
| | | $struct = $p['structure']; |
| | | |
| | | // S/MIME |
| | | if ($struct->mimetype == 'application/pkcs7-mime') { |
| | | if ($p['mimetype'] == 'application/pkcs7-mime') { |
| | | $this->parse_smime_encrypted($p); |
| | | } |
| | | // PGP/MIME: RFC3156 |
| | |
| | | // This body contains the control information. |
| | | // The second MIME body part MUST contain the actual encrypted data. It |
| | | // must be labeled with a content type of "application/octet-stream". |
| | | else if ($struct->ctype_parameters['protocol'] == 'application/pgp-encrypted' |
| | | && count($struct->parts) == 2 |
| | | else if (count($struct->parts) == 2 |
| | | && $struct->parts[0] && $struct->parts[0]->mimetype == 'application/pgp-encrypted' |
| | | && $struct->parts[1] && $struct->parts[1]->mimetype == 'application/octet-stream' |
| | | ) { |
| | |
| | | |
| | | // Store signature data for display |
| | | if (!empty($sig)) { |
| | | $this->signed_parts[$part->mime_id] = $part->mime_id; |
| | | $this->signatures[$part->mime_id] = $sig; |
| | | $this->signatures[$part->mime_id] = $sig; |
| | | } |
| | | |
| | | fclose($fh); |
| | |
| | | |
| | | // Store signature data for display |
| | | $this->signatures[$struct->mime_id] = $sig; |
| | | |
| | | // Message can be multipart (assign signature to each subpart) |
| | | if (!empty($msg_part->parts)) { |
| | | foreach ($msg_part->parts as $part) |
| | | $this->signed_parts[$part->mime_id] = $struct->mime_id; |
| | | } |
| | | else { |
| | | $this->signed_parts[$msg_part->mime_id] = $struct->mime_id; |
| | | } |
| | | $this->signatures[$msg_part->mime_id] = $sig; |
| | | } |
| | | |
| | | /** |
| | |
| | | $struct = $this->parse_body($body); |
| | | |
| | | // Modify original message structure |
| | | $this->modify_structure($p, $struct); |
| | | $this->modify_structure($p, $struct, strlen($body)); |
| | | |
| | | // Parse the structure (there may be encrypted/signed parts inside |
| | | $this->part_structure(array( |
| | |
| | | /** |
| | | * Replace message encrypted structure with decrypted message structure |
| | | * |
| | | * @param array |
| | | * @param rcube_message_part |
| | | * @param array Hook arguments |
| | | * @param rcube_message_part Part structure |
| | | * @param int Part size |
| | | */ |
| | | private function modify_structure(&$p, $struct) |
| | | private function modify_structure(&$p, $struct, $size = 0) |
| | | { |
| | | // modify mime_parts property of the message object |
| | | $old_id = $p['structure']->mime_id; |
| | |
| | | unset($p['object']->mime_parts[$idx]); |
| | | } |
| | | } |
| | | |
| | | // set some part params used by Roundcube core |
| | | $struct->headers = array_merge($p['structure']->headers, $struct->headers); |
| | | $struct->size = $size; |
| | | $struct->filename = $p['structure']->filename; |
| | | |
| | | // modify the new structure to be correctly handled by Roundcube |
| | | $this->modify_structure_part($struct, $p['object'], $old_id); |
| | |
| | | |
| | | // Cache the fact it was decrypted |
| | | $this->encrypted_parts[] = $part->mime_id; |
| | | |
| | | $msg->mime_parts[$part->mime_id] = $part; |
| | | |
| | | // modify sub-parts |