Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[mms] Add automatic configuration of remote account connection details.
Won't lie... this is pretty darn cool.
- Loading branch information
Showing
10 changed files
with
266 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.