From ba9857f21277a77d8f243638bd433a33ae4b2255 Mon Sep 17 00:00:00 2001 From: Michael M Slusarz Date: Mon, 9 Nov 2009 15:23:34 -0700 Subject: [PATCH] Output a more correct representation of signature data when viewing sig part of an armored text message --- imp/lib/Mime/Viewer/Pgp.php | 51 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/imp/lib/Mime/Viewer/Pgp.php b/imp/lib/Mime/Viewer/Pgp.php index 4a8f6d9ad..8c2fd99c7 100644 --- a/imp/lib/Mime/Viewer/Pgp.php +++ b/imp/lib/Mime/Viewer/Pgp.php @@ -33,6 +33,9 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Driver 'full' => false, 'info' => false, 'inline' => true, + /* This driver *does* render raw data, but only for + * application/pgp-signature parts that have been processed by the + * text/plain driver. This is handled via the canRender() function. */ 'raw' => false ); @@ -58,6 +61,38 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Driver static protected $_inlinecache = array(); /** + * Return the full rendered version of the Horde_Mime_Part object. + * + * @return array See Horde_Mime_Viewer_Driver::render(). + */ + protected function _renderRaw() + { + $id = $this->_mimepart->getMimeId(); + + $ret = array( + $id => array( + 'data' => '', + 'status' => array(), + 'type' => 'text/plain; charset=' . Horde_Nls::getCharset() + ) + ); + + if (empty($this->_imppgp)) { + $this->_imppgp = Horde_Crypt::singleton(array('IMP', 'Pgp')); + } + + $parts = $this->_imppgp->parsePGPData($this->_mimepart->getContents()); + foreach (array_keys($parts) as $key) { + if ($parts[$key]['type'] == Horde_Crypt_Pgp::ARMOR_SIGNATURE) { + $ret[$id]['data'] = implode("\r\n", $parts[$key]['data']); + break; + } + } + + return $ret; + } + + /** * Return the rendered inline version of the Horde_Mime_Part object. * * @return array See Horde_Mime_Viewer_Driver::render(). @@ -408,4 +443,20 @@ class IMP_Horde_Mime_Viewer_Pgp extends Horde_Mime_Viewer_Driver return $this->_imppgp->getSymmetricID($this->_params['contents']->getMailbox(), $this->_params['contents']->getUid(), $this->_mimepart->getMimeId()); } + /** + * Can this driver render the the data? + * + * @param string $mode See Horde_Mime_Viewer_Driver::canRender(). + * + * @return boolean See Horde_Mime_Viewer_Driver::canRender(). + */ + public function canRender($mode) + { + return (($mode == 'raw') && + ($this->_mimepart->getType() == 'application/pgp-signature') && + $this->_mimepart->getContentTypeParameter('x-imp-pgp-signature')) + ? true + : parent::canRender($mode); + } + } -- 2.11.0