From f61b021fb8160e433a713eab1b9644fcfa7d7292 Mon Sep 17 00:00:00 2001 From: Herb vd Dool Date: Wed, 1 Aug 2018 14:52:44 -0400 Subject: [PATCH] initial port to Backdrop --- README.md | 81 ++++++++++ README.txt | 90 ----------- config/maillog.settings.json | 7 + config/views.view.maillog.json | 143 ++++++++++++++++++ includes/maillog.mail.inc | 22 +-- includes/maillog.views.inc | 3 +- includes/maillog.views_default.inc | 128 ---------------- ...andler_field_maillog_entry_link_delete.inc | 5 +- ...llog_handler_field_maillog_link_delete.inc | 3 +- maillog.info | 10 +- maillog.install | 39 +++-- maillog.module | 46 ++++-- tests/maillog.tests.info | 5 + tests/maillog.unit.test | 62 +++----- tests/maillog_tests.info | 3 +- 15 files changed, 341 insertions(+), 306 deletions(-) create mode 100644 README.md delete mode 100644 README.txt create mode 100644 config/maillog.settings.json create mode 100644 config/views.view.maillog.json delete mode 100644 includes/maillog.views_default.inc create mode 100644 tests/maillog.tests.info diff --git a/README.md b/README.md new file mode 100644 index 0000000..c3b1778 --- /dev/null +++ b/README.md @@ -0,0 +1,81 @@ +Maillog +------- +The Maillog module provides a method of keeping archival copies of all emails +sent through the site. It can also, optionally, display a copy of the email +using the Devel module, if present. + +Features +-------------------------------------------------------------------------------- +* All emails being sent by the site may have a copy stored in the database for + later review. + +* All email delivery may be halted, preventing a site from sending out emails + in situations where that might not be needed, e.g. for a local development + copy of the site. + +* If the Devel module https://www.backdropcms.org/project/devel is installed, emails + can also be displayed on the page as they are being sent. + +* If the MailSystem module https://www.backdropcms.org/project/mailsystem is + installed it is possible to control which of the installed email modules will + be used to send messages from Maillog's settings page, mirroring MailSystem's + functionality. + +Configuration +-------------------------------------------------------------------------------- + 1. On the User Accounts Permissions administration page ("Administer >> Configure + >> People >> Permissions") there are three permissions to control: + + - The "Administer Maillog" permission allows users to access the settings + page to control the module's options. + + - The "View Maillog" permission allows users to access the Maillog list page + at admin/reports/maillog. + + - The "Delete Entries from the log" permission allows users to delete items + from the log page. + + 2. The main administrative page controls the module's settings page: + admin/config/development/maillog + + +Troubleshooting / known issues +-------------------------------------------------------------------------------- +If the email is not being logged then the site's default email system is not +configured correctly. It is recommended to use the MailSystem module +https://www.backdropcms.org/project/mailsystem to help with this. Alternatively, edit +the system.mail.json file in your active config folder: + +``` + "default-system": "MaillogMailSystem", +``` + +Related modules +-------------------------------------------------------------------------------- +Some similar modules that are available include: + +* Reroute Email + Reroutes outbound emails to a specific destination address. + http://backdropcms.org/project/reroute_email + +License +------- + +This project is GPL v2 software. See the LICENSE.txt file in this directory for +complete text. + + +Current Maintainers +------------------- + +- Seeking maintainers. + +Credits +------- + +- Ported to Backdrop CMS by herbdool (https://github.com/herbdool). + +This module is a port of the SMTP module for Drupal which was written and maintained by a large number of contributors, including: + +Maintained by Miro Dietiker https://www.drupal.org/u/miro_dietiker, Sascha Grossenbacher https://www.drupal.org/u/berdir and Damien McKenna +https://www.drupal.org/u/damiemckenna. diff --git a/README.txt b/README.txt deleted file mode 100644 index 174b4af..0000000 --- a/README.txt +++ /dev/null @@ -1,90 +0,0 @@ -Maillog -------- -The Maillog module provides a method of keeping archival copies of all emails -sent through the site. It can also, optionally, display a copy of the email -using the Devel module [1], if present. - - -Features --------------------------------------------------------------------------------- -* All emails being sent by the site may have a copy stored in the database for - later review. - -* All email delivery may be halted, preventing a site from sending out emails - in situations where that might not be needed, e.g. for a local development - copy of the site. - -* If the Devel module is installed [1], emails can also be displayed on the page - as they are being sent. - -* If the MailSystem module [2] is installed it is possible to control which of - the installed email modules will be used to send messages from Maillog's - settings page, mirroring MailSystem's functionality. - - -Configuration --------------------------------------------------------------------------------- - 1. On the People Permissions administration page ("Administer >> People - >> Permissions") there are three permissions to control: - - - The "Administer Maillog" permission allows users to access the settings - page to control the module's options. - - - The "View Maillog" permission allows users to access the Maillog list page - at admin/reports/maillog. - - - The "Delete Entries from the log" permission allows users to delete items - from the log page. - - 2. The main administrative page controls the module's settings page: - admin/config/development/maillog - - -Troubleshooting / known issues --------------------------------------------------------------------------------- -If the email is not being logged then the site's default email system is not -configured correctly. It is recommended to use the MailSystem module [2] to help -with this. Alternatively, add the following to the enf of the site's -settings.php file: - -// Control which module is responsible for sending the site's emails. -$conf['mail_system'] = array( - 'default-system' => 'MaillogMailSystem', -); - - -Related modules --------------------------------------------------------------------------------- -Some similar modules that are available include: - -* Reroute Email - Reroutes outbound emails to a specific destination address. - http://drupal.org/project/reroute_email - -* Advanced Mail Reroute - Reroutes outbound emails with complete control over the destination based upon - the email's key. - http://drupal.org/project/advanced_mail_reroute - -* Mail Logger - Logs all emails sent through the site. - http://drupal.org/project/mail_logger - - -Credits / contact --------------------------------------------------------------------------------- -Maintained by Miro Dietiker [3], Sascha Grossenbacher [4] and Damien McKenna -[5]. - -The best way to contact the authors is to submit an issue, be it a support -request, a feature request or a bug report, in the project issue queue: - https://www.drupal.org/project/issues/maillog - - -References --------------------------------------------------------------------------------- -1: https://www.drupal.org/project/devel -2: https://www.drupal.org/project/mailsystem -3: https://www.drupal.org/u/miro_dietiker -4: https://www.drupal.org/u/berdir -5: https://www.drupal.org/u/damiemckenna diff --git a/config/maillog.settings.json b/config/maillog.settings.json new file mode 100644 index 0000000..ac66f77 --- /dev/null +++ b/config/maillog.settings.json @@ -0,0 +1,7 @@ +{ + "_config_name": "maillog.settings", + "maillog_send": 1, + "maillog_log": 1, + "maillog_devel": 1, + "maillog_engine": "DefaultMailSystem" +} diff --git a/config/views.view.maillog.json b/config/views.view.maillog.json new file mode 100644 index 0000000..cfe9b06 --- /dev/null +++ b/config/views.view.maillog.json @@ -0,0 +1,143 @@ +{ + "_config_name": "views.view.maillog", + "name": "maillog", + "description": "Displays the list of e-mails logged by the 'Mail Log' module.", + "module": "maillog", + "storage": 4, + "tag": "", + "disabled": false, + "base_table": "maillog", + "human_name": "Mail Log Report", + "core": "1.0", + "display": { + "default": { + "display_title": "Defaults", + "display_plugin": "default", + "display_options": { + "query": { + "type": "views_query", + "options": [] + }, + "title": "Maillog", + "use_more_always": false, + "access": { + "type": "perm", + "perm": "view maillog" + }, + "cache": { + "type": "none" + }, + "exposed_form": { + "type": "basic" + }, + "pager": { + "type": "none" + }, + "style_plugin": "table", + "empty": { + "area_text_custom": { + "id": "area_text_custom", + "table": "views", + "field": "area_text_custom", + "label": "Maillog", + "empty": true, + "content": "Maillog is currently empty. Send a mail!" + } + }, + "fields": { + "idmaillog": { + "id": "idmaillog", + "table": "maillog", + "field": "idmaillog", + "exclude": true + }, + "sent_date": { + "id": "sent_date", + "table": "maillog", + "field": "sent_date" + }, + "header_message_id": { + "id": "header_message_id", + "table": "maillog", + "field": "header_message_id" + }, + "subject": { + "id": "subject", + "table": "maillog", + "field": "subject", + "alter": { + "make_link": true, + "path": "maillog/details/[idmaillog]" + } + }, + "header_from": { + "id": "header_from", + "table": "maillog", + "field": "header_from" + }, + "header_to": { + "id": "header_to", + "table": "maillog", + "field": "header_to" + }, + "nothing": { + "id": "nothing", + "table": "views", + "field": "nothing", + "label": "", + "exclude": true, + "alter": { + "text": "view", + "make_link": true, + "path": "maillog/details/[idmaillog]" + }, + "element_label_colon": false + }, + "delete_maillog": { + "id": "delete_maillog", + "table": "maillog", + "field": "delete_maillog", + "label": "", + "exclude": true, + "element_label_colon": false + }, + "nothing_1": { + "id": "nothing_1", + "table": "views", + "field": "nothing", + "label": "Actions", + "alter": { + "text": "[nothing] | [delete_maillog]" + } + } + }, + "sorts": { + "sent_date": { + "id": "sent_date", + "table": "maillog", + "field": "sent_date", + "order": "DESC" + } + } + } + }, + "page_1": { + "display_title": "Page", + "display_plugin": "page", + "display_options": { + "query": { + "type": "views_query", + "options": [] + }, + "path": "admin/reports/maillog", + "menu": { + "type": "normal", + "title": "Maillog", + "description": "Show the logged mails", + "weight": "0", + "name": "management" + } + } + } + } +} diff --git a/includes/maillog.mail.inc b/includes/maillog.mail.inc index 7250aaf..8f4d172 100644 --- a/includes/maillog.mail.inc +++ b/includes/maillog.mail.inc @@ -5,7 +5,7 @@ */ class MaillogMailSystem implements MailSystemInterface { /** - * Format a message composed by drupal_mail() prior sending. + * Format a message composed by backdrop_mail() prior sending. * * @param $message * A message array, as described in hook_mail_alter(). @@ -14,13 +14,13 @@ class MaillogMailSystem implements MailSystemInterface { * The formatted $message. */ public function format(array $message) { - $mailclass = variable_get('maillog_engine', 'DefaultMailSystem'); + $mailclass = config_get('maillog.settings', 'maillog_engine'); $default = new $mailclass(); return $default->format($message); } /** - * Send a message composed by drupal_mail(). + * Send a message composed by backdrop_mail(). * * @param $message * Message array with at least the following elements: @@ -35,7 +35,7 @@ class MaillogMailSystem implements MailSystemInterface { * - subject: Subject of the e-mail to be sent. This must not contain any * newline characters, or the mail may not be sent properly. * - body: Message to be sent. Accepts both CRLF and LF line-endings. - * E-mail bodies must be wrapped. You can use drupal_wrap_mail() for + * E-mail bodies must be wrapped. You can use backdrop_wrap_mail() for * smart plain text wrapping. * - headers: Associative array containing all additional mail headers not * defined by one of the other parameters. PHP's mail() looks for Cc @@ -46,14 +46,14 @@ class MaillogMailSystem implements MailSystemInterface { */ public function mail(array $message) { // Log the e-mail - if (variable_get('maillog_log', TRUE)) { + if (config_get('maillog.settings', 'maillog_log')) { $record = new stdClass; // In case the subject/from/to is already encoded, decode with mime_header_decode $record->header_message_id = isset($message['headers']['Message-ID']) ? $message['headers']['Message-ID'] : NULL; $record->subject = $message['subject']; $record->subject = mime_header_decode($record->subject); - $record->subject = drupal_substr($record->subject, 0, 255); + $record->subject = backdrop_substr($record->subject, 0, 255); $record->body = $message['body']; $record->header_from = isset($message['from']) ? $message['from'] : NULL; $record->header_from = mime_header_decode($record->header_from); @@ -75,11 +75,11 @@ class MaillogMailSystem implements MailSystemInterface { $record->header_all = serialize($message['headers']); $record->sent_date = REQUEST_TIME; - drupal_write_record('maillog', $record); + backdrop_write_record('maillog', $record); } // Display the e-mail using Devel module - if (variable_get('maillog_devel', TRUE) && function_exists('dpm')) { + if (config_get('maillog.settings', 'maillog_devel') && function_exists('dpm')) { $devel_msg = array(); $devel_msg[t('Subject')] = $message['subject']; $devel_msg[t('From')] = $message['from']; @@ -91,15 +91,15 @@ class MaillogMailSystem implements MailSystemInterface { dpm($devel_msg, 'maillog'); } - if (variable_get('maillog_send', TRUE)) { - $mailclass = variable_get('maillog_engine', 'DefaultMailSystem'); + if (config_get('maillog.settings', 'maillog_send')) { + $mailclass = config_get('maillog.settings', 'maillog_engine'); $default = new $mailclass(); $result = $default->mail($message); } elseif (user_access('administer maillog')) { $message = t('Sending of e-mail messages is disabled by Maillog module. Go here to enable.', array('@href' => url('admin/reports/maillog'))); - drupal_set_message($message, 'warning', TRUE); + backdrop_set_message($message, 'warning', TRUE); } else { global $user; diff --git a/includes/maillog.views.inc b/includes/maillog.views.inc index cf5619b..682f293 100644 --- a/includes/maillog.views.inc +++ b/includes/maillog.views.inc @@ -197,7 +197,7 @@ function maillog_views_data() { function maillog_views_handlers() { return array( 'info' => array( - 'path' => drupal_get_path('module', 'maillog') . '/includes', + 'path' => backdrop_get_path('module', 'maillog') . '/includes', ), 'handlers' => array( // field handlers @@ -207,4 +207,3 @@ function maillog_views_handlers() { ), ); } - diff --git a/includes/maillog.views_default.inc b/includes/maillog.views_default.inc deleted file mode 100644 index 5b6700c..0000000 --- a/includes/maillog.views_default.inc +++ /dev/null @@ -1,128 +0,0 @@ -name = 'Maillog'; - $view->description = 'Displays the list of e-mails logged by the \'Mail Log\' module.'; - $view->tag = ''; - $view->base_table = 'maillog'; - $view->human_name = ''; - $view->core = 0; - $view->api_version = '3.0'; - $view->disabled = FALSE; /* Edit this to true to make a default view disabled initially */ - - /* Display: Defaults */ - $handler = $view->new_display('default', 'Defaults', 'default'); - $handler->display->display_options['title'] = 'Maillog'; - $handler->display->display_options['use_more_always'] = FALSE; - $handler->display->display_options['access']['type'] = 'perm'; - $handler->display->display_options['access']['perm'] = 'view maillog'; - $handler->display->display_options['cache']['type'] = 'none'; - $handler->display->display_options['query']['type'] = 'views_query'; - $handler->display->display_options['exposed_form']['type'] = 'basic'; - $handler->display->display_options['pager']['type'] = 'none'; - $handler->display->display_options['style_plugin'] = 'table'; - /* No results behavior: Global: Unfiltered text */ - $handler->display->display_options['empty']['area_text_custom']['id'] = 'area_text_custom'; - $handler->display->display_options['empty']['area_text_custom']['table'] = 'views'; - $handler->display->display_options['empty']['area_text_custom']['field'] = 'area_text_custom'; - $handler->display->display_options['empty']['area_text_custom']['label'] = 'Maillog'; - $handler->display->display_options['empty']['area_text_custom']['empty'] = TRUE; - $handler->display->display_options['empty']['area_text_custom']['content'] = 'Maillog is currently empty. Send a mail!'; - /* Field: Maillog: Maillog_ID */ - $handler->display->display_options['fields']['idmaillog']['id'] = 'idmaillog'; - $handler->display->display_options['fields']['idmaillog']['table'] = 'maillog'; - $handler->display->display_options['fields']['idmaillog']['field'] = 'idmaillog'; - $handler->display->display_options['fields']['idmaillog']['exclude'] = TRUE; - /* Field: Maillog: Date */ - $handler->display->display_options['fields']['sent_date']['id'] = 'sent_date'; - $handler->display->display_options['fields']['sent_date']['table'] = 'maillog'; - $handler->display->display_options['fields']['sent_date']['field'] = 'sent_date'; - /* Field: Maillog: Message_ID */ - $handler->display->display_options['fields']['header_message_id']['id'] = 'header_message_id'; - $handler->display->display_options['fields']['header_message_id']['table'] = 'maillog'; - $handler->display->display_options['fields']['header_message_id']['field'] = 'header_message_id'; - /* Field: Maillog: Subject */ - $handler->display->display_options['fields']['subject']['id'] = 'subject'; - $handler->display->display_options['fields']['subject']['table'] = 'maillog'; - $handler->display->display_options['fields']['subject']['field'] = 'subject'; - $handler->display->display_options['fields']['subject']['alter']['make_link'] = TRUE; - $handler->display->display_options['fields']['subject']['alter']['path'] = 'maillog/details/[idmaillog]'; - /* Field: Maillog: From */ - $handler->display->display_options['fields']['header_from']['id'] = 'header_from'; - $handler->display->display_options['fields']['header_from']['table'] = 'maillog'; - $handler->display->display_options['fields']['header_from']['field'] = 'header_from'; - /* Field: Maillog: To */ - $handler->display->display_options['fields']['header_to']['id'] = 'header_to'; - $handler->display->display_options['fields']['header_to']['table'] = 'maillog'; - $handler->display->display_options['fields']['header_to']['field'] = 'header_to'; - /* Field: Global: Custom text */ - $handler->display->display_options['fields']['nothing']['id'] = 'nothing'; - $handler->display->display_options['fields']['nothing']['table'] = 'views'; - $handler->display->display_options['fields']['nothing']['field'] = 'nothing'; - $handler->display->display_options['fields']['nothing']['label'] = ''; - $handler->display->display_options['fields']['nothing']['exclude'] = TRUE; - $handler->display->display_options['fields']['nothing']['alter']['text'] = 'view'; - $handler->display->display_options['fields']['nothing']['alter']['make_link'] = TRUE; - $handler->display->display_options['fields']['nothing']['alter']['path'] = 'maillog/details/[idmaillog]'; - $handler->display->display_options['fields']['nothing']['element_label_colon'] = FALSE; - /* Field: Maillog: Delete link */ - $handler->display->display_options['fields']['delete_maillog']['id'] = 'delete_maillog'; - $handler->display->display_options['fields']['delete_maillog']['table'] = 'maillog'; - $handler->display->display_options['fields']['delete_maillog']['field'] = 'delete_maillog'; - $handler->display->display_options['fields']['delete_maillog']['label'] = ''; - $handler->display->display_options['fields']['delete_maillog']['exclude'] = TRUE; - $handler->display->display_options['fields']['delete_maillog']['element_label_colon'] = FALSE; - /* Field: Global: Custom text */ - $handler->display->display_options['fields']['nothing_1']['id'] = 'nothing_1'; - $handler->display->display_options['fields']['nothing_1']['table'] = 'views'; - $handler->display->display_options['fields']['nothing_1']['field'] = 'nothing'; - $handler->display->display_options['fields']['nothing_1']['label'] = 'Actions'; - $handler->display->display_options['fields']['nothing_1']['alter']['text'] = '[nothing] | [delete_maillog]'; - /* Sort criterion: Maillog: Date */ - $handler->display->display_options['sorts']['sent_date']['id'] = 'sent_date'; - $handler->display->display_options['sorts']['sent_date']['table'] = 'maillog'; - $handler->display->display_options['sorts']['sent_date']['field'] = 'sent_date'; - $handler->display->display_options['sorts']['sent_date']['order'] = 'DESC'; - - /* Display: Page */ - $handler = $view->new_display('page', 'Page', 'page_1'); - $handler->display->display_options['path'] = 'admin/reports/maillog'; - $handler->display->display_options['menu']['type'] = 'normal'; - $handler->display->display_options['menu']['title'] = 'Maillog'; - $handler->display->display_options['menu']['description'] = 'Show the logged mails'; - $handler->display->display_options['menu']['weight'] = '0'; - $handler->display->display_options['menu']['name'] = 'management'; - $translatables['Maillog'] = array( - t('Defaults'), - t('Maillog'), - t('more'), - t('Apply'), - t('Reset'), - t('Sort by'), - t('Asc'), - t('Desc'), - t('Maillog is currently empty. Send a mail!'), - t('Maillog_ID'), - t('Date'), - t('Message_ID'), - t('Subject'), - t('From'), - t('To'), - t('view'), - t('Actions'), - t('[nothing] | [delete_maillog]'), - t('Page'), - ); - - $views[$view->name] = $view; - return $views; -} diff --git a/includes/maillog_handler_field_maillog_entry_link_delete.inc b/includes/maillog_handler_field_maillog_entry_link_delete.inc index 83fddbf..008eec0 100644 --- a/includes/maillog_handler_field_maillog_entry_link_delete.inc +++ b/includes/maillog_handler_field_maillog_entry_link_delete.inc @@ -1,4 +1,4 @@ -options['text']) ? $this->options['text'] : t('delete'); - return l($text, "maillog/delete/$values->maillog_id", array('query' => drupal_get_destination())); + return l($text, "maillog/delete/$values->maillog_id", array('query' => backdrop_get_destination())); } } - diff --git a/includes/maillog_handler_field_maillog_link_delete.inc b/includes/maillog_handler_field_maillog_link_delete.inc index 90c4d38..df4faa9 100644 --- a/includes/maillog_handler_field_maillog_link_delete.inc +++ b/includes/maillog_handler_field_maillog_link_delete.inc @@ -25,7 +25,6 @@ class maillog_handler_field_maillog_link_delete extends views_handler_field { return; } $text = !empty($this->options['text']) ? $this->options['text'] : t('delete'); - return l($text, "maillog/delete/$values->idmaillog", array('query' => drupal_get_destination())); + return l($text, "maillog/delete/$values->idmaillog", array('query' => backdrop_get_destination())); } } - diff --git a/maillog.info b/maillog.info index a201749..eeac24f 100644 --- a/maillog.info +++ b/maillog.info @@ -1,15 +1,9 @@ name = Maillog / Mail Developer description = Utility to log all Mails for debugging purposes. It's possible to suppress mail delivery for e.g. dev or staging systems. package = Mail -core = 7.x +backdrop = 1.x +type = module dependencies[] = views configure = admin/config/development/maillog - -files[] = includes/maillog.mail.inc -files[] = includes/maillog_handler_field_maillog_entry_link_delete.inc -files[] = includes/maillog_handler_field_maillog_link_delete.inc - -; Tests. -files[] = tests/maillog.unit.test diff --git a/maillog.install b/maillog.install index 14c4c3e..69cb0dd 100644 --- a/maillog.install +++ b/maillog.install @@ -13,7 +13,7 @@ function maillog_enable() { $default_class = 'DefaultMailSystem'; // Load the current mail configuration. - $mail_system = variable_get('mail_system', array('default-system' => $default_class)); + $mail_system['default-system'] = config_get('system.mail', 'default-system'); $mail_system['maillog'] = 'MaillogMailSystem'; // If maillog is enabled, don't take over the default @@ -21,11 +21,11 @@ function maillog_enable() { $mail_system['default-system'] = $mail_system['maillog']; } else { - drupal_set_message(t('The Maillog module was not set as the default email system because another module is already handling email.')); + backdrop_set_message(t('The Maillog module was not set as the default email system because another module is already handling email.')); } // Update the settings. - variable_set('mail_system', $mail_system); + config_set('system.mail', 'default-system', $mail_system['default-system']); // The maillog reports page is provided by a view, but it needs a menu cache // clear after the default views are loaded in order for the menu item to @@ -33,8 +33,8 @@ function maillog_enable() { global $language; cache_clear_all('ctools_plugin_files:ctools:export_ui', 'cache'); cache_clear_all('ctools_plugin_type_info', 'cache'); - cache_clear_all('views:plugin_data:' . $language->language, 'cache'); - variable_set('menu_rebuild_needed', TRUE); + cache_clear_all('views:plugin_data:' . $language->langcode, 'cache'); + state_set('menu_rebuild_needed', TRUE); } /** @@ -42,7 +42,8 @@ function maillog_enable() { */ function maillog_disable() { // Get the current mail system config. - $mail_system = variable_get('mail_system', array('default-system' => 'DefaultMailSystem')); + $config = config('system.mail'); + $mail_system = $config->get(); // Delete any overrides that might be set for Maillog. unset($mail_system['maillog']); @@ -69,7 +70,8 @@ function maillog_disable() { } // Update the mail config. - variable_set('mail_system', $mail_system); + $config->setData($mail_system); + $config->save(); } /** @@ -139,11 +141,22 @@ function maillog_schema() { } /** - * Implements hook_uninstall(). + * Update webforms from Drupal to Backdrop. */ -function maillog_uninstall() { - variable_del('maillog_devel'); - variable_del('maillog_log'); - variable_del('maillog_send'); - variable_del('maillog_engine'); +function maillog_update_1000() { + $config = config('maillog.settings'); + + // migrate variables + $config->set('maillog_send', update_variable_get('maillog_send', TRUE)); + $config->set('maillog_log', update_variable_get('maillog_log', TRUE)); + $config->set('maillog_devel', update_variable_get('maillog_devel', TRUE)); + $config->set('maillog_engine', update_variable_get('maillog_engine', 'DefaultMailSystem')); + + $config->save(); + + // Delete variables. + update_variable_del('maillog_'); + update_variable_del('maillog_'); + update_variable_del('maillog_'); + update_variable_del('maillog_'); } diff --git a/maillog.module b/maillog.module index 8bb135b..d269a58 100644 --- a/maillog.module +++ b/maillog.module @@ -12,10 +12,32 @@ * Please install mimemail to make the outgoing engine pluggable. * * mail flow: - * drupal_mail -> maillog:drupal_mail_wrapper -> maillog_mail_send + * backdrop_mail -> maillog:backdrop_mail_wrapper -> maillog_mail_send * mimemail -> maillog_mailengine -> maillog_mail_send [-> ANY_engine] */ +/** + * Implements hook_config_info(). + */ +function maillog_config_info() { + $prefixes['maillog.settings'] = array( + 'label' => t('Maillog settings'), + 'group' => t('Configuration'), + ); + return $prefixes; +} + +/** + * Implements hook_autoload_info(). + */ +function maillog_autoload_info() { + return array( + 'MaillogMailSystem' => 'includes/maillog.mail.inc', + 'maillog_handler_field_maillog_entry_link_delete' => 'includes/maillog_handler_field_maillog_entry_link_delete.inc', + 'maillog_handler_field_maillog_link_delete' => 'includes/maillog_handler_field_maillog_link_delete.inc', + ); +} + /** * Implementation of hook_permision(). */ @@ -45,7 +67,7 @@ function maillog_menu() { $items['admin/config/development/maillog'] = array( 'title' => t('Maillog Settings'), 'description' => t('Configure the settings of Maillog module.'), - 'page callback' => 'drupal_get_form', + 'page callback' => 'backdrop_get_form', 'page arguments' => array('maillog_admin_settings'), 'access arguments' => array('administer maillog'), 'type' => MENU_NORMAL_ITEM, @@ -118,12 +140,12 @@ function maillog_maillog_delete($maillog) { $idmaillog = $maillog['idmaillog']; $result = db_query("DELETE FROM {maillog} WHERE idmaillog = :id", array(':id' => $idmaillog)); if ($result == FALSE) { - drupal_set_message(t('A Problem occured when deleting Mail with ID !idmaillog !', array('!idmaillog' => $idmaillog))); + backdrop_set_message(t('A Problem occured when deleting Mail with ID !idmaillog !', array('!idmaillog' => $idmaillog))); } else { - drupal_set_message(t('Mail with ID !idmaillog has been deleted!', array('!idmaillog' => $idmaillog))); + backdrop_set_message(t('Mail with ID !idmaillog has been deleted!', array('!idmaillog' => $idmaillog))); } - drupal_goto('admin/reports/maillog'); + backdrop_goto('admin/reports/maillog'); } /** @@ -142,34 +164,36 @@ function maillog_maillog_page($maillog) { * Implementation of the module settings form. */ function maillog_admin_settings() { + $config = config('maillog.settings'); $form = array(); + $form['#config'] = 'maillog.settings'; $form['maillog_send'] = array( '#type' => 'checkbox', '#title' => t("Allow the e-mails to be sent."), - '#default_value' => variable_get('maillog_send', TRUE), + '#default_value' => $config->get('maillog_send'), ); $form['maillog_log'] = array( '#type' => 'checkbox', '#title' => t("Create table entries in maillog table for each e-mail."), - '#default_value' => variable_get('maillog_log', TRUE), + '#default_value' => $config->get('maillog_log'), ); $form['maillog_devel'] = array( '#type' => 'checkbox', '#title' => t("Display the e-mails on page using devel module (if enabled)."), - '#default_value' => variable_get('maillog_devel', TRUE), + '#default_value' => $config->get('maillog_devel'), ); if (module_exists('mailsystem')) { $mailsystem_classes = mailsystem_get_classes(); - // maillog will be unset, because ist would cause an recursion + // maillog will be unset, because it would cause an recursion unset($mailsystem_classes['MaillogMailSystem']); $form['maillog_engine'] = array( '#type' => 'select', '#title' => t("Select the mail system which should be used."), - '#default_value' => variable_get('maillog_engine', 'DefaultMailSystem'), + '#default_value' => $config->get('maillog_engine'), '#options' => $mailsystem_classes, ); } @@ -183,7 +207,7 @@ function maillog_admin_settings() { function maillog_views_api() { return array( 'api' => 3, - 'path' => drupal_get_path('module', 'maillog') . '/includes/', + 'path' => backdrop_get_path('module', 'maillog') . '/includes/', ); } diff --git a/tests/maillog.tests.info b/tests/maillog.tests.info new file mode 100644 index 0000000..427e037 --- /dev/null +++ b/tests/maillog.tests.info @@ -0,0 +1,5 @@ +[MaillogUnitTest] +name = Maillog unit tests +description = Test the main Maillog functionality. +group = Maillog +file = maillog.unit.test diff --git a/tests/maillog.unit.test b/tests/maillog.unit.test index 9276cba..806d26f 100644 --- a/tests/maillog.unit.test +++ b/tests/maillog.unit.test @@ -4,18 +4,7 @@ * Unit-ish tests for the Maillog module. */ -class MaillogUnitTest extends DrupalWebTestCase { - - /** - * {@inheritdoc} - */ - public static function getInfo() { - return array( - 'name' => 'Maillog unit tests', - 'description' => 'Test the main Maillog functionality.', - 'group' => 'Maillog', - ); - } +class MaillogUnitTest extends BackdropWebTestCase { /** * {@inheritdoc} @@ -30,29 +19,27 @@ class MaillogUnitTest extends DrupalWebTestCase { parent::setUp($modules); // Take over the email system. - variable_set('mail_system', array('default-system' => 'MaillogMailSystem')); + config_set('system.mail', 'default-system', 'MaillogMailSystem'); // Don't allow emails to be delivered. - variable_set('maillog_send', FALSE); + config_set('maillog.settings', 'maillog_send', FALSE); // Log all emails. - variable_set('maillog_log', TRUE); + config_set('maillog.settings', 'maillog_log', TRUE); } /** * Confirm that SimpleTest has taken over the 'mail_system' variable. */ function testSetup() { - $enabled = variable_get('mail_system', array()); - $should_be = array( - 'default-system' => 'MaillogMailSystem', - ); + $enabled = config_get('system.mail', 'default-system'); + $should_be = 'MaillogMailSystem'; $this->assertEqual($enabled, $should_be, 'Maillog is controlling mail delivery.'); - $delivery = variable_get('maillog_send', FALSE); + $delivery = config_get('maillog.settings', 'maillog_send'); $this->assertEqual($delivery, FALSE, 'Email delivery is disabled.'); - $logging = variable_get('maillog_log', TRUE); + $logging = config_get('maillog.settings', 'maillog_log'); $this->assertEqual($logging, TRUE, 'Email delivery is being logged.'); } @@ -70,17 +57,18 @@ class MaillogUnitTest extends DrupalWebTestCase { $to_email = 'to_test@example.com'; $reply_email = 'reply_test@example.com'; $params = array(); - drupal_mail('maillog_tests', 'maillog_basic_test', $to_email, $langcode, $params, $from_email); + backdrop_mail('maillog_tests', 'maillog_basic_test', $to_email, $langcode, $params, $from_email); // Compare the maillog db entry with the sent mail. $logged_email = $this->getLatestMaillogEntry(); $this->assertTrue(!empty($logged_email), 'The test email was captured.'); $this->assertEqual($to_email, $logged_email['header_to'], 'Email "to" address is correct.'); - $this->assertEqual($from_email, $logged_email['header_from'], 'Email "from" address is correct.'); - $this->assertEqual($from_email, $logged_email['header_all']['From'], 'Email "from" header is correct.'); + $this->assertEqual($sender, $logged_email['header_from'], 'Email "from" address is correct.'); + $this->assertEqual($from_email, $logged_email['header_all']['Reply-to'], 'Email "from" address is correct.'); + $this->assertEqual($sender, $logged_email['header_all']['From'], 'Email "from" header is correct.'); $this->assertEqual($sender, $logged_email['header_all']['Sender'], 'Email "sender" header is correct.'); $this->assertEqual($sender, $logged_email['header_all']['Return-Path'], 'Email "return-path" header is correct.'); - $this->assertEqual('Drupal', $logged_email['header_all']['X-Mailer'], 'Email "x-mailer" header is correct.'); + $this->assertEqual('Backdrop CMS', $logged_email['header_all']['X-Mailer'], 'Email "x-mailer" header is correct.'); $this->assertEqual(t('Test email subject'), $logged_email['subject'], 'Email subject is correct.'); $this->assertEqual(t('Test email body.') . "\n", $logged_email['body'], 'Email body is correct.'); } @@ -95,7 +83,7 @@ class MaillogUnitTest extends DrupalWebTestCase { $from_email = 'from_test@example.com'; $to_email = 'to_test@example.com'; $params = array(); - drupal_mail('maillog_tests', 'maillog_long_subject_test', $to_email, $langcode, $params, $from_email); + backdrop_mail('maillog_tests', 'maillog_long_subject_test', $to_email, $langcode, $params, $from_email); // Compare the maillog db entry with the sent mail. $logged_email = $this->getLatestMaillogEntry(); @@ -105,7 +93,7 @@ class MaillogUnitTest extends DrupalWebTestCase { $subject = str_repeat(t('Test email subject') . ' ', 20); // Duplicate the string trimming. - $subject_trimmed = drupal_substr($subject, 0, 255); + $subject_trimmed = backdrop_substr($subject, 0, 255); $this->assertEqual($subject_trimmed, $logged_email['subject'], 'Email subject was trimmed correctly.'); $this->assertNotEqual($subject, $logged_email['subject'], 'Email subject is not untrimmed.'); @@ -122,7 +110,7 @@ class MaillogUnitTest extends DrupalWebTestCase { $from_email = 'from_test@example.com'; $to_email = 'to_test@example.com'; $params = array(); - drupal_mail('maillog_tests', 'maillog_subject_xss_test', $to_email, $langcode, $params, $from_email); + backdrop_mail('maillog_tests', 'maillog_subject_xss_test', $to_email, $langcode, $params, $from_email); // Compare the maillog db entry with the sent mail. $logged_email = $this->getLatestMaillogEntry(); @@ -132,16 +120,16 @@ class MaillogUnitTest extends DrupalWebTestCase { $this->loginAdminUser(); // Load the admin list page. - $this->drupalGet('admin/reports/maillog'); + $this->backdropGet('admin/reports/maillog'); $this->assertResponse(200); - + // Confirm that the page has been defanged. $this->assertText('XSS test'); $this->assertRaw(check_plain($xss_string)); $this->assertNoRaw($xss_string); // Load the maillog view page. - $this->drupalGet('maillog/details/' . $logged_email['idmaillog']); + $this->backdropGet('maillog/details/' . $logged_email['idmaillog']); $this->assertResponse(200); // Confirm that the page has been defanged. @@ -150,7 +138,7 @@ class MaillogUnitTest extends DrupalWebTestCase { $this->assertNoRaw($xss_string); // Check the title. - $this->assertTitle($xss_string . ' | ' . variable_get('site_name', 'Drupal')); + $this->assertTitle($xss_string . ' | ' . config_get('system.core', 'site_name')); } /** @@ -164,7 +152,7 @@ class MaillogUnitTest extends DrupalWebTestCase { $from_email = 'from_test@example.com'; $to_email = 'to_test@example.com'; $params = array(); - drupal_mail('maillog_tests', 'maillog_body_xss_test', $to_email, $langcode, $params, $from_email); + backdrop_mail('maillog_tests', 'maillog_body_xss_test', $to_email, $langcode, $params, $from_email); // Compare the maillog db entry with the sent mail. $logged_email = $this->getLatestMaillogEntry(); @@ -174,7 +162,7 @@ class MaillogUnitTest extends DrupalWebTestCase { $this->loginAdminUser(); // Load the maillog view page. - $this->drupalGet('maillog/details/' . $logged_email['idmaillog']); + $this->backdropGet('maillog/details/' . $logged_email['idmaillog']); $this->assertResponse(200); // The body field will be passed through check_plain, which will remove all @@ -209,7 +197,7 @@ class MaillogUnitTest extends DrupalWebTestCase { */ function loginAdminUser() { $user = $this->createAdminUser(); - $this->drupalLogin($user); + $this->backdropLogin($user); } /** @@ -224,11 +212,11 @@ class MaillogUnitTest extends DrupalWebTestCase { ); // Reset the static variable used to identify permissions, otherwise it's - // possible the permissions check in drupalCreateUser will fail. + // possible the permissions check in backdropCreateUser will fail. $this->checkPermissions(array(), TRUE); cache_clear_all(); - return $this->drupalCreateUser($permissions); + return $this->backdropCreateUser($permissions); } } diff --git a/tests/maillog_tests.info b/tests/maillog_tests.info index e38b748..63da209 100644 --- a/tests/maillog_tests.info +++ b/tests/maillog_tests.info @@ -1,5 +1,6 @@ name = Maillog tests description = Contains helper logic for the Maillog tests. package = Mail -core = 7.x +backdrop = 1.x +type = module hidden = TRUE