1: <?php
2: /**
3: * Copyright 2014 Horde LLC (http://www.horde.org/)
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @category Horde
9: * @copyright 2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Defines AJAX actions used on the remote accounts preference page.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: class IMP_Ajax_Application_Handler_RemotePrefs
24: extends Horde_Core_Ajax_Application_Handler
25: {
26: /**
27: * AJAX action: Do autoconfiguration for a remote account.
28: *
29: * Variables used:
30: * - email: (string) The e-mail address.
31: * - password: (string) Remote server password.
32: * - password_base64: (boolean) If true, password is base64 encoded.
33: * - secure: (boolean) If true, require a secure remote connection.
34: *
35: * @return boolean An object with the following properties:
36: * - mconfig: (object) The configuration object.
37: * - success: (boolean) True if autoconfiguration was successful.
38: */
39: public function autoconfigAccount()
40: {
41: global $injector, $notification;
42:
43: $res = new stdClass;
44: $res->success = false;
45:
46: $password = $this->vars->password;
47: if ($this->vars->password_base64) {
48: $password = base64_decode($password);
49: }
50:
51: try {
52: $aconfig = $injector->getInstance('IMP_Mail_Autoconfig');
53: $mconfig = $aconfig->getMailConfig($this->vars->email, array(
54: 'auth' => $password,
55: 'insecure' => empty($this->vars->secure)
56: ));
57:
58: if ($mconfig && !is_null($mconfig->username)) {
59: $imap = ($mconfig instanceof Horde_Mail_Autoconfig_Server_Imap);
60:
61: $res->mconfig = (object)$mconfig;
62: $res->mconfig->imap = $imap;
63: if (!strlen($res->mconfig->label)) {
64: $email = new Horde_Mail_Rfc822_Address($this->vars->email);
65: $res->mconfig->label = $email->bare_address;
66: }
67: $res->success = true;
68:
69: $notification->push(
70: _("Automatic configuration of the account was successful."),
71: 'horde.success'
72: );
73: }
74: } catch (Horde_Mail_Autoconfig_Exception $e) {}
75:
76: if (!$res->success) {
77: $notification->push(
78: _("Automatic configuration of the account failed. Please check your settings or otherwise use the Advanced Setup to manually enter the remote server configuration."),
79: 'horde.error'
80: );
81: }
82:
83: return $res;
84: }
85:
86: }
87: