diff --git a/admin/inc/class.admin_mail.inc.php b/admin/inc/class.admin_mail.inc.php index 4f47d7d9bdb..add619e5fe3 100644 --- a/admin/inc/class.admin_mail.inc.php +++ b/admin/inc/class.admin_mail.inc.php @@ -80,7 +80,8 @@ class admin_mail public $public_functions = array( 'add' => true, 'edit' => true, - 'ajax_activeAccounts' => true + 'ajax_activeAccounts' => true, + 'ews_custom_permissions' => true ); /** @@ -196,6 +197,11 @@ public function add(array $content=array(), $msg='', $msg_type='success') 'acc_imap_port' => 993, 'manual_class' => 'emailadmin_manual', ); + // Select Options + $sel_options['acc_imap_ssl'] = self::$ssl_types; + // Not listing other server types, since this could be single account + // EGroupware only allows different types for multiple accounts + $sel_options['acc_imap_type'] = Mail\Types::getIMAPServerTypes(false); Framework::message($msg ? $msg : (string)$_GET['msg'], $msg_type); if (!empty($content['acc_imap_host']) || !empty($content['acc_imap_username'])) @@ -203,9 +209,7 @@ public function add(array $content=array(), $msg='', $msg_type='success') $readonlys['button[manual]'] = true; unset($content['manual_class']); } - $tpl->exec(static::APP_CLASS.'autoconfig', $content, array( - 'acc_imap_ssl' => self::$ssl_types, - ), $readonlys, $content, 2); + $tpl->exec(static::APP_CLASS.'autoconfig', $content, $sel_options, $readonlys, $content, 2); } /** @@ -285,17 +289,17 @@ public function autoconfig(array $content) $e = null; try { - $content['output'] .= "\n".Api\DateTime::to('now', 'H:i:s').": Trying $ssl connection to $host:$port ...\n"; + $content['output'] .= "\n" . Api\DateTime::to('now', 'H:i:s') . ": Trying $ssl connection to $host:$port ...\n"; $content['acc_imap_port'] = $port; $imap = self::imap_client($content, self::TIMEOUT); //$content['output'] .= array2string($imap->capability()); $imap->login(); - $content['output'] .= "\n".lang('Successful connected to %1 server%2.', 'IMAP', ' '.lang('and logged in'))."\n"; + $content['output'] .= "\n" . lang('Successful connected to %1 server%2.', 'IMAP', ' ' . lang('and logged in')) . "\n"; if (!$imap->isSecureConnection()) { - $content['output'] .= lang('Connection is NOT secure! Everyone can read eg. your credentials.')."\n"; + $content['output'] .= lang('Connection is NOT secure! Everyone can read eg. your credentials.') . "\n"; $content['acc_imap_ssl'] = 'no'; } //$content['output'] .= "\n\n".array2string($imap->capability()); @@ -331,8 +335,13 @@ public function autoconfig(array $content) if ($connected) // continue with next wizard step: define folders { unset($content['button']); - return $this->folder($content, lang('Successful connected to %1 server%2.', 'IMAP', ' '.lang('and logged in')). - ($imap->isSecureConnection() ? '' : "\n".lang('Connection is NOT secure! Everyone can read eg. your credentials.'))); + //EWS: skip steps + if (Mail\Account::is_ews_type($content['acc_imap_type'])) + return $this->smtp($content, lang('Successful connected to %1 server%2.', 'EWS', ' ' . lang('and logged in')) . + ($imap->isSecureConnection() ? '' : "\n" . lang('Connection is NOT secure! Everyone can read eg. your credentials.'))); + else + return $this->folder($content, lang('Successful connected to %1 server%2.', 'IMAP', ' ' . lang('and logged in')) . + ($imap->isSecureConnection() ? '' : "\n".lang('Connection is NOT secure! Everyone can read eg. your credentials.'))); } // add validation error, if we can identify a field if (!$connected && $e instanceof Horde_Imap_Client_Exception) @@ -352,6 +361,9 @@ public function autoconfig(array $content) $readonlys['button[manual]'] = true; unset($content['manual_class']); $sel_options['acc_imap_ssl'] = self::$ssl_types; + // Not listing other server types, since this could be single account + // EGroupware only allows different types for multiple accounts + $sel_options['acc_imap_type'] = Mail\Types::getIMAPServerTypes(false); $tpl = new Etemplate('admin.mailwizard'); $tpl->exec(static::APP_CLASS.'autoconfig', $content, $sel_options, $readonlys, $content, 2); } @@ -630,7 +642,10 @@ public function smtp(array $content, $msg='') switch($button) { case 'back': - return $this->sieve($content); + if (Mail\Account::is_ews_type($content['acc_imap_type'])) + return $this->add($content); + else + return $this->sieve($content); } } // first try: hide manual config @@ -824,6 +839,7 @@ public function smtp(array $content, $msg='') */ public function edit(array $content=null, $msg='', $msg_type='success') { + unset($content['manual_class']); // app is trying to tell something, while redirecting to wizard if (empty($content) && $_GET['acc_id'] && empty($msg) && !empty( $_GET['msg'])) { @@ -893,6 +909,7 @@ public function edit(array $content=null, $msg='', $msg_type='success') { if (!$content['acc_'.$type.'_ssl']) $content['acc_'.$type.'_ssl'] = 'no'; } + } catch(Api\Exception\NotFound $e) { if (self::$debug) _egw_log_exception($e); @@ -933,8 +950,9 @@ public function edit(array $content=null, $msg='', $msg_type='success') 'acc_smtp_type' => true, 'acc_smtp_auth_session' => true, ); } + // ensure correct values for single user mail accounts (we only hide them client-side) - if (!($is_multiple = Mail\Account::is_multiple($content))) + if (!($is_multiple = Mail\Account::is_multiple($content)) && $content['acc_imap_type'] != 'EGroupware\Api\Mail\Imap' && !Mail\Account::is_ews_type( $content['acc_imap_type'] ) ) { $content['acc_imap_type'] = 'EGroupware\\Api\\Mail\\Imap'; unset($content['acc_imap_login_type']); @@ -1086,6 +1104,15 @@ public function edit(array $content=null, $msg='', $msg_type='success') } $content['accounts'][$content['acc_id']] = Mail\Account::identity_name($content, false); } + if ($content['acc_imap_type'] && Mail\Account::is_ews_type($content['acc_imap_type'])) + { + if ($content['clear_grid']) + { + $content['ews_permissions'] = array(); + $content['clear_grid'] = false; + Api\Mail_EWS::storeFolderPermissions($content['ews_permissions'], $content['acc_id']); + } + } } else { @@ -1220,6 +1247,24 @@ public function edit(array $content=null, $msg='', $msg_type='success') $tpl->setElementAttribute($folder, 'allowFreeEntries', true); } } + elseif (Mail\Account::is_ews_type($content['acc_imap_type'])) + { + try { + + $sel_options['acc_folder_sent'] = $sel_options['acc_folder_trash'] = + $sel_options['acc_folder_draft'] = $sel_options['acc_folder_template'] = + $sel_options['acc_folder_junk'] = $sel_options['acc_folder_archive'] = + $sel_options['notify_folders'] = $sel_options['acc_folder_ham'] = + Api\Mail\EWS\Lib::getFoldersSelOptions($content['acc_id'], true); + } + catch (Exception $e) + { + if (self::$debug) _egw_log_exception($e); + // let user know what the problem is and that he can fix it using wizard or deleting + $msg = lang($e->getMessage()) . "\n\n" . lang('You can use wizard to fix account settings or delete account.'); + $msg_type = 'error'; + } + } else { try { @@ -1253,6 +1298,13 @@ public function edit(array $content=null, $msg='', $msg_type='success') $sel_options['ident_id'] = $content['identities']; $sel_options['acc_id'] = $content['accounts']; $sel_options['acc_further_identities'] = self::$further_identities; + $sel_options['acc_ews_type'] = array( + 'inbox' => 'Inbox', + 'public_folders' => 'Public Folders' + ); + + // Disable permissions if inbox + $content['isInbox'] = ( $content['acc_ews_type'] == 'inbox' ); // user is allowed to create or edit further identities if ($edit_access || $content['acc_further_identities']) @@ -1334,6 +1386,12 @@ public function edit(array $content=null, $msg='', $msg_type='success') } } + // Disable EWS tab for other types + if ($content['acc_imap_type'] && !Mail\Account::is_ews_type($content['acc_imap_type'])) + { + $readonlys['tabs']['admin.mailaccount.ews'] = true; + } + // account allows users to change forwards if (!$edit_access && !$readonlys['tabs']['admin.mailaccount.aliases'] && $content['acc_user_forward']) { @@ -1371,6 +1429,23 @@ public function edit(array $content=null, $msg='', $msg_type='success') } $content['admin_actions'] = (bool)$admin_actions; + if ($content['acc_imap_type'] && Mail\Account::is_ews_type($content['acc_imap_type'])) + { + try + { + $content['acc_ews_apply_permissions'] = (int) $content['acc_ews_apply_permissions']; + } catch (Exception $e) + { + if (self::$debug) + { + _egw_log_exception($e); + } + // let user know what the problem is and that he can fix it using wizard or deleting + $msg = lang($e->getMessage()) . "\n\n" . lang('You can use wizard to fix account settings or delete account.'); + $msg_type = 'error'; + } + } + //try to fix identities with no domain part set e.g. alias as identity if (!strpos($content['ident_email'], '@')) { @@ -1380,6 +1455,31 @@ public function edit(array $content=null, $msg='', $msg_type='success') $tpl->exec(static::APP_CLASS.'edit', $content, $sel_options, $readonlys, $content, 2); } + public function ews_custom_permissions( $content = array() ) + { + $dtmpl = new Etemplate('admin.mailaccount.permissions'); + $acc_id = $_GET['acc_id']? $_GET['acc_id']: $content['acc_id']; + $content['acc_id'] = $acc_id; + + $sel_options['ews_permissions'] = Api\Mail_EWS::getFolderPermissionsSelOptions( $content['acc_id'] ); + $names = array_values( $sel_options['ews_permissions'][1]['ews_move_to'] ); + $sel_options['mailbox'] = array_combine( $names, $names ); + + if ( $content['save'] || $content['apply'] ) { + $res = Api\Mail_EWS::storeFolderPermissions( $content['ews_permissions'], $content['acc_id'] ); + $msg = lang('Operation Successful'); + if ( $res && $content['save'] ) { + Framework::message( $msg ); + Framework::window_close(); + } + $content['msg'] = $msg; + } + + $content['ews_permissions'] = Api\Mail_EWS::getFolderPermissions( $content['acc_id'] ); + $readonlys = array(); + $dtmpl->exec('admin.admin_mail.ews_custom_permissions', $content,$sel_options,$readonlys,$content,2); + } + /** * Replace 0 with '' or back * @@ -1407,17 +1507,25 @@ private static function fix_account_id_0(&$account_id=null, $back=false) * @param int $timeout =null default use value returned by Mail\Imap::getTimeOut() * @return Horde_Imap_Client_Socket */ - protected static function imap_client(array $content, $timeout=null) - { - return new Horde_Imap_Client_Socket(array( - 'username' => $content['acc_imap_username'], - 'password' => $content['acc_imap_password'], - 'hostspec' => $content['acc_imap_host'], - 'port' => $content['acc_imap_port'], - 'secure' => self::$ssl2secure[(string)array_search($content['acc_imap_ssl'], self::$ssl2type)], - 'timeout' => $timeout > 0 ? $timeout : Mail\Imap::getTimeOut(), - 'debug' => self::DEBUG_LOG, - )); + protected static function imap_client(array $content, $timeout = null) { + //EWS: Instantiate different object + if (Mail\Account::is_ews_type($content['acc_imap_type'])) + { + $class = $content['acc_imap_type']; + return new $class($content); + } + else + { + return new Horde_Imap_Client_Socket(array( + 'username' => $content['acc_imap_username'], + 'password' => $content['acc_imap_password'], + 'hostspec' => $content['acc_imap_host'], + 'port' => $content['acc_imap_port'], + 'secure' => self::$ssl2secure[(string) array_search($content['acc_imap_ssl'], self::$ssl2type)], + 'timeout' => $timeout > 0 ? $timeout : Mail\Imap::getTimeOut(), + 'debug' => self::DEBUG_LOG, + )); + } } /** diff --git a/admin/js/app.js b/admin/js/app.js index 0c143e7f161..1b6d58ae817 100644 --- a/admin/js/app.js +++ b/admin/js/app.js @@ -47,6 +47,11 @@ app.classes.admin = AppJS.extend( */ acl_dialog: null, + /** + * Keep widgets from triggering again + */ + widget_active: false, + /** * Constructor * @@ -117,6 +122,9 @@ app.classes.admin = AppJS.extend( case 'admin.mailaccount': this.account_hide_not_applying(); break; + case 'admin.mailaccount.permissions': + this.ews_switch_folder(); + break; } }, @@ -1273,5 +1281,51 @@ app.classes.admin = AppJS.extend( resizable: false, position: 'left top' }, et2_dialog._create_parent('mail')); + }, + /** + * Switch EWS Type + * + * When switching, we want to immediately save and change the array that's being loaded + * + */ + ews_switch_type: function (_element, _widget) + { + var option1 = 'inbox'; + var option2 = 'public_folders'; + var clear = this.et2.getWidgetById('clear_grid'); + var apply = this.et2.getWidgetById('button[apply]'); + var that = this; + if (!that.widget_active) { + that.widget_active = true; + et2_dialog.show_dialog(function (_button) { + if (_button == 2) { + clear.set_value(true); + apply.getInstanceManager().submit(apply, false, apply.options.novalidate); + } else { + if (_widget.getValue() == option1) + _widget.set_value(option2); + else + _widget.set_value(option1); + that.widget_active = false; + } + }, egw.lang('Changing Account Type will delete all your current settings. Are you sure you want to continue?'), + egw.lang('Change Type'), null, et2_dialog.BUTTON_YES_NO, et2_dialog.WARNING_MESSAGE, undefined, egw); + } + }, + + /** + * Switch Folder in ews permissions + * + */ + ews_switch_folder: function() + { + var folder = this.et2.getWidgetById('mailbox'); + jQuery('#admin-mailaccount-permissions_ews_permissions tr').each( function() { + if ( jQuery( this ).hasClass('th') ) return; + if ( jQuery( this ).find('input[name*=ews_name]').val() == folder.getValue() ) + jQuery( this ).show(); + else + jQuery( this ).hide(); + }); } }); diff --git a/admin/templates/default/app.css b/admin/templates/default/app.css index 4048399ca3e..8ebb7229883 100644 --- a/admin/templates/default/app.css +++ b/admin/templates/default/app.css @@ -177,3 +177,14 @@ select#admin-mailaccount_ident_id { font-size: 110%; } #admin-acl {width:99%;} + +#admin-mailaccount-permissions_ews_tabs .th { + border-bottom: none; +} +#admin-mailaccount-permissions_ews_tabs .et2_tabheader { + display:none; +} +#admin-mailaccount-permissions_ews_tabs #admin-mailaccount-permissions_ews_permissions .th { + visibility: collapse; +} + diff --git a/admin/templates/default/mailaccount.permissions.xet b/admin/templates/default/mailaccount.permissions.xet new file mode 100644 index 00000000000..52a2287e0c5 --- /dev/null +++ b/admin/templates/default/mailaccount.permissions.xet @@ -0,0 +1,83 @@ + + + + + + diff --git a/admin/templates/default/mailaccount.xet b/admin/templates/default/mailaccount.xet index 21c9f58b46b..338d857ec97 100644 --- a/admin/templates/default/mailaccount.xet +++ b/admin/templates/default/mailaccount.xet @@ -53,7 +53,7 @@ - + @@ -322,6 +322,32 @@ +