diff --git a/frontend/client/modules/crm/src/views/inbound-email/fields/folder.js b/frontend/client/modules/crm/src/views/inbound-email/fields/folder.js
new file mode 100644
index 0000000000..3087b4716e
--- /dev/null
+++ b/frontend/client/modules/crm/src/views/inbound-email/fields/folder.js
@@ -0,0 +1,67 @@
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM - Open Source CRM application.
+ * Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
+ * Website: http://www.espocrm.com
+ *
+ * EspoCRM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * EspoCRM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with EspoCRM. If not, see http://www.gnu.org/licenses/.
+ ************************************************************************/
+
+Espo.define('Crm:Views.InboundEmail.Fields.Folder', 'Views.Fields.Base', function (Dep) {
+
+ return Dep.extend({
+
+ editTemplate: 'crm:inbound-email.fields.folder.edit',
+
+ events: {
+ 'click [data-action="selectFolder"]': function () {
+ var self = this;
+
+ this.notify('Please wait...');
+
+ $.ajax({
+ type: 'GET',
+ url: 'InboundEmail/action/getFolders',
+ data: {
+ host: this.model.get('host'),
+ port: this.model.get('port'),
+ ssl: this.model.get('ssl'),
+ username: this.model.get('username'),
+ password: this.model.get('password'),
+ },
+ error: function () {
+ Espo.Ui.error(self.translate('couldNotConnectToImap', 'messages', 'InboundEmail'));
+ },
+ }).done(function (folders) {
+ this.createView('modal', 'Crm:InboundEmail.Modals.SelectFolder', {
+ folders: folders
+ }, function (view) {
+ self.notify(false);
+ view.render();
+
+ self.listenToOnce(view, 'select', function (folder) {
+ view.close();
+ self.addFolder(folder);
+ });
+ });
+ }.bind(this));
+ }
+ },
+
+ addFolder: function (folder) {
+ this.$element.val(folder);
+ },
+ });
+});
diff --git a/frontend/client/modules/crm/src/views/inbound-email/fields/folders.js b/frontend/client/modules/crm/src/views/inbound-email/fields/folders.js
new file mode 100644
index 0000000000..8e9de5b89d
--- /dev/null
+++ b/frontend/client/modules/crm/src/views/inbound-email/fields/folders.js
@@ -0,0 +1,40 @@
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM - Open Source CRM application.
+ * Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
+ * Website: http://www.espocrm.com
+ *
+ * EspoCRM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * EspoCRM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with EspoCRM. If not, see http://www.gnu.org/licenses/.
+ ************************************************************************/
+
+Espo.define('Crm:Views.InboundEmail.Fields.Folders', 'Crm:Views.InboundEmail.Fields.Folder', function (Dep) {
+
+ return Dep.extend({
+
+ addFolder: function (folder) {
+ var value = this.$element.val();
+
+ var folders = [];
+ if (value != '') {
+ folders = value.split(',');
+ }
+
+ if (!~folders.indexOf(folder)) {
+ folders.push(folder);
+ }
+ this.$element.val(folders.join(','));
+ },
+ });
+});
diff --git a/frontend/client/modules/crm/src/views/inbound-email/modals/select-folder.js b/frontend/client/modules/crm/src/views/inbound-email/modals/select-folder.js
new file mode 100644
index 0000000000..95a1c9eac7
--- /dev/null
+++ b/frontend/client/modules/crm/src/views/inbound-email/modals/select-folder.js
@@ -0,0 +1,59 @@
+/************************************************************************
+ * This file is part of EspoCRM.
+ *
+ * EspoCRM - Open Source CRM application.
+ * Copyright (C) 2014 Yuri Kuznetsov, Taras Machyshyn, Oleksiy Avramenko
+ * Website: http://www.espocrm.com
+ *
+ * EspoCRM is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * EspoCRM is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with EspoCRM. If not, see http://www.gnu.org/licenses/.
+ ************************************************************************/
+
+Espo.define('Crm:Views.InboundEmail.Modals.SelectFolder', 'Views.Modal', function (Dep) {
+
+ return Dep.extend({
+
+ cssName: 'select-folder-modal',
+
+ template: 'crm:inbound-email.modals.select-folder',
+
+ data: function () {
+ return {
+ folders: this.options.folders,
+ };
+ },
+
+ events: {
+ 'click button[data-action="select"]': function (e) {
+ var value = $(e.currentTarget).data('value');
+ this.trigger('select', value);
+ },
+ },
+
+ setup: function () {
+
+ this.buttons = [
+ {
+ name: 'cancel',
+ label: 'Cancel',
+ onClick: function (dialog) {
+ dialog.close();
+ }
+ }
+ ];
+
+ },
+
+ });
+});
+