diff --git a/config/install/inmail.fetcher.imap.yml b/config/install/inmail.fetcher.imap.yml deleted file mode 100644 index a460cff..0000000 --- a/config/install/inmail.fetcher.imap.yml +++ /dev/null @@ -1,9 +0,0 @@ -id: imap -label: 'IMAP Sample' -plugin: imap -configuration: - host: - ssl: FALSE - port: 143 - username: - password: diff --git a/config/schema/inmail.schema.yml b/config/schema/inmail.schema.yml index c6cb02a..fff1678 100644 --- a/config/schema/inmail.schema.yml +++ b/config/schema/inmail.schema.yml @@ -45,8 +45,8 @@ inmail.inmail_handler.*: label: 'Configuration' type: inmail.handler.[%parent.plugin] -inmail.fetcher.*: - label: 'Mail fetcher' +inmail.deliverer.*: + label: 'Mail deliverer' type: config_entity mapping: id: @@ -60,7 +60,7 @@ inmail.fetcher.*: type: string configuration: label: 'Configuration' - type: inmail.plugin.fetcher.[%parent.plugin] + type: inmail.plugin.deliverer.[%parent.plugin] # Empty default configuration schema inmail.analyzer.*: @@ -80,8 +80,8 @@ inmail.handler.moderator_forward: label: 'Moderator address' type: email -inmail.plugin.fetcher.imap: - label: 'IMAP Fetcher' +inmail.plugin.deliverer.imap: + label: 'IMAP Deliverer' type: mapping mapping: host: diff --git a/inmail.links.action.yml b/inmail.links.action.yml new file mode 100644 index 0000000..255b82b --- /dev/null +++ b/inmail.links.action.yml @@ -0,0 +1,5 @@ +inmail.deliverer_add: + route_name: inmail.deliverer_add + title: 'Configure new deliverer' + appears_on: + - 'inmail.deliverer_list' diff --git a/inmail.links.task.yml b/inmail.links.task.yml index d835d19..7f7b939 100644 --- a/inmail.links.task.yml +++ b/inmail.links.task.yml @@ -4,9 +4,9 @@ inmail.settings: base_route: inmail.settings weight: 0 -inmail.fetcher_list: - route_name: inmail.fetcher_list - title: 'Mail fetchers' +inmail.deliverer_list: + route_name: inmail.deliverer_list + title: 'Mail deliverers' base_route: inmail.settings weight: 1 diff --git a/inmail.module b/inmail.module index 862a8b5..b2d76a8 100644 --- a/inmail.module +++ b/inmail.module @@ -17,7 +17,7 @@ use Drupal\inmail\Entity\AnalyzerConfig; * You can read more under the following chapters: * - @link processing The general message processing flow @endlink * - @link mime Message parsing @endlink - * - @link fetching Fetching email over IMAP @endlink + * - @link deliverer Fetching email over IMAP @endlink * - @link analyzer Analysis of new messages @endlink * - @link handler Handling analyzed messages @endlink * - @link mailmute Integration with the Mailmute module @enlink @@ -93,11 +93,12 @@ use Drupal\inmail\Entity\AnalyzerConfig; */ /** - * @defgroup fetching Fetching email over IMAP + * @defgroup deliverer Fetching email over IMAP * @{ - * To process messages from an IMAP account, enter server details and - * credentials on the Inmail settings form. Messages are fetched and processed - * during Cron runs. + * To process messages from an IMAP account, visit the "Mail deliverers" list + * (admin/config/inmail/deliverers) and configure a new deliverer, entering + * server details and credentials in the form. Messages are delivered and + * processed during Cron runs. * @} */ @@ -270,18 +271,18 @@ function inmail_mail($key, &$message, $params) { * Implements hook_cron(). */ function inmail_cron() { - /** @var \Drupal\inmail\Entity\FetcherConfig[] $fetchers */ - $fetchers = \Drupal::entityManager()->getStorage('inmail_fetcher')->loadMultiple(); - /** @var \Drupal\Component\Plugin\PluginManagerInterface $fetcher_manager */ - $fetcher_manager = \Drupal::service('plugin.manager.inmail.fetcher'); + /** @var \Drupal\inmail\Entity\DelivererConfig[] $deliverers */ + $deliverers = \Drupal::entityManager()->getStorage('inmail_deliverer')->loadMultiple(); + /** @var \Drupal\Component\Plugin\PluginManagerInterface $deliverer_manager */ + $deliverer_manager = \Drupal::service('plugin.manager.inmail.deliverer'); /** @var \Drupal\inmail\MessageProcessorInterface $processor */ $processor = \Drupal::service('inmail.processor'); // Fetch and process new mail. - foreach ($fetchers as $fetcher) { - /** @var \Drupal\inmail\Plugin\inmail\Fetcher\FetcherInterface $plugin */ - $plugin = $fetcher_manager->createInstance($fetcher->id(), $fetcher->getConfiguration()); - $raws = $plugin->fetch(); + foreach ($deliverers as $deliverer) { + /** @var \Drupal\inmail\Plugin\inmail\Deliverer\DelivererInterface $plugin */ + $plugin = $deliverer_manager->createInstance($deliverer->id(), $deliverer->getConfiguration()); + $raws = $plugin->deliver(); $processor->processMultiple($raws); } } diff --git a/inmail.routing.yml b/inmail.routing.yml index d7d0ab8..aa9de00 100644 --- a/inmail.routing.yml +++ b/inmail.routing.yml @@ -66,32 +66,40 @@ entity.inmail_handler.disable: requirements: _permission: 'administer inmail' -inmail.fetcher_list: - path: admin/config/system/inmail/fetchers +inmail.deliverer_list: + path: admin/config/system/inmail/deliverers defaults: - _entity_list: 'inmail_fetcher' - _title: 'Mail fetchers' + _entity_list: 'inmail_deliverer' + _title: 'Mail deliverers' requirements: _permission: 'administer inmail' -entity.inmail_fetcher.edit_form: - path: admin/config/system/inmail/fetchers/{inmail_fetcher} +inmail.deliverer_add: + path: admin/config/system/inmail/deliverers/add defaults: - _entity_form: 'inmail_fetcher.default' - _title_callback: \Drupal\inmail\Controller\FetcherController::titleEdit + _entity_form: 'inmail_deliverer.add' + _title: 'Configure new deliverer' requirements: _permission: 'administer inmail' -entity.inmail_fetcher.enable: - path: admin/config/system/inmail/fetchers/{inmail_fetcher}/enable +entity.inmail_deliverer.edit_form: + path: admin/config/system/inmail/deliverers/{inmail_deliverer} defaults: - _controller: \Drupal\inmail\Controller\FetcherController::enable + _entity_form: 'inmail_deliverer.default' + _title_callback: \Drupal\inmail\Controller\DelivererController::titleEdit requirements: _permission: 'administer inmail' -entity.inmail_fetcher.disable: - path: admin/config/system/inmail/fetchers/{inmail_fetcher}/disable +entity.inmail_deliverer.enable: + path: admin/config/system/inmail/deliverers/{inmail_deliverer}/enable defaults: - _controller: \Drupal\inmail\Controller\FetcherController::disable + _controller: \Drupal\inmail\Controller\DelivererController::enable + requirements: + _permission: 'administer inmail' + +entity.inmail_deliverer.disable: + path: admin/config/system/inmail/deliverers/{inmail_deliverer}/disable + defaults: + _controller: \Drupal\inmail\Controller\DelivererController::disable requirements: _permission: 'administer inmail' diff --git a/inmail.services.yml b/inmail.services.yml index 260e421..863b9ac 100644 --- a/inmail.services.yml +++ b/inmail.services.yml @@ -2,14 +2,14 @@ services: inmail.processor: class: Drupal\inmail\MessageProcessor arguments: ['@entity.manager', '@plugin.manager.inmail.analyzer', '@plugin.manager.inmail.handler', '@logger.channel.inmail'] - plugin.manager.inmail.fetcher: + plugin.manager.inmail.deliverer: class: Drupal\Core\Plugin\DefaultPluginManager arguments: - - 'Plugin/inmail/Fetcher' + - 'Plugin/inmail/Deliverer' - '@container.namespaces' - '@module_handler' - - 'Drupal\inmail\Plugin\inmail\Fetcher\FetcherInterface' - - 'Drupal\inmail\Annotation\Fetcher' + - 'Drupal\inmail\Plugin\inmail\Deliverer\DelivererInterface' + - 'Drupal\inmail\Annotation\Deliverer' plugin.manager.inmail.analyzer: class: Drupal\inmail\AnalyzerManager parent: default_plugin_manager diff --git a/inmail_collect/src/Plugin/inmail/Handler/CollectHandler.php b/inmail_collect/src/Plugin/inmail/Handler/CollectHandler.php index 235ed05..ddab6d5 100644 --- a/inmail_collect/src/Plugin/inmail/Handler/CollectHandler.php +++ b/inmail_collect/src/Plugin/inmail/Handler/CollectHandler.php @@ -71,7 +71,7 @@ class CollectHandler extends HandlerBase { 'header-from' => $message->getHeader()->getFieldBody('From'), 'header-message-id' => $message->getHeader()->getFieldBody('Message-Id'), 'raw' => $message->toString(), - // @todo Add fetcher reference here. Relevant if multiple present. + // @todo Add deliverer reference here. Relevant if multiple present. ); Container::create(array( diff --git a/src/Annotation/Fetcher.php b/src/Annotation/Deliverer.php similarity index 51% rename from src/Annotation/Fetcher.php rename to src/Annotation/Deliverer.php index f42a749..8beda56 100644 --- a/src/Annotation/Fetcher.php +++ b/src/Annotation/Deliverer.php @@ -1,7 +1,7 @@ get('plugin.manager.inmail.fetcher')); + return new static($container->get('plugin.manager.inmail.deliverer')); } /** - * Returns a title for the fetcher configuration edit page. + * Returns a title for the deliverer configuration edit page. */ - public function titleEdit(FetcherConfig $inmail_fetcher) { - return $this->t('Configure %label fetcher', array('%label' => $inmail_fetcher->label())); + public function titleEdit(DelivererConfig $inmail_deliverer) { + return $this->t('Configure deliverer %label', array('%label' => $inmail_deliverer->label())); } /** - * Enables a mail fetcher. + * Enables a mail deliverer. */ - public function enable(FetcherConfig $inmail_fetcher) { - $inmail_fetcher->enable()->save(); - return new RedirectResponse(\Drupal::url('inmail.fetcher_list', [], ['absolute' => TRUE])); + public function enable(DelivererConfig $inmail_deliverer) { + $inmail_deliverer->enable()->save(); + return new RedirectResponse(\Drupal::url('inmail.deliverer_list', [], ['absolute' => TRUE])); } /** - * Disables a mail fetcher. + * Disables a mail deliverer. */ - public function disable(FetcherConfig $inmail_fetcher) { - $inmail_fetcher->disable()->save(); - return new RedirectResponse(\Drupal::url('inmail.fetcher_list', [], ['absolute' => TRUE])); + public function disable(DelivererConfig $inmail_deliverer) { + $inmail_deliverer->disable()->save(); + return new RedirectResponse(\Drupal::url('inmail.deliverer_list', [], ['absolute' => TRUE])); } } diff --git a/src/FetcherListBuilder.php b/src/DelivererListBuilder.php similarity index 67% rename from src/FetcherListBuilder.php rename to src/DelivererListBuilder.php index a45a41d..c01b317 100644 --- a/src/FetcherListBuilder.php +++ b/src/DelivererListBuilder.php @@ -1,7 +1,7 @@ fetcherManager = $fetcher_manager; + $this->delivererManager = $deliverer_manager; } /** @@ -44,7 +42,7 @@ class FetcherListBuilder extends ConfigEntityListBuilder { return new static( $entity_type, $container->get('entity.manager')->getStorage($entity_type->id()), - $container->get('plugin.manager.inmail.fetcher') + $container->get('plugin.manager.inmail.deliverer') ); } @@ -52,7 +50,7 @@ class FetcherListBuilder extends ConfigEntityListBuilder { * {@inheritdoc} */ public function buildHeader() { - $row['label'] = $this->t('Fetcher'); + $row['label'] = $this->t('Deliverer'); $row['plugin'] = $this->t('Plugin'); return $row + parent::buildHeader(); } @@ -61,10 +59,10 @@ class FetcherListBuilder extends ConfigEntityListBuilder { * {@inheritdoc} */ public function buildRow(EntityInterface $entity) { - /** @var \Drupal\inmail\Entity\FetcherConfig $entity */ + /** @var \Drupal\inmail\Entity\DelivererConfig $entity */ $plugin_id = $entity->getPluginId(); - if ($this->fetcherManager->hasDefinition($plugin_id)) { - $plugin_label = $this->fetcherManager->getDefinition($plugin_id)['label']; + if ($this->delivererManager->hasDefinition($plugin_id)) { + $plugin_label = $this->delivererManager->getDefinition($plugin_id)['label']; } else { $plugin_label = $this->t('Plugin missing'); diff --git a/src/Entity/FetcherConfig.php b/src/Entity/DelivererConfig.php similarity index 33% rename from src/Entity/FetcherConfig.php rename to src/Entity/DelivererConfig.php index c67d3a2..cee6152 100644 --- a/src/Entity/FetcherConfig.php +++ b/src/Entity/DelivererConfig.php @@ -1,26 +1,27 @@ get('plugin.manager.inmail.fetcher'), - $container->get('entity.manager')->getStorage('inmail_fetcher') + $container->get('plugin.manager.inmail.deliverer'), + $container->get('entity.manager')->getStorage('inmail_deliverer') ); } @@ -36,7 +36,7 @@ class FetcherConfigurationForm extends PluginConfigurationForm { public function submitForm(array &$form, FormStateInterface $form_state) { parent::submitForm($form, $form_state); - $form_state->setRedirect('inmail.fetcher_list'); + $form_state->setRedirect('inmail.deliverer_list'); } } diff --git a/src/Form/PluginConfigurationForm.php b/src/Form/PluginConfigurationForm.php index 3be2bcc..2da3b02 100644 --- a/src/Form/PluginConfigurationForm.php +++ b/src/Form/PluginConfigurationForm.php @@ -46,15 +46,11 @@ class PluginConfigurationForm extends EntityForm { /** @var \Drupal\inmail\Entity\PluginConfigEntity $entity */ $entity = $this->getEntity(); - // Load plugin instance. - /** @var \Drupal\Core\Plugin\PluginFormInterface $plugin */ - $plugin = $this->pluginManager->createInstance($entity->getPluginId(), $entity->getConfiguration()); - $form_state->set('plugin', $plugin); - $form['label'] = array( '#title' => $this->t('Label'), '#type' => 'textfield', '#default_value' => $entity->label(), + '#required' => TRUE, ); $form['id'] = array( @@ -72,7 +68,46 @@ class PluginConfigurationForm extends EntityForm { '#default_value' => TRUE, ); - $form['configuration'] = $plugin->buildConfigurationForm(array(), $form_state); + $form['plugin_container'] = array( + '#type' => 'container', + '#prefix' => '