Skip to content

Commit

Permalink
Bug: 12970 Differentiate between signed and encrypted messages.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrubinsk committed Oct 24, 2014
1 parent 5d41077 commit 5a29cb2
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 15 deletions.
6 changes: 4 additions & 2 deletions framework/ActiveSync/lib/Horde/ActiveSync/Imap/Adapter.php
Expand Up @@ -997,7 +997,7 @@ protected function _buildMailMessage(
// email is signed (or encrypted for that matter) we can't
// alter the data in anyway or the signature will not be
// verified, so we fetch the entire message and hope for the best.
if (!$imap_message->isSigned()) {
if (!$imap_message->isSigned() && !$imap_message->isEncrypted()) {
// Sending a non-signed MIME message, start building the
// UTF-8 converted structure.
$mime = new Horde_Mime_Part();
Expand Down Expand Up @@ -1046,7 +1046,9 @@ protected function _buildMailMessage(
$raw = new Horde_ActiveSync_Rfc822($imap_message->getFullMsg(true), false);
$airsync_body->estimateddatasize = $raw->getBytes();
$airsync_body->data = $raw->getString();
$eas_message->messageclass = 'IPM.Note.SMIME.MultipartSigned';
$eas_message->messageclass = $imap_message->isSigned()
? 'IPM.Note.SMIME.MultipartSigned'
: 'IPM.Note.SMIME';

// Might not know if we have attachments, but take a best
// guess.
Expand Down
26 changes: 22 additions & 4 deletions framework/ActiveSync/lib/Horde/ActiveSync/Imap/Message.php
Expand Up @@ -839,13 +839,12 @@ public function hasAttachments()
}

/**
* Return the S/MIME status of this message (RFC2633)
* Return the S/MIME signature status of this message (RFC2633)
*
* @param Horde_Mime_Part $message A mime part to check. If omitted, use
* $this->_message.
* self::$_message.
*
* @return boolean True if message is S/MIME signed or encrypted,
* false otherwise.
* @return boolean True if message is S/MIME signed, false otherwise.
*/
public function isSigned(Horde_Mime_Part $message = null)
{
Expand All @@ -857,4 +856,23 @@ public function isSigned(Horde_Mime_Part $message = null)
return $this->_message->isSigned();
}

/**
* Return the S/MIME encryption status of this message (RFC2633)
*
* @param Horde_Mime_Part $message A mime part to check. If omitted, use
* self::$_message.
*
* @return boolean True if message is S/MIME signed or encrypted,
* false otherwise.
*/
public function isEncrypted(Horde_Mime_Part $message = null)
{
if (!empty($message)) {
$message = new Horde_ActiveSync_Mime($message);
return $message->isEncrypted();
}

return $this->_message->isEncrypted();
}

}
41 changes: 32 additions & 9 deletions framework/ActiveSync/lib/Horde/ActiveSync/Mime.php
Expand Up @@ -28,7 +28,6 @@
*/
class Horde_ActiveSync_Mime
{

/**
* The composited mime part.
*
Expand All @@ -43,7 +42,6 @@ class Horde_ActiveSync_Mime
*/
protected $_hasAttachments;


/**
* Cont'r
*
Expand Down Expand Up @@ -174,20 +172,16 @@ public function hasiCalendar()
/**
* Return the S/MIME status of this message (RFC2633)
*
* @return boolean True if message is S/MIME signed or encrypted,
* false otherwise.
* @param Horde_Mime_Part The part to test. If omitted, uses self::$_base
*
* @return boolean True if message is S/MIME signed, otherwise false.
*/
public function isSigned(Horde_Mime_Part $mime = null)
{
if (empty($mime)) {
$mime = $this->_base;
}

if ($mime->getType() == 'application/pkcs7-mime' ||
$mime->getType() == 'application/x-pkcs7-mime') {
return true;
}

if ($mime->getPrimaryType() == 'multipart') {
if ($mime->getSubType() == 'signed') {
return true;
Expand All @@ -204,4 +198,33 @@ public function isSigned(Horde_Mime_Part $mime = null)
return false;
}

/**
* Return the S/MIME encryption status of this message.
*
* @param Horde_Mime_Part The part to test. If omitted, uses self::$_base
*
* @return boolean True if message is S/MIME encrypted, otherwise false.
* @since 2.20.0
* @todo For 3.0, combine into one method with self::isSigned() and return
* a bitmask result.
*/
public function isEncrypted(Horde_Mime_Part $mime = null)
{
if (empty($mime)) {
$mime = $this->_base;
}

if ($mime->getType() == 'application/pkcs7-mime' ||
$mime->getType() == 'application/x-pkcs7-mime') {
return true;
}

// Signed/encrypted part might be lower in the mime structure
foreach ($mime->getParts() as $part) {
if ($this->isEncrypted($part)) {
return true;
}
}
}

}

0 comments on commit 5a29cb2

Please sign in to comment.