mailto handler (research) (#136)

This commit is contained in:
RainLoop Team 2014-04-16 20:08:37 +04:00
parent 706d4408e7
commit 818bf9fb40
11 changed files with 316 additions and 206 deletions

View file

@ -1016,6 +1016,15 @@ RainLoopApp.prototype.bootstart = function ()
window.SimplePace.sleep();
}
// if (RL.settingsGet('MailToEmail'))
// {
// if (window.postMessage)
// {
// window.console.log('railoop/mailto/auth/' + RL.settingsGet('MailToEmail'), '' + window.location);
//// $.postMessage('railoop/mailto/auth/' + RL.settingsGet('MailToEmail'), '' + window.location);
// }
// }
if (!!RL.settingsGet('Auth'))
{
this.setTitle(Utils.i18n('TITLES/LOADING'));
@ -1098,6 +1107,17 @@ RainLoopApp.prototype.bootstart = function ()
}, 2000);
// if (window.navigator && Utils.isFunc(window.navigator.registerProtocolHandler))
// {
// window.navigator.registerProtocolHandler('mailto',
// window.location.protocol + '//' + window.location.host + window.location.pathname + '?mailto&to=%s',
// '' + (RL.settingsGet('Title') || 'RainLoop'));
// }
//
// $.receiveMessage(function () {
// window.console.log(arguments);
// }, '' + window.location);
Plugins.runHook('rl-start-user-screens');
RL.pub('rl.bootstart-user-screens');
}

View file

@ -283,6 +283,26 @@ class Utils
return !\preg_match('/[^\x09\x10\x13\x0A\x0D\x20-\x7E]/', $sValue);
}
/**
* @param string $sValue
*
* @return string
*/
public static function StrToLowerIfAscii($sValue)
{
return \MailSo\Base\Utils::IsAscii($sValue) ? \strtolower($sValue) : $sValue;
}
/**
* @param string $sValue
*
* @return string
*/
public static function StrToUpperIfAscii($sValue)
{
return \MailSo\Base\Utils::IsAscii($sValue) ? \strtoupper($sValue) : $sValue;
}
/**
* @param string $sValue
*

View file

@ -12,6 +12,7 @@ class Actions
{
const AUTH_TOKEN_KEY = 'rlauth';
const AUTH_SIGN_ME_TOKEN_KEY = 'rlsmauth';
const AUTH_MAILTO_TOKEN_KEY = 'rlmailtoauth';
const AUTH_SPEC_TOKEN_KEY = 'rlspecauth';
const AUTH_ADMIN_TOKEN_KEY = 'rlaauth';
const AUTH_LAST_ERROR = 'rllasterrorcode';
@ -820,6 +821,22 @@ class Actions
return $bResult;
}
/**
* @param string $sTo
*/
public function SetMailtoRequest($sTo)
{
if (!empty($sTo))
{
\RainLoop\Utils::SetCookie(self::AUTH_MAILTO_TOKEN_KEY,
\RainLoop\Utils::EncodeKeyValues(array(
'Time' => microtime(true),
'MailTo' => 'MailTo',
'To' => $sTo
)), 0, '/', null, null, true);
}
}
/**
* @param string $sEmail
* @param string $sLogin
@ -932,6 +949,7 @@ class Actions
'Auth' => false,
'AccountHash' => '',
'AuthAccountHash' => '',
'MailToEmail' => '',
'Email' => '',
'Title' => $oConfig->Get('webmail', 'title', ''),
'LoadingDescription' => $oConfig->Get('webmail', 'loading_description', ''),
@ -972,6 +990,18 @@ class Actions
$oSettings = null;
if (!$bAdmin)
{
$sToken = \RainLoop\Utils::GetCookie(self::AUTH_MAILTO_TOKEN_KEY, null);
if (null !== $sToken)
{
\RainLoop\Utils::ClearCookie(self::AUTH_MAILTO_TOKEN_KEY);
$mMailToData = \RainLoop\Utils::DecodeKeyValues($sToken);
if (\is_array($mMailToData) && !empty($mMailToData['MailTo']) && 'MailTo' === $mMailToData['MailTo'] &&
!empty($mMailToData['To']))
{
$aResult['MailToEmail'] = $mMailToData['To'];
}
}
$oAccount = $this->getAccountFromToken(false);
if ($oAccount instanceof \RainLoop\Account)
{

View file

@ -154,7 +154,7 @@ class Service
return $this;
}
if (0 < \count($aPaths) && !empty($aPaths[0]) && !$bAdmin)
if (0 < \count($aPaths) && !empty($aPaths[0]) && !$bAdmin && 'index' !== $aPaths[0])
{
$sMethodName = 'Service'.$aPaths[0];
if (\method_exists($this->oServiceActions, $sMethodName) &&

View file

@ -798,6 +798,26 @@ class ServiceActions
return '';
}
/**
* @return string
*/
public function ServiceMailto()
{
$sTo = \trim($this->oHttp->GetQuery('to', ''));
if (!empty($sTo))
{
if (preg_match('/^mailto:/i', $sTo))
{
$sTo = \substr($sTo, 7);
}
$this->oActions->SetMailtoRequest(\MailSo\Base\Utils::StrToLowerIfAscii($sTo));
}
$this->oActions->Location('./');
return '';
}
/**
* @return string
*/

File diff suppressed because one or more lines are too long

View file

@ -19473,6 +19473,15 @@ RainLoopApp.prototype.bootstart = function ()
window.SimplePace.sleep();
}
// if (RL.settingsGet('MailToEmail'))
// {
// if (window.postMessage)
// {
// window.console.log('railoop/mailto/auth/' + RL.settingsGet('MailToEmail'), '' + window.location);
//// $.postMessage('railoop/mailto/auth/' + RL.settingsGet('MailToEmail'), '' + window.location);
// }
// }
if (!!RL.settingsGet('Auth'))
{
this.setTitle(Utils.i18n('TITLES/LOADING'));
@ -19555,6 +19564,17 @@ RainLoopApp.prototype.bootstart = function ()
}, 2000);
// if (window.navigator && Utils.isFunc(window.navigator.registerProtocolHandler))
// {
// window.navigator.registerProtocolHandler('mailto',
// window.location.protocol + '//' + window.location.host + window.location.pathname + '?mailto&to=%s',
// '' + (RL.settingsGet('Title') || 'RainLoop'));
// }
//
// $.receiveMessage(function () {
// window.console.log(arguments);
// }, '' + window.location);
Plugins.runHook('rl-start-user-screens');
RL.pub('rl.bootstart-user-screens');
}

File diff suppressed because one or more lines are too long