Skip to content

Commit

Permalink
[mms] Add automatic configuration of remote account connection details.
Browse files Browse the repository at this point in the history
Won't lie... this is pretty darn cool.
  • Loading branch information
slusarz committed May 17, 2014
1 parent 7c3808f commit 0d39f92
Show file tree
Hide file tree
Showing 10 changed files with 266 additions and 23 deletions.
1 change: 1 addition & 0 deletions imp/docs/CHANGES
Expand Up @@ -2,6 +2,7 @@
v6.2.0-git
----------

[mms] Add automatic configuration of remote account connection details.
[mms] Support LMTP servers when sending mail.
[mms] Fix regression where creating a mailbox that is currently a container
would not subscribe to that mailbox.
Expand Down
6 changes: 6 additions & 0 deletions imp/docs/RFCS
Expand Up @@ -133,6 +133,12 @@ MIME
:RFC 5751: S/MIME Version 3.2 Message Specification


Other
=====

:RFC 6186: Use of SRV Records for Locating Email Submission/Access Services


Non-RFC Features
================

Expand Down
57 changes: 56 additions & 1 deletion imp/js/remoteprefs.js
Expand Up @@ -8,7 +8,8 @@

var ImpRemotePrefs = {

// Variables set by other code: confirm_delete
// Variables set by PHP code: confirm_delete, empty_email, empty_password,
// next, wait

_sendData: function(a, d, c)
{
Expand All @@ -20,6 +21,27 @@ var ImpRemotePrefs = {
$('prefs').submit();
},

_autoconfigCallback: function(r)
{
if (r.success) {
$('remote_type').setValue(r.mconfig.imap ? 'imap' : 'pop3');
$('remote_server').setValue(r.mconfig.host);
$('remote_user').setValue(r.mconfig.username);
$('remote_port').setValue(r.mconfig.port);

if ($F('remote_label').blank()) {
$('remote_label').setValue(r.mconfig.label);
}

$('autoconfig_button').hide();
$('add_button').show();
} else {
$('autoconfig_button').setValue(this.next);
}

$('prefs').enable();
},

clickHandler: function(e)
{
if (e.isRightClick()) {
Expand All @@ -42,6 +64,39 @@ var ImpRemotePrefs = {
this._sendData('add', '');
break;

case 'autoconfig_button':
if ($F('remote_email').blank()) {
window.alert(this.empty_email);
} else if ($F('remote_password').blank()) {
window.alert(this.empty_password);
} else {
HordeCore.doAction(
'autoconfigAccount',
{
email: $F('remote_email'),
// Base64 encode just to keep password data from
// being plaintext. A trivial obfuscation, but
// will prevent passwords from leaking in the
// event of some sort of data dump.
password: Base64.encode($F('remote_password')),
password_base64: true,
secure: ~~(!!($F('remote_secure') == 'yes'))
},
{
callback: this._autoconfigCallback.bind(this)
}
);
elt.setValue(this.wait);
$('prefs').disable();
}
e.stop();
break;

case 'advanced_show':
$('prefs').select('.imp-remote-autoconfig').invoke('hide');
$('prefs').select('.imp-remote-advanced').invoke('show');
break;

case 'cancel_button':
this._sendData('', '', true);
break;
Expand Down
4 changes: 4 additions & 0 deletions imp/lib/Ajax/Application.php
Expand Up @@ -59,6 +59,9 @@ protected function _init()
$this->addHandler('IMP_Ajax_Application_Handler_Mboxtoggle');
$this->addHandler('IMP_Ajax_Application_Handler_Passphrase');
$this->addHandler('IMP_Ajax_Application_Handler_Search');
if ($injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_REMOTE)) {
$this->addHandler('IMP_Ajax_Application_Handler_RemotePrefs');
}
break;

case $registry::VIEW_DYNAMIC:
Expand All @@ -71,6 +74,7 @@ protected function _init()
$this->addHandler('IMP_Ajax_Application_Handler_Search');
if ($injector->getInstance('IMP_Factory_Imap')->create()->access(IMP_Imap::ACCESS_REMOTE)) {
$this->addHandler('IMP_Ajax_Application_Handler_Remote');
$this->addHandler('IMP_Ajax_Application_Handler_RemotePrefs');
}
break;

Expand Down
84 changes: 84 additions & 0 deletions imp/lib/Ajax/Application/Handler/RemotePrefs.php
@@ -0,0 +1,84 @@
<?php
/**
* Copyright 2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/

/**
* Defines AJAX actions used on the remote accounts preference page.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
class IMP_Ajax_Application_Handler_RemotePrefs
extends Horde_Core_Ajax_Application_Handler
{
/**
* AJAX action: Do autoconfiguration for a remote account.
*
* Variables used:
* - email: (string) The e-mail address.
* - password: (string) Remote server password.
* - password_base64: (boolean) If true, password is base64 encoded.
* - secure: (boolean) If true, require a secure remote connection.
*
* @return boolean An object with the following properties:
* - mconfig: (object) The configuration object.
* - success: (boolean) True if autoconfiguration was successful.
*/
public function autoconfigAccount()
{
global $injector, $notification;

$res = new stdClass;
$res->success = false;

$password = $this->vars->password;
if ($this->vars->password_base64) {
$password = base64_decode($password);
}

try {
$aconfig = $injector->getInstance('IMP_Mail_Autoconfig');
$mconfig = $aconfig->getMailConfig($this->vars->email, array(
'auth' => $password,
'insecure' => empty($this->vars->secure)
));

if ($mconfig && !is_null($mconfig->username)) {
$email = new Horde_Mail_Rfc822_Address($this->vars->email);
$imap = ($mconfig instanceof Horde_Mail_Autoconfig_Server_Imap);

$res->mconfig = (object)$mconfig;
$res->mconfig->imap = $imap;
$res->mconfig->label = $email->bare_address;
$res->success = true;

$notification->push(
_("Automatic configuration of the account was successful."),
'horde.success'
);
}
} catch (Horde_Mail_Autoconfig_Exception $e) {}

if (!$res->success) {
$notification->push(
_("Automatic configuration of the account failed. Please check your settings or otherwise use the Advanced Setup to manually enter the remote server configuration."),
'horde.error'
);
}

return $res;
}

}
1 change: 1 addition & 0 deletions imp/lib/Application.php
Expand Up @@ -103,6 +103,7 @@ protected function _bootstrap()
'IMP_Identity' => 'IMP_Factory_Identity',
'IMP_Ftree' => 'IMP_Factory_Ftree',
'IMP_Mail' => 'IMP_Factory_Mail',
'IMP_Mail_Autoconfig' => 'IMP_Factory_MailAutoconfig',
'IMP_Mailbox_SessionCache' => 'IMP_Factory_MailboxCache',
'IMP_Maillog' => 'IMP_Factory_Maillog',
'IMP_Prefs_Sort' => 'IMP_Factory_PrefsSort',
Expand Down
54 changes: 54 additions & 0 deletions imp/lib/Factory/MailAutoconfig.php
@@ -0,0 +1,54 @@
<?php
/**
* Copyright 2014 Horde LLC (http://www.horde.org/)
*
* See the enclosed file COPYING for license information (GPL). If you
* did not receive this file, see http://www.horde.org/licenses/gpl.
*
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/

/**
* A Horde_Injector based factory for the Mail autoconfiguration object.
*
* @author Michael Slusarz <slusarz@horde.org>
* @category Horde
* @copyright 2014 Horde LLC
* @license http://www.horde.org/licenses/gpl GPL
* @package IMP
*/
class IMP_Factory_MailAutoconfig
extends Horde_Core_Factory_Injector
{
/**
* Return the mail autoconfig instance.
*
* @return Horde_Mail_Autoconfig The singleton instance.
*/
public function create(Horde_Injector $injector)
{
/* Need to manually set the drivers, since we should be using Horde
* objects for Http_Client and Net_DNS2_Resolver. The return from
* getDrivers() is already in priority order, so we don't need to
* worry about that. */
$drivers = array();
foreach (Horde_Mail_Autoconfig::getDrivers() as $val) {
$val = clone $val;

if (($val instanceof Horde_Mail_Autoconfig_Driver_Guess) ||
($val instanceof Horde_Mail_Autoconfig_Driver_Srv)) {
$val->dns = $injector->getInstance('Net_DNS2_Resolver');
} elseif ($val instanceof Horde_Mail_Autoconfig_Driver_Thunderbird) {
$val->http = $injector->getInstance('Horde_Http_Client');
}

$drivers[] = $val;
}

return new Horde_Mail_Autoconfig(array('drivers' => $drivers));
}

}
7 changes: 6 additions & 1 deletion imp/lib/Prefs/Special/Remote.php
Expand Up @@ -36,9 +36,14 @@ public function display(Horde_Core_Prefs_Ui $ui)

$ui->nobuttons = true;

$page_output->addScriptFile('external/base64.js');
$page_output->addScriptFile('remoteprefs.js');
$page_output->addInlineJsVars(array(
'ImpRemotePrefs.confirm_delete' => _("Are you sure you want to delete this account?")
'ImpRemotePrefs.confirm_delete' => _("Are you sure you want to delete this account?"),
'ImpRemotePrefs.empty_email' => _("The e-mail field cannot be empty."),
'ImpRemotePrefs.empty_password' => _("The password field cannot be empty."),
'ImpRemotePrefs.next' => _("Next"),
'ImpRemotePrefs.wait' => _("Please wait...")
));

$view = new Horde_View(array(
Expand Down
17 changes: 15 additions & 2 deletions imp/package.xml
Expand Up @@ -22,7 +22,7 @@
<email>chuck@horde.org</email>
<active>no</active>
</lead>
<date>2014-05-14</date>
<date>2014-05-17</date>
<version>
<release>6.2.0beta1</release>
<api>6.2.0</api>
Expand All @@ -33,6 +33,7 @@
</stability>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [mms] Add automatic configuration of remote account connection details.
* [mms] Support LMTP servers when sending mail.
* [mms] Fix regression where creating a mailbox that is currently a container would not subscribe to that mailbox.
* [mms] Add checks to ensure that saved session expiration message was created by the user rather than an outside source.
Expand Down Expand Up @@ -127,6 +128,7 @@
<file name="Mboxtoggle.php" role="horde" />
<file name="Passphrase.php" role="horde" />
<file name="Remote.php" role="horde" />
<file name="RemotePrefs.php" role="horde" />
<file name="Search.php" role="horde" />
<file name="Smartmobile.php" role="horde" />
</dir> <!-- /lib/Ajax/Application/Handler -->
Expand Down Expand Up @@ -236,6 +238,7 @@
<file name="Identity.php" role="horde" />
<file name="Imap.php" role="horde" />
<file name="Mail.php" role="horde" />
<file name="MailAutoconfig.php" role="horde" />
<file name="Mailbox.php" role="horde" />
<file name="MailboxCache.php" role="horde" />
<file name="MailboxList.php" role="horde" />
Expand Down Expand Up @@ -1340,6 +1343,13 @@
<max>3.0.0alpha1</max>
<exclude>3.0.0alpha1</exclude>
</package>
<package>
<name>Horde_Mail_Autoconfig</name>
<channel>pear.horde.org</channel>
<min>1.0.0</min>
<max>2.0.0alpha1</max>
<exclude>2.0.0alpha1</exclude>
</package>
<package>
<name>Horde_Mime</name>
<channel>pear.horde.org</channel>
Expand Down Expand Up @@ -1598,6 +1608,7 @@
<install as="imp/lib/Ajax/Application/Handler/Mboxtoggle.php" name="lib/Ajax/Application/Handler/Mboxtoggle.php" />
<install as="imp/lib/Ajax/Application/Handler/Passphrase.php" name="lib/Ajax/Application/Handler/Passphrase.php" />
<install as="imp/lib/Ajax/Application/Handler/Remote.php" name="lib/Ajax/Application/Handler/Remote.php" />
<install as="imp/lib/Ajax/Application/Handler/RemotePrefs.php" name="lib/Ajax/Application/Handler/RemotePrefs.php" />
<install as="imp/lib/Ajax/Application/Handler/Search.php" name="lib/Ajax/Application/Handler/Search.php" />
<install as="imp/lib/Ajax/Application/Handler/Smartmobile.php" name="lib/Ajax/Application/Handler/Smartmobile.php" />
<install as="imp/lib/Ajax/Application/Viewport/Error.php" name="lib/Ajax/Application/Viewport/Error.php" />
Expand Down Expand Up @@ -1661,6 +1672,7 @@
<install as="imp/lib/Factory/Identity.php" name="lib/Factory/Identity.php" />
<install as="imp/lib/Factory/Imap.php" name="lib/Factory/Imap.php" />
<install as="imp/lib/Factory/Mail.php" name="lib/Factory/Mail.php" />
<install as="imp/lib/Factory/MailAutoconfig.php" name="lib/Factory/MailAutoconfig.php" />
<install as="imp/lib/Factory/Mailbox.php" name="lib/Factory/Mailbox.php" />
<install as="imp/lib/Factory/MailboxCache.php" name="lib/Factory/MailboxCache.php" />
<install as="imp/lib/Factory/MailboxList.php" name="lib/Factory/MailboxList.php" />
Expand Down Expand Up @@ -3598,9 +3610,10 @@
<stability>
<release>beta</release>
<api>beta</api></stability>
<date>2014-05-14</date>
<date>2014-05-17</date>
<license uri="http://www.horde.org/licenses/gpl">GPL-2.0</license>
<notes>
* [mms] Add automatic configuration of remote account connection details.
* [mms] Support LMTP servers when sending mail.
* [mms] Fix regression where creating a mailbox that is currently a container would not subscribe to that mailbox.
* [mms] Add checks to ensure that saved session expiration message was created by the user rather than an outside source.
Expand Down

0 comments on commit 0d39f92

Please sign in to comment.