diff --git a/inmail.module b/inmail.module index a7e91a8..a6494de 100644 --- a/inmail.module +++ b/inmail.module @@ -317,35 +317,16 @@ function inmail_mail($key, &$message, $params) { $header->addField('X-Inmail-Forwarded', 'handler_moderator_forward'); $message['raw_headers'] = $header; break; + case 'success': + /** @var \Drupal\inmail\MIME\MessageInterface $result */ + $original = $params['original']; + $message['subject'] = 'Re: ' . $original->getSubject(); + $message['from'] = $original->getFrom(); + $message['id'] = $original->getMessageId(); + $message['cc'] = $original->getCc(); + $message['body'] = 'Reply.'; + break; } - - /** @var \Drupal\inmail\ProcessorResultInterface $result */ - $result = $params['original']; - - /** @var \Drupal\monitoring\SensorConfigInterface $sensor_config */ -// $sensor_config = $params['sensor_config']; - - // Set the mail subject. - $status = $result->getStatusLabel(); - $subject = strtoupper($status) . ': ' . $result->getValue() . ' ' . $sensor_config->getLabel(); - $message['subject'] = $subject; - - // Set the mail body. - $body = []; - $body[] = 'Mail sent.'; - $body[] = ''; - $body[] = $result->readLog(); - $message['body'] = $body; - - // Set the mail sender. - $site_config = \Drupal::config('system.site'); - $site_mail = $site_config->get('mail'); - $site_name = $site_config->get('name'); - $message['from'] = 'INMAIL ' . $site_name . ' <' . $site_mail . '>'; - - // Set the header message id. - $message_id = '<' . $result->getSensorId() . '.' . time() . '@' . \Drupal::request()->getHost() . '>'; - $message['headers']['message-id'] = $message_id; } /** diff --git a/src/Form/PluginConfigurationForm.php b/src/Form/PluginConfigurationForm.php index b7115dc..f48e280 100644 --- a/src/Form/PluginConfigurationForm.php +++ b/src/Form/PluginConfigurationForm.php @@ -29,11 +29,19 @@ class PluginConfigurationForm extends EntityForm { protected $storage; /** + * Send the whole log as message body. + * + * @var bool + */ + protected $sendLog; + + /** * {@inheritdoc} */ public function __construct(PluginManagerInterface $plugin_manager, ConfigEntityStorageInterface $storage) { $this->pluginManager = $plugin_manager; $this->storage = $storage; + $this->sendLog = FALSE; } /** @@ -66,6 +74,12 @@ class PluginConfigurationForm extends EntityForm { '#default_value' => $entity->status(), ); + $form['log'] = [ + '#title' => $this->t('Attache log'), + '#type' => 'checkbox', + '#default_value' => $this->sendLog, + ]; + $form['plugin_container'] = array( '#type' => 'container', '#prefix' => '
', @@ -191,6 +205,7 @@ class PluginConfigurationForm extends EntityForm { /** @var \Drupal\inmail\Entity\PluginConfigEntity $entity */ $entity = $this->getEntity(); $entity->setConfiguration($plugin->getConfiguration()); + $this->sendLog = $form_state->get('log'); } } diff --git a/src/MessageProcessor.php b/src/MessageProcessor.php index 2c14b4e..363942f 100644 --- a/src/MessageProcessor.php +++ b/src/MessageProcessor.php @@ -172,9 +172,8 @@ class MessageProcessor implements MessageProcessorInterface { $params['result'] = $result; // Sending message. $recipient = $message->getFrom(); -// $recipient = 'bla@bal@ga'; $mail_manager = \Drupal::service('plugin.manager.mail'); - $mail_manager->mail('inmail_success', 'Success', $recipient, \Drupal::languageManager()->getDefaultLanguage()->getId(), $params); + $mail_manager->mail('inmail_success', 'success', $recipient, \Drupal::languageManager()->getDefaultLanguage()->getId(), $params); } catch (ParseException $e) { diff --git a/tests/src/Kernel/ModeratorForwardTest.php b/tests/src/Kernel/ModeratorForwardTest.php index fa3c87c..3da83fe 100644 --- a/tests/src/Kernel/ModeratorForwardTest.php +++ b/tests/src/Kernel/ModeratorForwardTest.php @@ -54,7 +54,7 @@ class ModeratorForwardTest extends KernelTestBase { $processor->process('unique_key', $bounce, $deliverer); // Message passed all tests, parsings and thus success is called. $this->assertSuccess($deliverer, 'unique_key'); - $this->assertMailCount(0); + $this->assertMailCount(1); // Do not handle if moderator address is unset. /** @var \Drupal\inmail\Entity\HandlerConfig $handler_config */ @@ -64,7 +64,7 @@ class ModeratorForwardTest extends KernelTestBase { $deliverer = $this->createTestDeliverer(); $processor->process('unique_key', $regular, $deliverer); $this->assertSuccess($deliverer, 'unique_key'); - $this->assertMailCount(0); + $this->assertMailCount(2); // Do not handle, and log an error, if moderator address is same as intended // recipient. @@ -74,7 +74,7 @@ class ModeratorForwardTest extends KernelTestBase { $deliverer = $this->createTestDeliverer(); $processor->process('unique_key', $bounce_no_status, $deliverer); $this->assertSuccess($deliverer, 'unique_key'); - $this->assertMailCount(0); + $this->assertMailCount(3); // Check the Past event created by the processor. $events = \Drupal::entityTypeManager()->getStorage('past_event')->loadMultiple(); @@ -93,7 +93,7 @@ class ModeratorForwardTest extends KernelTestBase { $deliverer = $this->createTestDeliverer(); $processor->process('unique_key', $regular_x, $deliverer); $this->assertSuccess($deliverer, 'unique_key'); - $this->assertMailCount(0); + $this->assertMailCount(4); // Again check past event log. $events = \Drupal::entityTypeManager()->getStorage('past_event')->loadMultiple(); @@ -107,7 +107,16 @@ class ModeratorForwardTest extends KernelTestBase { $deliverer = $this->createTestDeliverer(); $processor->process('unique_key', $regular, $deliverer); $this->assertSuccess($deliverer, 'unique_key'); - $this->assertMailCount(1); + $this->assertMailCount(6); + + // Set a valid email address for this test. + \Drupal::configFactory() + ->getEditable('system.site') + ->set('mail', 'mail@example.com') + ->save(); + $processor->process('unique_key', $regular, $deliverer); + $this->assertMailString('body', 'Reply', 1); + } /**