Skip to content

Commit

Permalink
OpenPGP first look (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
RainLoop committed Jan 27, 2014
1 parent 74991b1 commit 098a04e
Show file tree
Hide file tree
Showing 15 changed files with 175 additions and 20 deletions.
9 changes: 8 additions & 1 deletion Gruntfile.js
Expand Up @@ -112,6 +112,13 @@ module.exports = function (grunt) {
],
dest: 'rainloop/v/<%= cfg.devVersion %>/static/js/boot.js'
},
js_openpgp: {
nonull: true,
src: [
"vendors/openpgp.min.js",
],
dest: 'rainloop/v/<%= cfg.devVersion %>/static/js/openpgp.js'
},
js_libs: {
nonull: true,
options: {
Expand Down Expand Up @@ -383,7 +390,7 @@ module.exports = function (grunt) {
nospawn: true
},
files: ['dev/**/*.js', 'vendors/**/*.js'],
tasks: ['concat:js_libs', 'concat:js_admin', 'concat:js_app']
tasks: ['concat:js_libs', 'concat:js_openpgp', 'concat:js_admin', 'concat:js_app']
},
styles: {
options: {
Expand Down
13 changes: 12 additions & 1 deletion dev/Boots/RainLoopApp.js
Expand Up @@ -785,6 +785,18 @@ RainLoopApp.prototype.bootstart = function ()

if (bValue)
{
// if (window.crypto && window.crypto.getRandomValues)
// {
// $.ajax({
// 'url': RL.link().openPgpJs(),
// 'dataType': 'script',
// 'cache': true,
// 'success': function () {
// window.console.log('openPgpJs');
// }
// });
// }

kn.startScreens([MailBoxScreen, SettingsScreen]);

// setup maito protocol
Expand Down Expand Up @@ -849,7 +861,6 @@ RainLoopApp.prototype.bootstart = function ()
}

if (!Globals.bMobileDevice)
// if (false)
{
_.defer(function () {
Utils.initLayoutResizer('#rl-left', '#rl-right', Enums.ClientSideKeyName.FolderListSize);
Expand Down
9 changes: 9 additions & 0 deletions dev/Common/LinkBuilder.js
Expand Up @@ -257,6 +257,15 @@ LinkBuilder.prototype.notificationMailIcon = function ()
this.sVersion + '/static/css/images/icom-message-notification.png';
};

/**
* @return {string}
*/
LinkBuilder.prototype.openPgpJs = function ()
{
return ('' === this.sCdnStaticDomain ? 'rainloop/v/' : this.sCdnStaticDomain) +
this.sVersion + '/static/js/openpgp.js';
};

/**
* @return {string}
*/
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -2,7 +2,7 @@
"name": "RainLoop",
"title": "RainLoop Webmail",
"version": "1.6.2",
"release": "660",
"release": "661",
"description": "Simple, modern & fast web-based email client",
"homepage": "http://rainloop.net",
"main": "Gruntfile.js",
Expand Down
8 changes: 8 additions & 0 deletions rainloop/v/0.0.0/app/libraries/MailSo/Imap/BodyStructure.php
Expand Up @@ -248,6 +248,14 @@ public function IsDoc()
return 'doc' === \MailSo\Base\Utils::ContentTypeType($this->ContentType(), $this->FileName());
}

/**
* @return bool
*/
public function IsPgpSignature()
{
return 'application/pgp-signature' === \strtolower($this->ContentType());
}

/**
* @return array|null
*/
Expand Down
28 changes: 20 additions & 8 deletions rainloop/v/0.0.0/app/libraries/MailSo/Mail/MailClient.php
Expand Up @@ -356,18 +356,30 @@ public function Message($sFolderName, $iIndex, $bIndexIsUid = true, $oCacher = n

$oBodyStructure = null;
$oMessage = false;
$aTextMimeIndexes = array();
$aBodyPeekMimeIndexes = array();

$aFetchResponse = $this->oImapClient->Fetch(array(\MailSo\Imap\Enumerations\FetchType::BODYSTRUCTURE), $iIndex, $bIndexIsUid);
if (0 < \count($aFetchResponse))
if (0 < \count($aFetchResponse) && isset($aFetchResponse[0]))
{
$oBodyStructure = $aFetchResponse[0]->GetFetchBodyStructure();
$aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : null;
if (is_array($aTextParts) && 0 < \count($aTextParts))
if ($oBodyStructure)
{
foreach ($aTextParts as $oPart)
$aTextParts = $oBodyStructure->SearchHtmlOrPlainParts();
if (is_array($aTextParts) && 0 < \count($aTextParts))
{
foreach ($aTextParts as $oPart)
{
$aBodyPeekMimeIndexes[] = $oPart->PartID();
}
}

$aSignatureParts = $oBodyStructure->SearchByContentType('application/pgp-signature');
if (is_array($aSignatureParts) && 0 < \count($aSignatureParts))
{
$aTextMimeIndexes[] = $oPart->PartID();
foreach ($aSignatureParts as $oPart)
{
$aBodyPeekMimeIndexes[] = $oPart->PartID();
}
}
}
}
Expand All @@ -381,9 +393,9 @@ public function Message($sFolderName, $iIndex, $bIndexIsUid = true, $oCacher = n
$this->getEnvelopeOrHeadersRequestString()
);

if (0 < \count($aTextMimeIndexes))
if (0 < \count($aBodyPeekMimeIndexes))
{
foreach ($aTextMimeIndexes as $sTextMimeIndex)
foreach ($aBodyPeekMimeIndexes as $sTextMimeIndex)
{
$aFetchItems[] = \MailSo\Imap\Enumerations\FetchType::BODY_PEEK.'['.$sTextMimeIndex.']';
}
Expand Down
68 changes: 65 additions & 3 deletions rainloop/v/0.0.0/app/libraries/MailSo/Mail/Message.php
Expand Up @@ -103,6 +103,11 @@ class Message
*/
private $sPlain;

/**
* @var string
*/
private $sPlainRaw;

/**
* @var string
*/
Expand Down Expand Up @@ -158,6 +163,11 @@ class Message
*/
private $iThreadsLen;

/**
* @var string
*/
private $sPgpSignature;

/**
* @access private
*/
Expand Down Expand Up @@ -191,6 +201,7 @@ public function Clear()
$this->oBcc = null;

$this->sPlain = '';
$this->sPlainRaw = '';
$this->sHtml = '';

$this->oAttachments = null;
Expand All @@ -208,6 +219,8 @@ public function Clear()
$this->iThreadsLen = 0;
$this->iParentThread = 0;

$this->sPgpSignature = '';

return $this;
}

Expand All @@ -227,6 +240,14 @@ public function Plain()
return $this->sPlain;
}

/**
* @return string
*/
public function PlainRaw()
{
return $this->sPlainRaw;
}

/**
* @return string
*/
Expand All @@ -235,6 +256,14 @@ public function Html()
return $this->sHtml;
}

/**
* @return string
*/
public function PgpSignature()
{
return $this->sPgpSignature;
}

/**
* @param string $sHtml
*
Expand Down Expand Up @@ -527,8 +556,6 @@ public function InitByFetchResponse($sFolder, $oFetchResponse, $oBodyStructure =
$oBodyStructure = $oFetchResponse->GetFetchBodyStructure();
}

$aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : array();

$sUid = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::UID);
$sSize = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::RFC822_SIZE);
$sInternalDate = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::INTERNALDATE);
Expand Down Expand Up @@ -704,6 +731,7 @@ public function InitByFetchResponse($sFolder, $oFetchResponse, $oBodyStructure =
$this->sInReplyTo = $oFetchResponse->GetFetchEnvelopeValue(8, '');
}

$aTextParts = $oBodyStructure ? $oBodyStructure->SearchHtmlOrPlainParts() : null;
if (\is_array($aTextParts) && 0 < \count($aTextParts))
{
if (0 === \strlen($sCharset))
Expand Down Expand Up @@ -749,9 +777,43 @@ public function InitByFetchResponse($sFolder, $oFetchResponse, $oBodyStructure =
else
{
$this->sPlain = \implode("\n", $sPlainParts);
$this->sPlainRaw = $this->sPlain;
}

$aMatch = array();
if (\preg_match('/-----BEGIN PGP SIGNATURE-----(.+)-----END PGP SIGNATURE-----/ism', $this->sPlain, $aMatch) && !empty($aMatch[0]))
{
$this->sPgpSignature = $aMatch[0];
$this->sPlain = \trim($this->sPlain);
}

$aMatch = array();
if (!empty($this->sPgpSignature) &&
\preg_match('/-----BEGIN PGP SIGNED MESSAGE-----(.+)-----BEGIN PGP SIGNATURE-----(.+)-----END PGP SIGNATURE-----/ism', $this->sPlain, $aMatch) &&
!empty($aMatch[0]) && isset($aMatch[1]))
{
$this->sPlain = \str_replace($aMatch[0], $aMatch[1], $this->sPlain);
$this->sPlain = \trim(\preg_replace('/^Hash: [^\s]+/i', '', \trim($this->sPlain)));
}

unset($sHtmlParts, $sPlainParts);
unset($sHtmlParts, $sPlainParts, $aMatch);
}

if (empty($this->sPgpSignature) && 'multipart/signed' === \strtolower($this->sContentType) &&
'application/pgp-signature' === \strtolower($oHeaders->ParameterValue(
\MailSo\Mime\Enumerations\Header::CONTENT_TYPE,
\MailSo\Mime\Enumerations\Parameter::PROTOCOL
)))
{
$aPgpSignatureParts = $oBodyStructure ? $oBodyStructure->SearchByContentType('application/pgp-signature') : null;
if (\is_array($aPgpSignatureParts) && 0 < \count($aPgpSignatureParts) && isset($aPgpSignatureParts[0]))
{
$sPgpSignatureText = $oFetchResponse->GetFetchValue(\MailSo\Imap\Enumerations\FetchType::BODY.'['.$aPgpSignatureParts[0]->PartID().']');
if (\is_string($sPgpSignatureText) && 0 < \strlen($sPgpSignatureText) && 0 < \strpos($sPgpSignatureText, 'BEGIN PGP SIGNATURE'))
{
$this->sPgpSignature = \trim($sPgpSignatureText);
}
}
}

if ($oBodyStructure)
Expand Down
Expand Up @@ -13,4 +13,5 @@ class Parameter
const NAME = 'name';
const FILENAME = 'filename';
const BOUNDARY = 'boundary';
const PROTOCOL = 'protocol';
}
8 changes: 6 additions & 2 deletions rainloop/v/0.0.0/app/libraries/RainLoop/Actions.php
Expand Up @@ -6320,13 +6320,14 @@ protected function responseObject($mResponse, $sParent = '', $aParameters = arra
}
}

$sPlain = '';
$sPlain = $sPlainRaw = '';
$sHtml = $mResponse->Html();
$bRtl = false;

if (0 === \strlen($sHtml))
{
$sPlain = $mResponse->Plain();
$sPlainRaw = $mResponse->PlainRaw();
$bRtl = \MailSo\Base\Utils::IsRTL($sPlain);
}
else
Expand All @@ -6341,9 +6342,12 @@ protected function responseObject($mResponse, $sParent = '', $aParameters = arra
$sHtml, $bHasExternals, $mFoundedCIDs, $aContentLocationUrls, $mFoundedContentLocationUrls);

$mResult['Plain'] = 0 === \strlen($sPlain) ? '' : \MailSo\Base\HtmlUtils::ConvertPlainToHtml($sPlain);
$mResult['PlainRaw'] = $sPlainRaw;
$mResult['Rtl'] = $bRtl;

unset($sHtml, $sPlain);
$mResult['PgpSignature'] = $mResponse->PgpSignature();

unset($sHtml, $sPlain, $sPlainRaw);

$mResult['HasExternals'] = $bHasExternals;
$mResult['HasInternals'] = (\is_array($mFoundedCIDs) && 0 < \count($mFoundedCIDs)) ||
Expand Down
9 changes: 9 additions & 0 deletions rainloop/v/0.0.0/static/js/admin.js
Expand Up @@ -3222,6 +3222,15 @@ LinkBuilder.prototype.notificationMailIcon = function ()
this.sVersion + '/static/css/images/icom-message-notification.png';
};

/**
* @return {string}
*/
LinkBuilder.prototype.openPgpJs = function ()
{
return ('' === this.sCdnStaticDomain ? 'rainloop/v/' : this.sCdnStaticDomain) +
this.sVersion + '/static/js/openpgp.js';
};

/**
* @return {string}
*/
Expand Down
2 changes: 1 addition & 1 deletion rainloop/v/0.0.0/static/js/admin.min.js

Large diffs are not rendered by default.

22 changes: 21 additions & 1 deletion rainloop/v/0.0.0/static/js/app.js
Expand Up @@ -3222,6 +3222,15 @@ LinkBuilder.prototype.notificationMailIcon = function ()
this.sVersion + '/static/css/images/icom-message-notification.png';
};

/**
* @return {string}
*/
LinkBuilder.prototype.openPgpJs = function ()
{
return ('' === this.sCdnStaticDomain ? 'rainloop/v/' : this.sCdnStaticDomain) +
this.sVersion + '/static/js/openpgp.js';
};

/**
* @return {string}
*/
Expand Down Expand Up @@ -17362,6 +17371,18 @@ RainLoopApp.prototype.bootstart = function ()

if (bValue)
{
// if (window.crypto && window.crypto.getRandomValues)
// {
// $.ajax({
// 'url': RL.link().openPgpJs(),
// 'dataType': 'script',
// 'cache': true,
// 'success': function () {
// window.console.log('openPgpJs');
// }
// });
// }

kn.startScreens([MailBoxScreen, SettingsScreen]);

// setup maito protocol
Expand Down Expand Up @@ -17426,7 +17447,6 @@ RainLoopApp.prototype.bootstart = function ()
}

if (!Globals.bMobileDevice)
// if (false)
{
_.defer(function () {
Utils.initLayoutResizer('#rl-left', '#rl-right', Enums.ClientSideKeyName.FolderListSize);
Expand Down
4 changes: 2 additions & 2 deletions rainloop/v/0.0.0/static/js/app.min.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions rainloop/v/0.0.0/static/js/openpgp.js

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions vendors/openpgp.min.js

Large diffs are not rendered by default.

0 comments on commit 098a04e

Please sign in to comment.