Find this useful? Enter your email to receive occasional updates for securing PHP code.
Signing you up...
Thank you for signing up!
PHP Decode
<?php namespace Roundcube\Plugins\Tests; use PHPUnit\Framework\TestCase; class EnigmaMi..
Decoded Output download
<?php
namespace Roundcube\Plugins\Tests;
use PHPUnit\Framework\TestCase;
class EnigmaMimeMessageTest extends TestCase
{
/**
* Test isMultipart()
*/
public function test_is_multipart()
{
$mime = new \Mail_mime();
$message1 = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$this->assertFalse($message1->isMultipart());
$mime->setHTMLBody('<html></html>');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$this->assertTrue($message->isMultipart());
$message = new \enigma_mime_message($message1, \enigma_mime_message::PGP_SIGNED);
$this->assertTrue($message->isMultipart());
}
/**
* Test getFromAddress()
*/
public function test_get_from_address()
{
$mime = new \Mail_mime();
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$this->assertNull($message->getFromAddress());
$mime->setFrom('[email protected]');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$this->assertSame('[email protected]', $message->getFromAddress());
}
/**
* Test getRecipients()
*/
public function test_get_recipients()
{
$mime = new \Mail_mime();
$mime->setFrom('[email protected]');
$mime->addTo('<[email protected]>, undisclosed-recipients:');
$mime->addCc('<[email protected]>');
$mime->addBcc('[email protected]');
$expected = ['[email protected]', '[email protected]', '[email protected]'];
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$this->assertSame($expected, $message->getRecipients());
}
/**
* Test getOrigBody()
*/
public function test_get_orig_body()
{
$mime = new \Mail_mime();
$mime->setTXTBody('test body');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$expected = "Content-Transfer-Encoding: quoted-printable
"
. "Content-Type: text/plain; charset=ISO-8859-1
"
. "
"
. "test body
";
$this->assertSame($expected, $message->getOrigBody());
}
/**
* Test get()
*/
public function test_get()
{
$mime = new \Mail_mime();
$mime->setTXTBody('test body');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$expected = "This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
"
. "
"
. "--=_%x
"
. "Content-Transfer-Encoding: quoted-printable
"
. "Content-Type: text/plain; charset=ISO-8859-1
"
. "
"
. "test body
"
. "
"
. "--=_%x--
";
$signed_headers = "MIME-Version: 1.0
"
. "Content-Type: multipart/signed;
"
. " protocol=\"application/pgp-signature\";
"
. " boundary=\"=_%x\"
";
// Note: The str_replace() below is for phpunit <= 6.5
$this->assertStringMatchesFormat(
str_replace("
", "
", $expected),
str_replace("
", "
", $message->get())
);
$this->assertStringMatchesFormat(
str_replace("
", "
", $signed_headers),
str_replace("
", "
", $message->txtHeaders())
);
$mime = new \Mail_mime();
$mime->setTXTBody('test body');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$message->addPGPSignature('signature', 'algorithm');
$signed = "This is an OpenPGP/MIME signed message (RFC 4880 and 3156)
"
. "
"
. "--=_%x
"
. "Content-Transfer-Encoding: quoted-printable
"
. "Content-Type: text/plain; charset=ISO-8859-1
"
. "
"
. "test body
"
. "
"
. "--=_%x
"
. "Content-Type: application/pgp-signature;
"
. " name=signature.asc
"
. "Content-Disposition: attachment;
"
. " filename=signature.asc;
"
. " size=9
"
. "Content-Description: OpenPGP digital signature
"
. "
"
. "signature
"
. "--=_%x--
";
$signed_headers = "MIME-Version: 1.0
"
. "Content-Type: multipart/signed;
"
. " protocol=\"application/pgp-signature\";
"
. " boundary=\"=_%x\";
"
. " micalg=pgp-algorithm
";
// Note: The str_replace() below is for phpunit <= 6.5
$this->assertStringMatchesFormat(
str_replace("
", "
", $signed),
str_replace("
", "
", $message->get())
);
$this->assertStringMatchesFormat(
str_replace("
", "
", $signed_headers),
str_replace("
", "
", $message->txtHeaders())
);
$mime = new \Mail_mime();
$mime->setTXTBody('test body');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_ENCRYPTED);
$message->setPGPEncryptedBody('encrypted body');
$encrypted = "This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)
"
. "
"
. "--=_%x
"
. "Content-Type: application/pgp-encrypted
"
. "Content-Description: PGP/MIME version identification
"
. "
"
. "Version: 1
"
. "--=_%x
"
. "Content-Type: application/octet-stream;
"
. " name=encrypted.asc
"
. "Content-Disposition: inline;
"
. " filename=encrypted.asc;
"
. " size=14
"
. "Content-Description: PGP/MIME encrypted message
"
. "
"
. "encrypted body
"
. "--=_%x--
";
$encrypted_headers = "MIME-Version: 1.0
"
. "Content-Type: multipart/encrypted;
"
. " protocol=\"application/pgp-encrypted\";
"
. " boundary=\"=_%x\"
";
// Note: The str_replace() below is for phpunit <= 6.5
$this->assertStringMatchesFormat(
str_replace("
", "
", $encrypted),
str_replace("
", "
", $message->get())
);
$this->assertStringMatchesFormat(
str_replace("
", "
", $encrypted_headers),
str_replace("
", "
", $message->txtHeaders())
);
}
}
?>
Did this file decode correctly?
Original Code
<?php
namespace Roundcube\Plugins\Tests;
use PHPUnit\Framework\TestCase;
class EnigmaMimeMessageTest extends TestCase
{
/**
* Test isMultipart()
*/
public function test_is_multipart()
{
$mime = new \Mail_mime();
$message1 = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$this->assertFalse($message1->isMultipart());
$mime->setHTMLBody('<html></html>');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$this->assertTrue($message->isMultipart());
$message = new \enigma_mime_message($message1, \enigma_mime_message::PGP_SIGNED);
$this->assertTrue($message->isMultipart());
}
/**
* Test getFromAddress()
*/
public function test_get_from_address()
{
$mime = new \Mail_mime();
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$this->assertNull($message->getFromAddress());
$mime->setFrom('[email protected]');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$this->assertSame('[email protected]', $message->getFromAddress());
}
/**
* Test getRecipients()
*/
public function test_get_recipients()
{
$mime = new \Mail_mime();
$mime->setFrom('[email protected]');
$mime->addTo('<[email protected]>, undisclosed-recipients:');
$mime->addCc('<[email protected]>');
$mime->addBcc('[email protected]');
$expected = ['[email protected]', '[email protected]', '[email protected]'];
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$this->assertSame($expected, $message->getRecipients());
}
/**
* Test getOrigBody()
*/
public function test_get_orig_body()
{
$mime = new \Mail_mime();
$mime->setTXTBody('test body');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$expected = "Content-Transfer-Encoding: quoted-printable\r\n"
. "Content-Type: text/plain; charset=ISO-8859-1\r\n"
. "\r\n"
. "test body\r\n";
$this->assertSame($expected, $message->getOrigBody());
}
/**
* Test get()
*/
public function test_get()
{
$mime = new \Mail_mime();
$mime->setTXTBody('test body');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$expected = "This is an OpenPGP/MIME signed message (RFC 4880 and 3156)\r\n"
. "\r\n"
. "--=_%x\r\n"
. "Content-Transfer-Encoding: quoted-printable\r\n"
. "Content-Type: text/plain; charset=ISO-8859-1\r\n"
. "\r\n"
. "test body\r\n"
. "\r\n"
. "--=_%x--\r\n";
$signed_headers = "MIME-Version: 1.0\r\n"
. "Content-Type: multipart/signed;\r\n"
. " protocol=\"application/pgp-signature\";\r\n"
. " boundary=\"=_%x\"\r\n";
// Note: The str_replace() below is for phpunit <= 6.5
$this->assertStringMatchesFormat(
str_replace("\r\n", "\n", $expected),
str_replace("\r\n", "\n", $message->get())
);
$this->assertStringMatchesFormat(
str_replace("\r\n", "\n", $signed_headers),
str_replace("\r\n", "\n", $message->txtHeaders())
);
$mime = new \Mail_mime();
$mime->setTXTBody('test body');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_SIGNED);
$message->addPGPSignature('signature', 'algorithm');
$signed = "This is an OpenPGP/MIME signed message (RFC 4880 and 3156)\r\n"
. "\r\n"
. "--=_%x\r\n"
. "Content-Transfer-Encoding: quoted-printable\r\n"
. "Content-Type: text/plain; charset=ISO-8859-1\r\n"
. "\r\n"
. "test body\r\n"
. "\r\n"
. "--=_%x\r\n"
. "Content-Type: application/pgp-signature;\r\n"
. " name=signature.asc\r\n"
. "Content-Disposition: attachment;\r\n"
. " filename=signature.asc;\r\n"
. " size=9\r\n"
. "Content-Description: OpenPGP digital signature\r\n"
. "\r\n"
. "signature\r\n"
. "--=_%x--\r\n";
$signed_headers = "MIME-Version: 1.0\r\n"
. "Content-Type: multipart/signed;\r\n"
. " protocol=\"application/pgp-signature\";\r\n"
. " boundary=\"=_%x\";\r\n"
. " micalg=pgp-algorithm\r\n";
// Note: The str_replace() below is for phpunit <= 6.5
$this->assertStringMatchesFormat(
str_replace("\r\n", "\n", $signed),
str_replace("\r\n", "\n", $message->get())
);
$this->assertStringMatchesFormat(
str_replace("\r\n", "\n", $signed_headers),
str_replace("\r\n", "\n", $message->txtHeaders())
);
$mime = new \Mail_mime();
$mime->setTXTBody('test body');
$message = new \enigma_mime_message($mime, \enigma_mime_message::PGP_ENCRYPTED);
$message->setPGPEncryptedBody('encrypted body');
$encrypted = "This is an OpenPGP/MIME encrypted message (RFC 4880 and 3156)\r\n"
. "\r\n"
. "--=_%x\r\n"
. "Content-Type: application/pgp-encrypted\r\n"
. "Content-Description: PGP/MIME version identification\r\n"
. "\r\n"
. "Version: 1\r\n"
. "--=_%x\r\n"
. "Content-Type: application/octet-stream;\r\n"
. " name=encrypted.asc\r\n"
. "Content-Disposition: inline;\r\n"
. " filename=encrypted.asc;\r\n"
. " size=14\r\n"
. "Content-Description: PGP/MIME encrypted message\r\n"
. "\r\n"
. "encrypted body\r\n"
. "--=_%x--\r\n";
$encrypted_headers = "MIME-Version: 1.0\r\n"
. "Content-Type: multipart/encrypted;\r\n"
. " protocol=\"application/pgp-encrypted\";\r\n"
. " boundary=\"=_%x\"\r\n";
// Note: The str_replace() below is for phpunit <= 6.5
$this->assertStringMatchesFormat(
str_replace("\r\n", "\n", $encrypted),
str_replace("\r\n", "\n", $message->get())
);
$this->assertStringMatchesFormat(
str_replace("\r\n", "\n", $encrypted_headers),
str_replace("\r\n", "\n", $message->txtHeaders())
);
}
}
Function Calls
None |
Stats
MD5 | 1552a3553ab9ab836b7d86f466f91041 |
Eval Count | 0 |
Decode Time | 86 ms |