From 2bca2d4d7906f16d2fe2f9af413ea484c5ab238c Mon Sep 17 00:00:00 2001 From: bcweaver <brianweaver@gmail.com> Date: Tue, 23 Oct 2018 17:40:18 -0400 Subject: [PATCH] Removing unused 'reroute_email' package --- composer.json | 1 - composer.lock | 77 +--- vendor/composer/installed.json | 77 ---- web/modules/reroute_email/LICENSE.txt | 339 ------------------ web/modules/reroute_email/README.txt | 161 --------- .../config/install/reroute_email.settings.yml | 4 - .../config/schema/reroute_email.schema.yml | 22 -- .../reroute_email/reroute_email.info.yml | 12 - .../reroute_email/reroute_email.install | 85 ----- .../reroute_email.links.menu.yml | 5 - .../reroute_email.links.task.yml | 9 - .../reroute_email/reroute_email.module | 285 --------------- .../reroute_email.permissions.yml | 3 - .../reroute_email/reroute_email.routing.yml | 14 - .../reroute_email/src/Form/SettingsForm.php | 215 ----------- .../reroute_email/src/Form/TestEmailForm.php | 116 ------ .../reroute_email_test.info.yml | 12 - .../reroute_email_test.module | 70 ---- .../tests/src/Functional/ContactTest.php | 121 ------- .../src/Functional/DefaultAddressesTest.php | 111 ------ .../src/Functional/DomainWhitelistedTest.php | 42 --- .../tests/src/Functional/MailKeysTest.php | 53 --- .../src/Functional/MultipleRecipientsTest.php | 45 --- .../src/Functional/RerouteEmailTestBase.php | 167 --------- .../src/Functional/TestEmailFormTest.php | 108 ------ .../Functional/UnusualMessageFieldsTest.php | 94 ----- 26 files changed, 1 insertion(+), 2247 deletions(-) delete mode 100644 web/modules/reroute_email/LICENSE.txt delete mode 100644 web/modules/reroute_email/README.txt delete mode 100644 web/modules/reroute_email/config/install/reroute_email.settings.yml delete mode 100644 web/modules/reroute_email/config/schema/reroute_email.schema.yml delete mode 100644 web/modules/reroute_email/reroute_email.info.yml delete mode 100644 web/modules/reroute_email/reroute_email.install delete mode 100644 web/modules/reroute_email/reroute_email.links.menu.yml delete mode 100644 web/modules/reroute_email/reroute_email.links.task.yml delete mode 100644 web/modules/reroute_email/reroute_email.module delete mode 100644 web/modules/reroute_email/reroute_email.permissions.yml delete mode 100644 web/modules/reroute_email/reroute_email.routing.yml delete mode 100644 web/modules/reroute_email/src/Form/SettingsForm.php delete mode 100644 web/modules/reroute_email/src/Form/TestEmailForm.php delete mode 100644 web/modules/reroute_email/tests/modules/reroute_email_test/reroute_email_test.info.yml delete mode 100644 web/modules/reroute_email/tests/modules/reroute_email_test/reroute_email_test.module delete mode 100644 web/modules/reroute_email/tests/src/Functional/ContactTest.php delete mode 100644 web/modules/reroute_email/tests/src/Functional/DefaultAddressesTest.php delete mode 100644 web/modules/reroute_email/tests/src/Functional/DomainWhitelistedTest.php delete mode 100644 web/modules/reroute_email/tests/src/Functional/MailKeysTest.php delete mode 100644 web/modules/reroute_email/tests/src/Functional/MultipleRecipientsTest.php delete mode 100644 web/modules/reroute_email/tests/src/Functional/RerouteEmailTestBase.php delete mode 100644 web/modules/reroute_email/tests/src/Functional/TestEmailFormTest.php delete mode 100644 web/modules/reroute_email/tests/src/Functional/UnusualMessageFieldsTest.php diff --git a/composer.json b/composer.json index c391971bba..beb8d4b94a 100644 --- a/composer.json +++ b/composer.json @@ -119,7 +119,6 @@ "drupal/paragraphs": "1.3", "drupal/pathauto": "1.0", "drupal/redis": "1.0-rc2", - "drupal/reroute_email": "1.0", "drupal/responsive_menu": "2.5", "drupal/roleassign": "^1.0@alpha", "drupal/scheduler": "1.0", diff --git a/composer.lock b/composer.lock index 27a392d39b..9b795b04e7 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "content-hash": "43ec5dc5ea515b8a049e94f612c9688a", + "content-hash": "6db25da5fe1fd37f41e66c6d2c46bbe6", "packages": [ { "name": "alchemy/zippy", @@ -4838,81 +4838,6 @@ "source": "http://cgit.drupalcode.org/redis" } }, - { - "name": "drupal/reroute_email", - "version": "1.0.0", - "source": { - "type": "git", - "url": "https://git.drupal.org/project/reroute_email", - "reference": "8.x-1.0" - }, - "dist": { - "type": "zip", - "url": "https://ftp.drupal.org/files/projects/reroute_email-8.x-1.0.zip", - "reference": "8.x-1.0", - "shasum": "84d75bc9674b66d7ba3b9b870f2a5ba1292f7509" - }, - "require": { - "drupal/core": "~8.0" - }, - "type": "drupal-module", - "extra": { - "branch-alias": { - "dev-1.x": "1.x-dev" - }, - "drupal": { - "version": "8.x-1.0", - "datestamp": "1513342685", - "security-coverage": { - "status": "covered", - "message": "Covered by Drupal's security advisory policy" - } - } - }, - "notification-url": "https://packages.drupal.org/8/downloads", - "license": [ - "GPL-2.0-or-later" - ], - "authors": [ - { - "name": "B-Prod", - "homepage": "https://www.drupal.org/user/407852" - }, - { - "name": "DYdave", - "homepage": "https://www.drupal.org/user/467284" - }, - { - "name": "Devaraj johnson", - "homepage": "https://www.drupal.org/user/2698767" - }, - { - "name": "Rohin Knight", - "homepage": "https://www.drupal.org/user/388531" - }, - { - "name": "bohart", - "homepage": "https://www.drupal.org/user/289861" - }, - { - "name": "kbahey", - "homepage": "https://www.drupal.org/user/4063" - }, - { - "name": "rfay", - "homepage": "https://www.drupal.org/user/30906" - }, - { - "name": "wafaa", - "homepage": "https://www.drupal.org/user/50133" - } - ], - "description": "Reroutes emails send from the site to a predefined email. Useful for test sites.", - "homepage": "https://www.drupal.org/project/reroute_email", - "support": { - "source": "http://cgit.drupalcode.org/reroute_email" - } - }, { "name": "drupal/responsive_menu", "version": "2.5.0", diff --git a/vendor/composer/installed.json b/vendor/composer/installed.json index b6ed30b85a..674190acdc 100644 --- a/vendor/composer/installed.json +++ b/vendor/composer/installed.json @@ -4987,83 +4987,6 @@ "source": "http://cgit.drupalcode.org/redis" } }, - { - "name": "drupal/reroute_email", - "version": "1.0.0", - "version_normalized": "1.0.0.0", - "source": { - "type": "git", - "url": "https://git.drupal.org/project/reroute_email", - "reference": "8.x-1.0" - }, - "dist": { - "type": "zip", - "url": "https://ftp.drupal.org/files/projects/reroute_email-8.x-1.0.zip", - "reference": "8.x-1.0", - "shasum": "84d75bc9674b66d7ba3b9b870f2a5ba1292f7509" - }, - "require": { - "drupal/core": "~8.0" - }, - "type": "drupal-module", - "extra": { - "branch-alias": { - "dev-1.x": "1.x-dev" - }, - "drupal": { - "version": "8.x-1.0", - "datestamp": "1513342685", - "security-coverage": { - "status": "covered", - "message": "Covered by Drupal's security advisory policy" - } - } - }, - "installation-source": "dist", - "notification-url": "https://packages.drupal.org/8/downloads", - "license": [ - "GPL-2.0-or-later" - ], - "authors": [ - { - "name": "B-Prod", - "homepage": "https://www.drupal.org/user/407852" - }, - { - "name": "DYdave", - "homepage": "https://www.drupal.org/user/467284" - }, - { - "name": "Devaraj johnson", - "homepage": "https://www.drupal.org/user/2698767" - }, - { - "name": "Rohin Knight", - "homepage": "https://www.drupal.org/user/388531" - }, - { - "name": "bohart", - "homepage": "https://www.drupal.org/user/289861" - }, - { - "name": "kbahey", - "homepage": "https://www.drupal.org/user/4063" - }, - { - "name": "rfay", - "homepage": "https://www.drupal.org/user/30906" - }, - { - "name": "wafaa", - "homepage": "https://www.drupal.org/user/50133" - } - ], - "description": "Reroutes emails send from the site to a predefined email. Useful for test sites.", - "homepage": "https://www.drupal.org/project/reroute_email", - "support": { - "source": "http://cgit.drupalcode.org/reroute_email" - } - }, { "name": "drupal/responsive_menu", "version": "2.5.0", diff --git a/web/modules/reroute_email/LICENSE.txt b/web/modules/reroute_email/LICENSE.txt deleted file mode 100644 index d159169d10..0000000000 --- a/web/modules/reroute_email/LICENSE.txt +++ /dev/null @@ -1,339 +0,0 @@ - GNU GENERAL PUBLIC LICENSE - Version 2, June 1991 - - Copyright (C) 1989, 1991 Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA - Everyone is permitted to copy and distribute verbatim copies - of this license document, but changing it is not allowed. - - Preamble - - The licenses for most software are designed to take away your -freedom to share and change it. By contrast, the GNU General Public -License is intended to guarantee your freedom to share and change free -software--to make sure the software is free for all its users. This -General Public License applies to most of the Free Software -Foundation's software and to any other program whose authors commit to -using it. (Some other Free Software Foundation software is covered by -the GNU Lesser General Public License instead.) You can apply it to -your programs, too. - - When we speak of free software, we are referring to freedom, not -price. Our General Public Licenses are designed to make sure that you -have the freedom to distribute copies of free software (and charge for -this service if you wish), that you receive source code or can get it -if you want it, that you can change the software or use pieces of it -in new free programs; and that you know you can do these things. - - To protect your rights, we need to make restrictions that forbid -anyone to deny you these rights or to ask you to surrender the rights. -These restrictions translate to certain responsibilities for you if you -distribute copies of the software, or if you modify it. - - For example, if you distribute copies of such a program, whether -gratis or for a fee, you must give the recipients all the rights that -you have. You must make sure that they, too, receive or can get the -source code. And you must show them these terms so they know their -rights. - - We protect your rights with two steps: (1) copyright the software, and -(2) offer you this license which gives you legal permission to copy, -distribute and/or modify the software. - - Also, for each author's protection and ours, we want to make certain -that everyone understands that there is no warranty for this free -software. If the software is modified by someone else and passed on, we -want its recipients to know that what they have is not the original, so -that any problems introduced by others will not reflect on the original -authors' reputations. - - Finally, any free program is threatened constantly by software -patents. We wish to avoid the danger that redistributors of a free -program will individually obtain patent licenses, in effect making the -program proprietary. To prevent this, we have made it clear that any -patent must be licensed for everyone's free use or not licensed at all. - - The precise terms and conditions for copying, distribution and -modification follow. - - GNU GENERAL PUBLIC LICENSE - TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION - - 0. This License applies to any program or other work which contains -a notice placed by the copyright holder saying it may be distributed -under the terms of this General Public License. The "Program", below, -refers to any such program or work, and a "work based on the Program" -means either the Program or any derivative work under copyright law: -that is to say, a work containing the Program or a portion of it, -either verbatim or with modifications and/or translated into another -language. (Hereinafter, translation is included without limitation in -the term "modification".) Each licensee is addressed as "you". - -Activities other than copying, distribution and modification are not -covered by this License; they are outside its scope. The act of -running the Program is not restricted, and the output from the Program -is covered only if its contents constitute a work based on the -Program (independent of having been made by running the Program). -Whether that is true depends on what the Program does. - - 1. You may copy and distribute verbatim copies of the Program's -source code as you receive it, in any medium, provided that you -conspicuously and appropriately publish on each copy an appropriate -copyright notice and disclaimer of warranty; keep intact all the -notices that refer to this License and to the absence of any warranty; -and give any other recipients of the Program a copy of this License -along with the Program. - -You may charge a fee for the physical act of transferring a copy, and -you may at your option offer warranty protection in exchange for a fee. - - 2. You may modify your copy or copies of the Program or any portion -of it, thus forming a work based on the Program, and copy and -distribute such modifications or work under the terms of Section 1 -above, provided that you also meet all of these conditions: - - a) You must cause the modified files to carry prominent notices - stating that you changed the files and the date of any change. - - b) You must cause any work that you distribute or publish, that in - whole or in part contains or is derived from the Program or any - part thereof, to be licensed as a whole at no charge to all third - parties under the terms of this License. - - c) If the modified program normally reads commands interactively - when run, you must cause it, when started running for such - interactive use in the most ordinary way, to print or display an - announcement including an appropriate copyright notice and a - notice that there is no warranty (or else, saying that you provide - a warranty) and that users may redistribute the program under - these conditions, and telling the user how to view a copy of this - License. (Exception: if the Program itself is interactive but - does not normally print such an announcement, your work based on - the Program is not required to print an announcement.) - -These requirements apply to the modified work as a whole. If -identifiable sections of that work are not derived from the Program, -and can be reasonably considered independent and separate works in -themselves, then this License, and its terms, do not apply to those -sections when you distribute them as separate works. But when you -distribute the same sections as part of a whole which is a work based -on the Program, the distribution of the whole must be on the terms of -this License, whose permissions for other licensees extend to the -entire whole, and thus to each and every part regardless of who wrote it. - -Thus, it is not the intent of this section to claim rights or contest -your rights to work written entirely by you; rather, the intent is to -exercise the right to control the distribution of derivative or -collective works based on the Program. - -In addition, mere aggregation of another work not based on the Program -with the Program (or with a work based on the Program) on a volume of -a storage or distribution medium does not bring the other work under -the scope of this License. - - 3. You may copy and distribute the Program (or a work based on it, -under Section 2) in object code or executable form under the terms of -Sections 1 and 2 above provided that you also do one of the following: - - a) Accompany it with the complete corresponding machine-readable - source code, which must be distributed under the terms of Sections - 1 and 2 above on a medium customarily used for software interchange; or, - - b) Accompany it with a written offer, valid for at least three - years, to give any third party, for a charge no more than your - cost of physically performing source distribution, a complete - machine-readable copy of the corresponding source code, to be - distributed under the terms of Sections 1 and 2 above on a medium - customarily used for software interchange; or, - - c) Accompany it with the information you received as to the offer - to distribute corresponding source code. (This alternative is - allowed only for noncommercial distribution and only if you - received the program in object code or executable form with such - an offer, in accord with Subsection b above.) - -The source code for a work means the preferred form of the work for -making modifications to it. For an executable work, complete source -code means all the source code for all modules it contains, plus any -associated interface definition files, plus the scripts used to -control compilation and installation of the executable. However, as a -special exception, the source code distributed need not include -anything that is normally distributed (in either source or binary -form) with the major components (compiler, kernel, and so on) of the -operating system on which the executable runs, unless that component -itself accompanies the executable. - -If distribution of executable or object code is made by offering -access to copy from a designated place, then offering equivalent -access to copy the source code from the same place counts as -distribution of the source code, even though third parties are not -compelled to copy the source along with the object code. - - 4. You may not copy, modify, sublicense, or distribute the Program -except as expressly provided under this License. Any attempt -otherwise to copy, modify, sublicense or distribute the Program is -void, and will automatically terminate your rights under this License. -However, parties who have received copies, or rights, from you under -this License will not have their licenses terminated so long as such -parties remain in full compliance. - - 5. You are not required to accept this License, since you have not -signed it. However, nothing else grants you permission to modify or -distribute the Program or its derivative works. These actions are -prohibited by law if you do not accept this License. Therefore, by -modifying or distributing the Program (or any work based on the -Program), you indicate your acceptance of this License to do so, and -all its terms and conditions for copying, distributing or modifying -the Program or works based on it. - - 6. Each time you redistribute the Program (or any work based on the -Program), the recipient automatically receives a license from the -original licensor to copy, distribute or modify the Program subject to -these terms and conditions. You may not impose any further -restrictions on the recipients' exercise of the rights granted herein. -You are not responsible for enforcing compliance by third parties to -this License. - - 7. If, as a consequence of a court judgment or allegation of patent -infringement or for any other reason (not limited to patent issues), -conditions are imposed on you (whether by court order, agreement or -otherwise) that contradict the conditions of this License, they do not -excuse you from the conditions of this License. If you cannot -distribute so as to satisfy simultaneously your obligations under this -License and any other pertinent obligations, then as a consequence you -may not distribute the Program at all. For example, if a patent -license would not permit royalty-free redistribution of the Program by -all those who receive copies directly or indirectly through you, then -the only way you could satisfy both it and this License would be to -refrain entirely from distribution of the Program. - -If any portion of this section is held invalid or unenforceable under -any particular circumstance, the balance of the section is intended to -apply and the section as a whole is intended to apply in other -circumstances. - -It is not the purpose of this section to induce you to infringe any -patents or other property right claims or to contest validity of any -such claims; this section has the sole purpose of protecting the -integrity of the free software distribution system, which is -implemented by public license practices. Many people have made -generous contributions to the wide range of software distributed -through that system in reliance on consistent application of that -system; it is up to the author/donor to decide if he or she is willing -to distribute software through any other system and a licensee cannot -impose that choice. - -This section is intended to make thoroughly clear what is believed to -be a consequence of the rest of this License. - - 8. If the distribution and/or use of the Program is restricted in -certain countries either by patents or by copyrighted interfaces, the -original copyright holder who places the Program under this License -may add an explicit geographical distribution limitation excluding -those countries, so that distribution is permitted only in or among -countries not thus excluded. In such case, this License incorporates -the limitation as if written in the body of this License. - - 9. The Free Software Foundation may publish revised and/or new versions -of the General Public License from time to time. Such new versions will -be similar in spirit to the present version, but may differ in detail to -address new problems or concerns. - -Each version is given a distinguishing version number. If the Program -specifies a version number of this License which applies to it and "any -later version", you have the option of following the terms and conditions -either of that version or of any later version published by the Free -Software Foundation. If the Program does not specify a version number of -this License, you may choose any version ever published by the Free Software -Foundation. - - 10. If you wish to incorporate parts of the Program into other free -programs whose distribution conditions are different, write to the author -to ask for permission. For software which is copyrighted by the Free -Software Foundation, write to the Free Software Foundation; we sometimes -make exceptions for this. Our decision will be guided by the two goals -of preserving the free status of all derivatives of our free software and -of promoting the sharing and reuse of software generally. - - NO WARRANTY - - 11. BECAUSE THE PROGRAM IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY -FOR THE PROGRAM, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN -OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES -PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED -OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF -MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS -TO THE QUALITY AND PERFORMANCE OF THE PROGRAM IS WITH YOU. SHOULD THE -PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, -REPAIR OR CORRECTION. - - 12. IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING -WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR -REDISTRIBUTE THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, -INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING -OUT OF THE USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED -TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY -YOU OR THIRD PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER -PROGRAMS), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE -POSSIBILITY OF SUCH DAMAGES. - - END OF TERMS AND CONDITIONS - - How to Apply These Terms to Your New Programs - - If you develop a new program, and you want it to be of the greatest -possible use to the public, the best way to achieve this is to make it -free software which everyone can redistribute and change under these terms. - - To do so, attach the following notices to the program. It is safest -to attach them to the start of each source file to most effectively -convey the exclusion of warranty; and each file should have at least -the "copyright" line and a pointer to where the full notice is found. - - <one line to give the program's name and a brief idea of what it does.> - Copyright (C) <year> <name of author> - - This program 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 2 of the License, or - (at your option) any later version. - - This program 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 this program; if not, write to the Free Software Foundation, Inc., - 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. - -Also add information on how to contact you by electronic and paper mail. - -If the program is interactive, make it output a short notice like this -when it starts in an interactive mode: - - Gnomovision version 69, Copyright (C) year name of author - Gnomovision comes with ABSOLUTELY NO WARRANTY; for details type `show w'. - This is free software, and you are welcome to redistribute it - under certain conditions; type `show c' for details. - -The hypothetical commands `show w' and `show c' should show the appropriate -parts of the General Public License. Of course, the commands you use may -be called something other than `show w' and `show c'; they could even be -mouse-clicks or menu items--whatever suits your program. - -You should also get your employer (if you work as a programmer) or your -school, if any, to sign a "copyright disclaimer" for the program, if -necessary. Here is a sample; alter the names: - - Yoyodyne, Inc., hereby disclaims all copyright interest in the program - `Gnomovision' (which makes passes at compilers) written by James Hacker. - - <signature of Ty Coon>, 1 April 1989 - Ty Coon, President of Vice - -This General Public License does not permit incorporating your program into -proprietary programs. If your program is a subroutine library, you may -consider it more useful to permit linking proprietary applications with the -library. If this is what you want to do, use the GNU Lesser General -Public License instead of this License. diff --git a/web/modules/reroute_email/README.txt b/web/modules/reroute_email/README.txt deleted file mode 100644 index e9933b32b3..0000000000 --- a/web/modules/reroute_email/README.txt +++ /dev/null @@ -1,161 +0,0 @@ -REROUTE EMAIL -------------- - -CONTENTS OF THIS FILE ---------------------- - - * Description - * Installation and configuration - * Tips and Tricks - * Settings code snippet - * Test Email Form - * Bugs / features / patches - * Authors and maintainers - * Link references - --------------------------------------------------------------------------------- - DESCRIPTION --------------------------------------------------------------------------------- - -This module intercepts all outgoing emails from a Drupal site and reroutes them -to a list of predefined configurable email addresses. - -This is especially useful in cases where you would not want emails sent from a -Drupal site to reach target users. For example, if a live site was copied to a -test site for development and testing purposes, in general, you would like to -prevent any email sent from the test site to reach real users of the original -site. The module is also an appropriate tool for checking closer outgoing emails -for formatting, footers, headers, and more. - -Additionally, it is a good example of what hook_mail_alter(), available in -Drupal 5.x and later, can do. - --------------------------------------------------------------------------------- - INSTALLATION AND CONFIGURATION --------------------------------------------------------------------------------- - -To install this module, do the following: - -1 - Download the module and copy it into your contributed modules folder: -[for example, your_drupal_path/sites/all/modules/contrib] and enable it from the -modules administration/management page (no requirements). -More information at: Installing contributed modules (Drupal 8) [1]. - -2 - Configuration: -After successful installation, browse to the Reroute Email settings page either -by using the "Configure" link (next to module's name on the modules listing -page), or page's menu link under: -Home » Administration » Configuration » Development -Path: /admin/config/development/reroute_email - -3 - Enter a list of email addresses to route all emails to. If the field is -empty and no value is provided for rerouted email addresses, all outgoing -emails would be aborted and recorded in the recent log entries, with a full -dump of the email variables, which could provide an additional debugging -method. The whitelist section allows setting up lists of email address and -domain name exceptions for which outgoing emails would not be rerouted. - --------------------------------------------------------------------------------- - TIPS AND TRICKS --------------------------------------------------------------------------------- - -1 - Reroute Email provides configuration variables that can be directly -overridden in the settings.php file of a site. This is particularly useful for -moving sites from live to test and vice versa. - -2 - An example of setup would be to enable rerouting on a test environment, -while making sure it is disabled in production. - -Add the following line in the settings.php file for the test environment: - $config['reroute_email.settings']['enable'] = TRUE; - $config['reroute_email.settings']['address'] = 'your.email@example.com'; - -And for the live site, set it as follows: - $config['reroute_email.settings']['enable'] = FALSE; - -3 - Your custom module can add a special header 'X-Rerouted-Force' with TRUE or -FALSE value to any own emails in hook_mail or any emails in hook_mail_alter() -implementations. This header will force enable or disable email rerouting by -ignoring default settings. - --------------------------------------------------------------------------------- - SETTINGS CODE SNIPPET --------------------------------------------------------------------------------- - -Configuration and all the settings variables can be overridden in the -settings.php file by copying and pasting the code snippet below and changing -the values: - -/** - * Reroute Email module: - * - * To override specific variables and ensure that email rerouting is enabled or - * disabled, change the values below accordingly for your site. - */ - -// Enable email rerouting. -$config['reroute_email.settings']['enable'] = TRUE; - -// Space, comma, semicolon, or newline-delimited list of email addresses. Every -// destination email address which is not on "Whitelisted email addresses" list -// will be rerouted to these addresses. If the field is empty and no value is -// provided, all outgoing emails would be aborted and the email would be -// recorded in the recent log entries (if enabled). -$config['reroute_email.settings']['address'] = 'your.email@example.com'; - -// Space, comma, semicolon, or newline-delimited list of email addresses to pass -// through. Every destination email address which is not on this list will be -// rerouted. If the field is empty and no value is provided, all outgoing emails -// would be rerouted. We can use wildcard email "*@example.com" to whitelist all -// emails by the domain. -$config['reroute_email.settings']['whitelist'] = '*@example.com, foo@bar.com'; - -// Space, comma, semicolon, or newline-delimited list of message keys to be -// rerouted. Either module machine name or specific mail key can be used for -// that. Only matching messages will be rerouted. If left empty (as default), -// all emails will be selected for rerouting. -$config['reroute_email.settings']['mailkeys'] = 'somemodule, mymodule_mykey'; - -// Enable inserting a message into the email body when the mail is being -// rerouted. -$config['reroute_email.settings']['message'] = TRUE; - --------------------------------------------------------------------------------- - TEST EMAIL FORM --------------------------------------------------------------------------------- - -Reroute Email also provides a convenient form for testing email sending or -rerouting. After enabling the module, a test email form is accessible under: -Admin » Configuration » Development » Reroute Email » Test email form -Path: /admin/config/development/reroute_email/test - -This form allows sending an email upon submission to the recipients entered in -the fields To, Cc and Bcc, which is very practical for testing if emails are -correctly rerouted to the configured addresses. - --------------------------------------------------------------------------------- - BUGS / FEATURES / PATCHES --------------------------------------------------------------------------------- - -Feel free to follow up in the issue queue [2] for any contributions, bug -reports, feature requests. -Tests, feedback or comments in general are highly appreciated. - --------------------------------------------------------------------------------- - AUTHORS AND MAINTAINERS --------------------------------------------------------------------------------- - -kbahey (https://www.drupal.org/user/4063) -rfay (http://drupal.org/user/30906) -DYdave (http://drupal.org/user/467284) -bohart (https://drupal.org/user/289861) - -If you use this module, find it useful, and want to send the author a thank you -note, then use the Feedback/Contact page at the URL above. - --------------------------------------------------------------------------------- - LINK REFERENCES --------------------------------------------------------------------------------- - -1: http://drupal.org/documentation/install/modules-themes/modules-8 -2: https://www.drupal.org/project/issues/reroute_email diff --git a/web/modules/reroute_email/config/install/reroute_email.settings.yml b/web/modules/reroute_email/config/install/reroute_email.settings.yml deleted file mode 100644 index 64d52cbb78..0000000000 --- a/web/modules/reroute_email/config/install/reroute_email.settings.yml +++ /dev/null @@ -1,4 +0,0 @@ -enable: false -description: true -message: true -mailkeys: '' diff --git a/web/modules/reroute_email/config/schema/reroute_email.schema.yml b/web/modules/reroute_email/config/schema/reroute_email.schema.yml deleted file mode 100644 index 3c39d7f1d2..0000000000 --- a/web/modules/reroute_email/config/schema/reroute_email.schema.yml +++ /dev/null @@ -1,22 +0,0 @@ -reroute_email.settings: - type: config_object - label: 'Reroute Email Settings.' - mapping: - enable: - type: boolean - label: 'Enable rerouting.' - address: - type: string - label: 'Rerouting email addresses.' - whitelist: - type: string - label: 'Whitelisted email addresses.' - description: - type: boolean - label: 'Show rerouting description in mail body.' - message: - type: boolean - label: 'Display a Drupal status message after rerouting.' - mailkeys: - type: string - label: 'Filter by mail keys.' diff --git a/web/modules/reroute_email/reroute_email.info.yml b/web/modules/reroute_email/reroute_email.info.yml deleted file mode 100644 index 9f2cf0b960..0000000000 --- a/web/modules/reroute_email/reroute_email.info.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: 'Reroute emails' -description: 'Reroutes emails send from the site to a predefined email. Useful for test sites.' -package: Development -# core: 8.x -configure: reroute_email.settings -type: module - -# Information added by Drupal.org packaging script on 2017-12-15 -version: '8.x-1.0' -core: '8.x' -project: 'reroute_email' -datestamp: 1513342688 diff --git a/web/modules/reroute_email/reroute_email.install b/web/modules/reroute_email/reroute_email.install deleted file mode 100644 index 918738638f..0000000000 --- a/web/modules/reroute_email/reroute_email.install +++ /dev/null @@ -1,85 +0,0 @@ -<?php - -/** - * @file - * Reroute Email installation and upgrade tasks. - */ - -use Drupal\Core\Link; - -/** - * Implements hook_requirements(). - */ -function reroute_email_requirements($phase) { - $requirements = []; - $reroute_config = \Drupal::config('reroute_email.settings'); - - if ($phase === 'runtime' && $reroute_config->get(REROUTE_EMAIL_ENABLE)) { - $settings = [ - '@link' => Link::createFromRoute(t('configure whitelist'), 'reroute_email.settings')->toString(), - '%addresses' => $reroute_config->get(REROUTE_EMAIL_ADDRESS), - ]; - - if (empty($settings['%addresses'])) { - $message = t('All outgoing emails (@link) would be aborted and recorded in the recent log entries (if enabled).', $settings); - } - else { - $message = t('All outgoing emails (@link) would be rerouted to: %addresses', $settings); - } - - $requirements['reroute_email'] = [ - 'title' => t('Reroute Email'), - 'value' => $message, - 'severity' => REQUIREMENT_WARNING, - ]; - } - - return $requirements; -} - -/** - * Implements hook_update_N(). - * - * Now we have a separate fields for `Rerouting email addresses` and - * `Whitelisted email addresses`. Previously all emails was rerouted - * to the first email from `Rerouting email addresses`. - */ -function reroute_email_update_8001() { - // We have changed config names. - $old = [ - REROUTE_EMAIL_ENABLE => 'reroute_email_enable', - REROUTE_EMAIL_ADDRESS => 'reroute_email_address', - REROUTE_EMAIL_DESCRIPTION => 'reroute_email_enable_message', - ]; - - $config = \Drupal::configFactory()->getEditable('reroute_email.settings'); - - // Do not update values if the user sets them manually already. - // `Whitelisted addresses` is a new variable, so it couldn't exist before. - if (NULL !== $config->get(REROUTE_EMAIL_WHITELIST)) { - return; - } - - // Update whitelisted email addresses value. - $addresses = $config->get($old[REROUTE_EMAIL_ADDRESS]); - $config->set(REROUTE_EMAIL_WHITELIST, $addresses); - - // Update rerouting email addresses value. - $addresses = reroute_email_split_string($addresses); - $config->set(REROUTE_EMAIL_ADDRESS, !empty($addresses[0]) ? $addresses[0] : ''); - - // Update other configs to new names. - $config->set(REROUTE_EMAIL_ENABLE, $config->get($old[REROUTE_EMAIL_ENABLE])); - $config->set(REROUTE_EMAIL_DESCRIPTION, $config->get($old[REROUTE_EMAIL_DESCRIPTION])); - - // Remove old configs. - $config->clear($old[REROUTE_EMAIL_ENABLE]); - $config->clear($old[REROUTE_EMAIL_ADDRESS]); - $config->clear($old[REROUTE_EMAIL_DESCRIPTION]); - - // Save configuration values. - $config->save(); - - // Return a message to the user. - return t('Reroute email module updates completed successfully. Please visit configuration page to check.'); -} diff --git a/web/modules/reroute_email/reroute_email.links.menu.yml b/web/modules/reroute_email/reroute_email.links.menu.yml deleted file mode 100644 index 1d3e1e4a85..0000000000 --- a/web/modules/reroute_email/reroute_email.links.menu.yml +++ /dev/null @@ -1,5 +0,0 @@ -reroute_email.settings: - route_name: reroute_email.settings - title: 'Reroute Email' - description: 'Reroute emails to a test address.' - parent: system.admin_config_development diff --git a/web/modules/reroute_email/reroute_email.links.task.yml b/web/modules/reroute_email/reroute_email.links.task.yml deleted file mode 100644 index cce3dd2091..0000000000 --- a/web/modules/reroute_email/reroute_email.links.task.yml +++ /dev/null @@ -1,9 +0,0 @@ -reroute_email.settings: - route_name: reroute_email.settings - title: Settings - weight: -10 - base_route: reroute_email.settings -reroute_email.test_email_form: - route_name: reroute_email.test_email_form - title: 'Test email form' - base_route: reroute_email.settings diff --git a/web/modules/reroute_email/reroute_email.module b/web/modules/reroute_email/reroute_email.module deleted file mode 100644 index 9859a2ef8b..0000000000 --- a/web/modules/reroute_email/reroute_email.module +++ /dev/null @@ -1,285 +0,0 @@ -<?php - -/** - * @file - * Intercepts all outgoing emails to be rerouted to a configurable destination. - */ - -use Egulias\EmailValidator\EmailParser; -use Egulias\EmailValidator\EmailLexer; -use Drupal\Component\Utility\Unicode; - -define('REROUTE_EMAIL_ENABLE', 'enable'); -define('REROUTE_EMAIL_ADDRESS', 'address'); -define('REROUTE_EMAIL_WHITELIST', 'whitelist'); -define('REROUTE_EMAIL_DESCRIPTION', 'description'); -define('REROUTE_EMAIL_MESSAGE', 'message'); -define('REROUTE_EMAIL_MAILKEYS', 'mailkeys'); -define('REROUTE_EMAIL_ADDRESS_EMPTY_PLACEHOLDER', '[No reroute email address configured]'); - -/** - * Implements hook_module_implements_alter(). - * - * Ensure reroute_email runs last when hook_mail_alter is invoked. - */ -function reroute_email_module_implements_alter(&$implementations, $hook) { - // Testing with isset is only necessary if module doesn't implement the hook. - if ($hook == 'mail_alter') { - - // Move our hook implementation to the bottom. - $group = $implementations['reroute_email']; - unset($implementations['reroute_email']); - $implementations['reroute_email'] = $group; - - // If the queue_mail module is installed, ensure that comes after ours so - // queued emails are still rerouted. - if (isset($implementations['queue_mail'])) { - $group = $implementations['queue_mail']; - unset($implementations['queue_mail']); - $implementations['queue_mail'] = $group; - } - } -} - -/** - * Implements hook_mail_alter(). - * - * Alter destination of outgoing emails if reroute_email is enabled. - */ -function reroute_email_mail_alter(&$message) { - global $base_url; - $config = \Drupal::config('reroute_email.settings'); - - if (empty($message) || !is_array($message)) { - return; - } - - // Allow other modules to decide whether the email should be rerouted by - // specify a special header 'X-Rerouted-Force' to TRUE or FALSE. Any module - // can add this header to any own emails in hook_mail or any other emails in - // hook_mail_alter() implementations. - if (!empty($message['headers']) && isset($message['headers']['X-Rerouted-Force'])) { - if (FALSE === (bool) $message['headers']['X-Rerouted-Force']) { - return; - } - - // We ignore all module settings if X-Rerouted-Force header was set to TRUE. - } - - // There is no value for X-Rerouted-Force header in the message. Let's - // determine if the message should be rerouted according to the module - // settings values. - elseif (reroute_email_check($message) === FALSE) { - return; - } - - $mailkey = isset($message['id']) ? $message['id'] : t('[mail id] is missing'); - $to = isset($message['to']) ? $message['to'] : t('[to] is missing'); - - $message['headers']['X-Rerouted-Mail-Key'] = $mailkey; - $message['headers']['X-Rerouted-Website'] = $base_url; - - // Unset Bcc and Cc fields to prevent emails from going to those addresses. - if (isset($message['headers']) && is_array($message['headers'])) { - - // Ensure we catch all Cc and Bcc headers, regardless of case, - // and protecting against multiple instances of the "same" header. - $header_keys = []; - foreach (array_keys($message['headers']) as $key) { - $header_keys[strtolower($key)][] = $key; - } - - if (!empty($header_keys['cc'])) { - foreach ($header_keys['cc'] as $header) { - $message['headers']['X-Rerouted-Original-Cc'] = $message['headers'][$header]; - unset($message['headers'][$header]); - } - } - if (!empty($header_keys['bcc'])) { - foreach ($header_keys['bcc'] as $header) { - $message['headers']['X-Rerouted-Original-Bcc'] = $message['headers'][$header]; - unset($message['headers'][$header]); - } - } - } - - // Get reroute_email_address, or use system.site.mail if not set. - $rerouting_addresses = $config->get(REROUTE_EMAIL_ADDRESS); - if (NULL === $rerouting_addresses) { - $rerouting_addresses = \Drupal::config('system.site')->get('mail'); - } - $message['headers']['X-Rerouted-Original-To'] = $to; - $message['to'] = $rerouting_addresses; - - // Format a message to show at the top. - if ($config->get(REROUTE_EMAIL_DESCRIPTION)) { - $message_lines = [ - t('This email was rerouted.'), - t('Web site: @site', ['@site' => $base_url]), - t('Mail key: @key', ['@key' => $mailkey]), - t('Originally to: @to', ['@to' => $to]), - ]; - - // Add Cc/Bcc values to the message only if they are set. - if (!empty($message['headers']['X-Rerouted-Original-Cc'])) { - $message_lines[] = t('Originally cc: @cc', ['@cc' => $message['headers']['X-Rerouted-Original-Cc']]); - } - if (!empty($message['headers']['X-Rerouted-Original-Bcc'])) { - $message_lines[] = t('Originally bcc: @bcc', ['@bcc' => $message['headers']['X-Rerouted-Original-Bcc']]); - } - - // Simple separator between reroute and original messages. - $message_lines[] = '-----------------------'; - $message_lines[] = ''; - - $msg = implode(PHP_EOL, $message_lines); - - // Prepend explanation message to the body of the email. This must be - // handled differently depending on whether the body came in as a - // string or an array. If it came in as a string (despite the fact it - // should be an array) we'll respect that and leave it as a string. - if (is_string($message['body'])) { - $message['body'] = $msg . $message['body']; - } - else { - array_unshift($message['body'], $msg); - } - } - - // Abort sending of the email if the no rerouting addresses provided. - if ($rerouting_addresses === '') { - $message['send'] = FALSE; - - // Extensive params keys cause OOM error in var_export(). - unset($message['params']); - - // Record a variable dump of the email in the recent log entries. - $message_string = var_export($message, TRUE); - - \Drupal::logger('reroute_email') - ->notice('Aborted email sending for <em>@message_id</em>. <br/>Detailed email data: Array $message <pre>@message</pre>', [ - '@message_id' => $message['id'], - '@message' => $message_string, - ]); - - // Let users know email has been aborted, but logged. - drupal_set_message(t('<em>@message_id</em> was aborted by reroute email; site administrators can check the recent log entries for complete details on the rerouted email.', ['@message_id' => $message['id']])); - } - elseif ($config->get(REROUTE_EMAIL_MESSAGE)) { - - // Display a message to let users know email was rerouted. - drupal_set_message(t('Submitted email, with ID: <em>@message_id</em>, was rerouted to configured address: <em>@reroute_target</em>. For more details please refer to Reroute Email settings.', [ - '@message_id' => $message['id'], - '@reroute_target' => $message['to'], - ])); - } -} - -/** - * Implements hook_mail(). - */ -function reroute_email_mail($key, &$message, $params) { - if ($message['id'] !== 'reroute_email_test_email_form') { - return; - } - $message['headers']['Cc'] = $params['cc']; - $message['headers']['Bcc'] = $params['bcc']; - $message['subject'] = $params['subject']; - $message['body'][] = $params['body']; -} - -/** - * Helper function to determine a need to reroute. - * - * @param array &$message - * A message array, as described in hook_mail_alter(). - * - * @return bool - * Return TRUE if should be rerouted, FALSE otherwise. - */ -function reroute_email_check(array &$message) { - // Disable rerouting according to admin settings. - $config = \Drupal::config('reroute_email.settings'); - if (empty($config->get(REROUTE_EMAIL_ENABLE))) { - return FALSE; - } - - // Check configured mail keys filters. - $keys = reroute_email_split_string($config->get(REROUTE_EMAIL_MAILKEYS, '')); - if (!empty($keys) && !(in_array($message['id'], $keys, TRUE) || in_array($message['module'], $keys, TRUE))) { - $message['header']['X-Reroute-Status'] = 'MAILKEY-IGNORED'; - return FALSE; - } - - // Split addresses into arrays. - $original_addresses = reroute_email_split_string($message['to']); - $whitelisted_addresses = reroute_email_split_string($config->get(REROUTE_EMAIL_WHITELIST)); - $whitelisted_domains = []; - - // Split whitelisted domains from whitelisted addresses. - foreach ($whitelisted_addresses as $key => $email) { - if (preg_match('/^\*@(.*)$/', $email, $matches)) { - - // The part after the @ sign is the domain and according to RFC 1035, - // section 3.1: "Name servers and resolvers must compare [domains] in a - // case-insensitive manner". - $domain = Unicode::strtolower($matches[1]); - - $whitelisted_domains[$domain] = $domain; - unset($whitelisted_addresses[$key]); - } - } - - // Compare original addresses with whitelisted. - $invalid = 0; - foreach ($original_addresses as $email) { - - // Just ignore all invalid email addresses. - if (\Drupal::service('email.validator')->isValid($email) === FALSE) { - $invalid++; - continue; - } - - // Check whitelisted emails and domains. - $domain = Unicode::strtolower((new EmailParser(new EmailLexer()))->parse($email)['domain']); - if (in_array($email, $whitelisted_addresses, TRUE) || - in_array($domain, $whitelisted_domains, TRUE)) { - continue; - } - - // No need to continue if at least one address should be rerouted. - $message['header']['X-Reroute-Status'] = 'REROUTED'; - return TRUE; - } - - // Reroute if all addresses are invalid. - if (count($original_addresses) === $invalid) { - $message['header']['X-Reroute-Status'] = 'INVALID-ADDRESSES'; - return TRUE; - } - - // All addresses passes whitelist checks. - $message['header']['X-Reroute-Status'] = 'WHITELISTED'; - return FALSE; -} - -/** - * Split a string into an array by pre defined allowed delimiters. - * - * Items may be separated by any number and combination of: - * spaces, commas, semicolons, or newlines. - * - * @param string $string - * A string to be split into an array. - * - * @return array - * An array of unique values from a string. - */ -function reroute_email_split_string($string) { - $array = preg_split('/[\s,;\n]+/', $string, -1, PREG_SPLIT_NO_EMPTY); - - // Remove duplications. - $array = array_unique($array); - - return $array; -} diff --git a/web/modules/reroute_email/reroute_email.permissions.yml b/web/modules/reroute_email/reroute_email.permissions.yml deleted file mode 100644 index 8ebee741ac..0000000000 --- a/web/modules/reroute_email/reroute_email.permissions.yml +++ /dev/null @@ -1,3 +0,0 @@ -'administer reroute email': - title: 'Administer Reroute Email' - description: 'Administer the Reroute Email module.' diff --git a/web/modules/reroute_email/reroute_email.routing.yml b/web/modules/reroute_email/reroute_email.routing.yml deleted file mode 100644 index fe5f375657..0000000000 --- a/web/modules/reroute_email/reroute_email.routing.yml +++ /dev/null @@ -1,14 +0,0 @@ -reroute_email.settings: - path: /admin/config/development/reroute_email - defaults: - _title: 'Reroute Email' - _form: \Drupal\reroute_email\Form\SettingsForm - requirements: - _permission: 'administer reroute email' -reroute_email.test_email_form: - path: /admin/config/development/reroute_email/test - defaults: - _title: 'Test email form' - _form: \Drupal\reroute_email\Form\TestEmailForm - requirements: - _permission: 'administer reroute email' diff --git a/web/modules/reroute_email/src/Form/SettingsForm.php b/web/modules/reroute_email/src/Form/SettingsForm.php deleted file mode 100644 index 4110d7e056..0000000000 --- a/web/modules/reroute_email/src/Form/SettingsForm.php +++ /dev/null @@ -1,215 +0,0 @@ -<?php - -namespace Drupal\reroute_email\Form; - -use Drupal\Core\Config\ConfigFactoryInterface; -use Drupal\Core\Extension\ModuleHandlerInterface; -use Drupal\Core\Form\ConfigFormBase; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Render\RendererInterface; -use Egulias\EmailValidator\EmailValidator; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Implements a settings form for Reroute Email configuration. - */ -class SettingsForm extends ConfigFormBase { - - /** - * An editable config. - * - * @var \Drupal\Core\Config\Config - */ - protected $rerouteConfig; - - /** - * The module handler service. - * - * @var \Drupal\Core\Extension\ModuleHandlerInterface - */ - protected $moduleHandler; - - /** - * The renderer. - * - * @var \Drupal\Core\Render\RendererInterface - */ - protected $renderer; - - /** - * The email validator. - * - * @var \Egulias\EmailValidator\EmailValidator - */ - protected $emailValidator; - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'reroute_email_settings'; - } - - /** - * {@inheritdoc} - */ - protected function getEditableConfigNames() { - return ['reroute_email.settings']; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('config.factory'), - $container->get('module_handler'), - $container->get('renderer'), - $container->get('email.validator') - ); - } - - /** - * Constructs a new object. - * - * @param \Drupal\Core\Config\ConfigFactoryInterface $config_factory - * The factory for configuration objects. - * @param \Drupal\Core\Extension\ModuleHandlerInterface $module_handler - * The module handler service. - * @param \Drupal\Core\Render\RendererInterface $renderer - * The renderer. - * @param \Egulias\EmailValidator\EmailValidator $email_validator - * The email validator. - */ - public function __construct(ConfigFactoryInterface $config_factory, ModuleHandlerInterface $module_handler, RendererInterface $renderer, EmailValidator $email_validator) { - parent::__construct($config_factory); - $this->rerouteConfig = $this->config('reroute_email.settings'); - $this->moduleHandler = $module_handler; - $this->renderer = $renderer; - $this->emailValidator = $email_validator; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state) { - $form[REROUTE_EMAIL_ENABLE] = [ - '#type' => 'checkbox', - '#title' => $this->t('Enable rerouting'), - '#default_value' => $this->rerouteConfig->get(REROUTE_EMAIL_ENABLE), - '#description' => $this->t('Check this box if you want to enable email rerouting. Uncheck to disable rerouting.'), - ]; - - $default_address = $this->rerouteConfig->get(REROUTE_EMAIL_ADDRESS); - if (NULL === $default_address) { - $default_address = $this->config('system.site')->get('mail'); - } - - $states = [ - 'visible' => [':input[name=' . REROUTE_EMAIL_ENABLE . ']' => ['checked' => TRUE]], - ]; - - $form[REROUTE_EMAIL_ADDRESS] = [ - '#type' => 'textfield', - '#title' => $this->t('Rerouting email addresses'), - '#default_value' => $default_address, - '#description' => $this->t('Provide a space, comma, or semicolon-delimited list of email addresses.<br/>Every destination email address which is not on "Whitelisted email addresses" list will be rerouted to these addresses.<br/>If the field is empty and no value is provided, all outgoing emails would be aborted and the email would be recorded in the recent log entries (if enabled).'), - '#element_validate' => [[$this, 'validateFormEmails']], - '#states' => $states, - ]; - - $form[REROUTE_EMAIL_WHITELIST] = [ - '#type' => 'textfield', - '#title' => $this->t('Whitelisted email addresses'), - '#default_value' => $this->rerouteConfig->get(REROUTE_EMAIL_WHITELIST), - '#description' => $this->t('Provide a space, comma, or semicolon-delimited list of email addresses to pass through. <br/>Every destination email address which is not on this list will be rerouted.<br/>If the field is empty and no value is provided, all outgoing emails would be rerouted.<br/>We can use wildcard email "*@example.com" to whitelist all emails by the domain.'), - '#element_validate' => [[$this, 'validateFormEmails']], - '#states' => $states, - ]; - - $form[REROUTE_EMAIL_DESCRIPTION] = [ - '#type' => 'checkbox', - '#title' => $this->t('Show rerouting description in mail body'), - '#default_value' => $this->rerouteConfig->get(REROUTE_EMAIL_DESCRIPTION), - '#description' => $this->t('Check this box if you want a message to be inserted into the email body when the mail is being rerouted. Otherwise, SMTP headers will be used to describe the rerouting. If sending rich-text email, leave this unchecked so that the body of the email will not be disturbed.'), - '#states' => $states, - ]; - - $form[REROUTE_EMAIL_MESSAGE] = [ - '#type' => 'checkbox', - '#title' => $this->t('Display a Drupal status message after rerouting'), - '#default_value' => $this->rerouteConfig->get(REROUTE_EMAIL_MESSAGE), - '#description' => $this->t('Check this box if you would like a Drupal status message to be displayed to users after submitting an email to let them know it was rerouted to a different email address.'), - '#states' => $states, - ]; - - // Format a list of modules that implement hook_mail. - $mail_modules = $this->moduleHandler->getImplementations('mail'); - $all_modules = $this->moduleHandler->getModuleList(); - foreach ($mail_modules as $key => $module) { - $mail_modules[$key] = $this->t("%module's module possible mail keys are `@machine_name`, `@machine_name_%`;", [ - '%module' => isset($all_modules[$module]->info['name']) ? $all_modules[$module]->info['name'] : $module, - '@machine_name' => $module, - ]); - } - $mail_modules = ['#theme' => 'item_list', '#items' => $mail_modules]; - - $form['mailkeys'] = [ - '#type' => 'details', - '#title' => $this->t('Advanced settings'), - '#states' => $states, - '#open' => $this->rerouteConfig->get(REROUTE_EMAIL_MAILKEYS, '') !== '', - ]; - - $form['mailkeys'][REROUTE_EMAIL_MAILKEYS] = [ - '#title' => $this->t('Filter by mail keys:'), - '#type' => 'textarea', - '#rows' => 3, - '#default_value' => $this->rerouteConfig->get(REROUTE_EMAIL_MAILKEYS, ''), - '#description' => $this->t('Provide a space, comma, semicolon, or newline-delimited list of message keys to be rerouted. Either module machine name or specific mail key can be used for that.<br/>Only matching messages will be rerouted. If left empty (as default), <strong>all emails will be selected for rerouting</strong>. Here is a list of modules that send emails:<br/>@modules_list Where `%` is one of a specific mail key provided by the module.', [ - '@modules_list' => $this->renderer->render($mail_modules), - ]), - ]; - - return parent::buildForm($form, $form_state); - } - - /** - * Validate multiple email addresses field. - * - * @param array $element - * A field array to validate. - * @param \Drupal\Core\Form\FormStateInterface $form_state - * The current state of the form. - */ - public function validateFormEmails(array $element, FormStateInterface $form_state) { - // Allow only valid email addresses. - $addresses = reroute_email_split_string($form_state->getValue($element['#name'])); - foreach ($addresses as $address) { - if (!$this->emailValidator->isValid($address)) { - $form_state->setErrorByName($element['#name'], $this->t('@address is not a valid email address.', ['@address' => $address])); - } - } - - // Save value in usable way to use as `to` param in drupal_mail. - // String "email@example.com; ;; , ,," save just as "email@example.com". - // This will be ignored if any validation errors occur. - $form_state->setValue($element['#name'], implode(',', $addresses)); - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $this->rerouteConfig - ->set(REROUTE_EMAIL_ENABLE, $form_state->getValue(REROUTE_EMAIL_ENABLE)) - ->set(REROUTE_EMAIL_ADDRESS, $form_state->getValue(REROUTE_EMAIL_ADDRESS)) - ->set(REROUTE_EMAIL_WHITELIST, $form_state->getValue(REROUTE_EMAIL_WHITELIST)) - ->set(REROUTE_EMAIL_DESCRIPTION, $form_state->getValue(REROUTE_EMAIL_DESCRIPTION)) - ->set(REROUTE_EMAIL_MESSAGE, $form_state->getValue(REROUTE_EMAIL_MESSAGE)) - ->set(REROUTE_EMAIL_MAILKEYS, $form_state->getValue(REROUTE_EMAIL_MAILKEYS)) - ->save(); - parent::submitForm($form, $form_state); - } - -} diff --git a/web/modules/reroute_email/src/Form/TestEmailForm.php b/web/modules/reroute_email/src/Form/TestEmailForm.php deleted file mode 100644 index fc46001d6f..0000000000 --- a/web/modules/reroute_email/src/Form/TestEmailForm.php +++ /dev/null @@ -1,116 +0,0 @@ -<?php - -namespace Drupal\reroute_email\Form; - -use Drupal\Core\Form\FormBase; -use Drupal\Core\Form\FormStateInterface; -use Drupal\Core\Language\LanguageManagerInterface; -use Drupal\Core\Mail\MailManagerInterface; -use Symfony\Component\DependencyInjection\ContainerInterface; - -/** - * Implements a form to test Reroute Email. - */ -class TestEmailForm extends FormBase { - - /** - * The mail manager. - * - * @var \Drupal\Core\Mail\MailManagerInterface - */ - protected $mailManager; - - /** - * The language manager service. - * - * @var \Drupal\Core\Language\LanguageManagerInterface - */ - protected $languageManager; - - /** - * {@inheritdoc} - */ - public function getFormId() { - return 'reroute_email_test_email_form'; - } - - /** - * {@inheritdoc} - */ - public static function create(ContainerInterface $container) { - return new static( - $container->get('plugin.manager.mail'), - $container->get('language_manager') - ); - } - - /** - * Constructs a new object. - * - * @param \Drupal\Core\Mail\MailManagerInterface $mail_manager - * Mail manager service. - * @param \Drupal\Core\Language\LanguageManagerInterface $language_manager - * The language manager. - */ - public function __construct(MailManagerInterface $mail_manager, LanguageManagerInterface $language_manager) { - $this->mailManager = $mail_manager; - $this->languageManager = $language_manager; - } - - /** - * {@inheritdoc} - */ - public function buildForm(array $form, FormStateInterface $form_state) { - return [ - 'addresses' => [ - '#type' => 'fieldset', - '#description' => $this->t('A list of addresses separated by a comma could be submitted.<br/>Email addresses are not validated: any valid or invalid email address format could be submitted.'), - 'to' => [ - '#type' => 'textfield', - '#title' => $this->t('To'), - '#required' => TRUE, - ], - 'cc' => [ - '#type' => 'textfield', - '#title' => $this->t('Cc'), - ], - 'bcc' => [ - '#type' => 'textfield', - '#title' => $this->t('Bcc'), - ], - ], - 'subject' => [ - '#type' => 'textfield', - '#title' => $this->t('Subject'), - '#default_value' => $this->t('Reroute Email Test'), - ], - 'body' => [ - '#type' => 'textarea', - '#title' => $this->t('Body'), - '#default_value' => $this->t('Reroute Email Body'), - ], - 'submit' => [ - '#type' => 'submit', - '#value' => $this->t('Send email'), - ], - ]; - } - - /** - * {@inheritdoc} - */ - public function submitForm(array &$form, FormStateInterface $form_state) { - $to = $form_state->getValue(['to']); - $param_keys = ['cc', 'bcc', 'subject', 'body']; - $params = array_intersect_key($form_state->getValues(), array_flip($param_keys)); - $langcode = $this->languageManager->getDefaultLanguage(); - - // Send email with drupal_mail. - $message = $this->mailManager->mail('reroute_email', 'test_email_form', $to, $langcode, $params); - - if (!empty($message['result'])) { - drupal_set_message($this->t('Test email submitted for delivery from test form.')); - } - } - -} diff --git a/web/modules/reroute_email/tests/modules/reroute_email_test/reroute_email_test.info.yml b/web/modules/reroute_email/tests/modules/reroute_email_test/reroute_email_test.info.yml deleted file mode 100644 index 80e4a72c41..0000000000 --- a/web/modules/reroute_email/tests/modules/reroute_email_test/reroute_email_test.info.yml +++ /dev/null @@ -1,12 +0,0 @@ -name: 'Reroute Email Test' -description: 'Helper module for the reroute email tests.' -# core: 8.x -package: Testing -hidden: true -type: module - -# Information added by Drupal.org packaging script on 2017-12-15 -version: '8.x-1.0' -core: '8.x' -project: 'reroute_email' -datestamp: 1513342688 diff --git a/web/modules/reroute_email/tests/modules/reroute_email_test/reroute_email_test.module b/web/modules/reroute_email/tests/modules/reroute_email_test/reroute_email_test.module deleted file mode 100644 index 331ce56551..0000000000 --- a/web/modules/reroute_email/tests/modules/reroute_email_test/reroute_email_test.module +++ /dev/null @@ -1,70 +0,0 @@ -<?php - -/** - * @file - * Provides Mail hook implementations for testing the Reroute Email module. - */ - -/** - * Implements hook_module_implements_alter(). - * - * Ensure reroute_email_test runs last when hook_mail_alter is invoked. - */ -function reroute_email_test_module_implements_alter(&$implementations, $hook) { - // Testing with isset is only necessary if module doesn't implement the hook. - if ($hook == 'mail_alter') { - // Move our hook implementation to the bottom. - $group = $implementations['reroute_email_test']; - unset($implementations['reroute_email_test']); - $implementations['reroute_email_test'] = $group; - } -} - -/** - * Implements hook_mail(). - * - * This function allows testing Reroute Email's handling of a string passed for - * message's body instead of an Array as required by drupal_mail. It also - * allows testing the robustness of the handling of Cc and Bcc header keys. - * Body, Cc and Bcc values are initialized from test case through $params. - */ -function reroute_email_test_mail($key, &$message, $params) { - if ($key != 'test_reroute_email') { - return; - } - $message['subject'] = 'Reroute Email Test: Message body is a string, Cc and Bcc header keys have a special case'; - - // Body is provided as a string. - if (!empty($params['body'])) { - $message['body'] = $params['body']; - } - // Provide Cc and Bcc headers with an unexpected case. - if (!empty($params['headers']['test_cc_key']) && !empty($params['headers'][$params['headers']['test_cc_key']])) { - $message['headers'][$params['headers']['test_cc_key']] = $params['headers'][$params['headers']['test_cc_key']]; - } - if (!empty($params['headers']['test_bcc_key']) && !empty($params['headers'][$params['headers']['test_bcc_key']])) { - $message['headers'][$params['headers']['test_bcc_key']] = $params['headers'][$params['headers']['test_bcc_key']]; - } -} - -/** - * Implements hook_mail_alter(). - * - * This helper function is necessary to catch message's body if it is a string - * to make it an array to be compliant with drupal_mail and prevent a Warning: - * implode(): Invalid arguments passed in DefaultMailSystem->format(). - */ -function reroute_email_test_mail_alter(&$message) { - // Only alter the email for the key test_reroute_email. - if ($message['key'] != 'test_reroute_email') { - return; - } - // Prevent Warning from drupal_mail because body is not an array, only if - // message has already been processed by reroute_email. - if (is_string($message['body']) && isset($message['headers']['X-Rerouted-Mail-Key'])) { - // Record to be checked in test in the log entries. - \Drupal::logger('reroute_email_test')->notice('A String was detected in the body: <pre>@body</pre>', ['@body' => $message['body']]); - // Convert body to an Array. - $message['body'] = [$message['body']]; - } -} diff --git a/web/modules/reroute_email/tests/src/Functional/ContactTest.php b/web/modules/reroute_email/tests/src/Functional/ContactTest.php deleted file mode 100644 index ec36629668..0000000000 --- a/web/modules/reroute_email/tests/src/Functional/ContactTest.php +++ /dev/null @@ -1,121 +0,0 @@ -<?php - -namespace Drupal\Tests\reroute_email\Functional; - -use Drupal\Component\Render\FormattableMarkup; - -/** - * Test ability to reroute mail sent from the Contact module form. - * - * @ingroup reroute_email_tests - * - * @group reroute_email - */ -class ContactTest extends RerouteEmailTestBase { - - public static $modules = ['reroute_email', 'contact']; - - protected $confirmationMessage; - - /** - * Enable modules and create user with specific permissions. - */ - public function setUp() { - - // Add more permissions to be able to manipulate the contact forms. - $this->permissions[] = 'administer contact forms'; - $this->permissions[] = 'access site-wide contact form'; - $this->confirmationMessage = 'Your message has been sent.'; - - parent::setUp(); - - // Create a "feedback" contact form. Note that the 'message' was added in - // the 8.2.x series, and is not there in 8.1.x, so this could fail in 8.1.x. - $this->drupalPostForm('admin/structure/contact/add', [ - 'label' => 'feedback', - 'id' => 'feedback', - 'recipients' => $this->originalDestination, - 'message' => $this->confirmationMessage, - 'selected' => TRUE, - ], 'Save'); - $this->assertResponse(200, 'Contact form named "feedback" added.'); - - // Make sure that the flood controls don't break the test. - \Drupal::service('config.factory')->getEditable('contact.settings') - ->set('flood.limit', 1000) - ->set('flood.interval', 60); - } - - /** - * Basic tests of email rerouting for emails sent through the Contact forms. - * - * The Core Contact email form is submitted several times with different - * Email Rerouting settings: Rerouting enabled or disabled, Body injection - * enabled or disabled, several recipients with or without whitelist. - */ - public function testBasicNotification() { - // Additional destination email address used for testing the whitelist. - $additional_destination = 'additional@example.com'; - - // Configure to reroute to {$this->rerouteDestination}. - $this->configureRerouteEmail(TRUE, $this->rerouteDestination); - - // Configure the contact settings to send to $original_destination. - $this->drupalPostForm('admin/structure/contact/manage/feedback', ['recipients' => $this->originalDestination], t('Save')); - - // Go to the contact page and send an email. - $post = ['subject[0][value]' => 'Test test test', 'message[0][value]' => 'This is a test']; - $this->drupalPostForm('contact', $post, 'Send message'); - $this->assertResponse(200, 'Posted contact form successfully.'); - $this->assertText($this->confirmationMessage); - - // Check rerouted email. - $this->assertMail('to', $this->rerouteDestination, new FormattableMarkup('Email was rerouted to @address.', ['@address' => $this->rerouteDestination])); - $this->assertEmailOriginallyTo(); - - // Now try sending to one of the additional email addresses that should - // not be rerouted. Configure two email addresses in reroute form. - // Body injection is still turned on. - $this->configureRerouteEmail(NULL, $this->rerouteDestination, "{$this->rerouteDestination}, {$additional_destination}"); - - // Configure the contact settings to point to the additional recipient. - $this->drupalPostForm('admin/structure/contact/manage/feedback', ['recipients' => $additional_destination], t('Save')); - - // Go to the contact page and send an email. - $post = ['subject[0][value]' => 'Test test test', 'message[0][value]' => 'This is a test']; - $this->drupalPostForm('contact', $post, t('Send message')); - $this->assertText($this->confirmationMessage); - $this->assertMail('to', $additional_destination, 'Email was not rerouted because destination was in whitelist.'); - - // Now change the configuration to disable reroute and set the default - // email recipients (from system.site.mail) - $this->configureRerouteEmail(FALSE); - - // Set the contact form to send to original_destination. - $this->drupalPostForm('admin/structure/contact/manage/feedback', ['recipients' => $this->originalDestination], t('Save')); - - // Go to the contact page and send an email. - $post = ['subject[0][value]' => 'Test test test', 'message[0][value]' => 'This is a test']; - $this->drupalPostForm('contact', $post, t('Send message')); - $this->assertText($this->confirmationMessage); - - // Mail should not be rerouted - should go to $original_destination. - $this->assertMail('to', $this->originalDestination, 'Mail not rerouted - sent to original destination.'); - - // Configure to reroute without body injection. - $this->configureRerouteEmail(TRUE, $this->rerouteDestination, '', FALSE); - - // Go to the contact page and send an email. - $post = ['subject[0][value]' => 'Test test test', 'message[0][value]' => 'This is a test']; - $this->drupalPostForm('contact', $post, t('Send message')); - $this->assertText($this->confirmationMessage); - $mails = $this->getMails(); - $mail = end($mails); - - // There should be nothing in the body except the contact message - no - // body injection like 'Originally to'. - $this->assertTrue(strpos($mail['body'], 'Originally to') === FALSE, 'Body does not contain "Originally to".'); - $this->assertEqual($mail['headers']['X-Rerouted-Original-To'], $this->originalDestination, 'X-Rerouted-Original-To is correctly set to the original destination email.'); - } - -} diff --git a/web/modules/reroute_email/tests/src/Functional/DefaultAddressesTest.php b/web/modules/reroute_email/tests/src/Functional/DefaultAddressesTest.php deleted file mode 100644 index 8dc222ad68..0000000000 --- a/web/modules/reroute_email/tests/src/Functional/DefaultAddressesTest.php +++ /dev/null @@ -1,111 +0,0 @@ -<?php - -namespace Drupal\Tests\reroute_email\Functional; - -use Drupal\Component\Render\FormattableMarkup; - -/** - * Test for default address. - * - * When reroute email addresses field is not configured, attempt to use the site - * email address, otherwise use sendmail_from system variable. - * - * @ingroup reroute_email_tests - * - * @group reroute_email - */ -class DefaultAddressesTest extends RerouteEmailTestBase { - - public static $modules = ['reroute_email', 'dblog']; - - /** - * Enable modules and create user with specific permissions. - */ - public function setUp() { - // Add more permissions to access recent log messages in test. - $this->permissions[] = 'access site reports'; - parent::setUp(); - } - - /** - * Test reroute email address is set to site_mail, sendmail_from or empty. - * - * When reroute email addresses field is not configured and settings haven't - * been configured yet, check if the site email address or the sendmail_from - * system variable are properly used as fallbacks. Additionally, check that - * emails are aborted and a watchdog entry logged if reroute email address is - * set to an empty string. - */ - public function testRerouteDefaultAddress() { - - // Check default value for reroute_email_address when not configured. - // If system.site's 'mail' is not empty, it should be the default value. - $site_mail = $this->config('system.site')->get('mail'); - $this->assertTrue(isset($site_mail), new FormattableMarkup('Site mail is not empty: @site_mail.', ['@site_mail' => $site_mail])); - - // Programmatically enable email rerouting. - $this->rerouteConfig->set(REROUTE_EMAIL_ENABLE, TRUE)->save(); - - // Load the Reroute Email Settings form page. Ensure rerouting is enabled. - $this->drupalGet('admin/config/development/reroute_email'); - $this->assertFieldChecked('edit-enable', 'Email rerouting was programmatically successfully enabled.'); - $this->assertTrue($this->rerouteConfig->get(REROUTE_EMAIL_ENABLE), 'Rerouting is enabled.'); - - // Email addresses field default value is system.site.mail. - $this->assertFieldByName(REROUTE_EMAIL_ADDRESS, $site_mail, new FormattableMarkup('reroute_email_address default value on form is system.site.mail value: @site_mail.', ['@site_mail' => $site_mail])); - - // Ensure reroute_email_address is actually empty at this point. - $this->assertNull($this->rerouteConfig->get(REROUTE_EMAIL_ADDRESS), 'Reroute email destination address is not configured.'); - - // Submit a test email, check if it is rerouted to system.site.mail address. - $this->drupalPostForm('admin/config/development/reroute_email/test', ['to' => 'to@example.com'], 'Send email'); - $this->assertText(t('Test email submitted for delivery from test form.')); - $this->assert(count($this->getMails()) === 1, 'Exactly one email captured.'); - $this->verboseEmail(); - - // Check rerouted email is the site email address. - $this->assertMail('to', $site_mail, new FormattableMarkup('Email was properly rerouted to site email address: @default_destination.', ['@default_destination' => $site_mail])); - - // Unset system.site.mail. - $this - ->config('system.site') - ->set('mail', NULL) - ->save(); - - // Configure whitelisted addresses as an empty string to about all emails. - $this->configureRerouteEmail(TRUE, '', ''); - - // Make sure configured emails values are an empty string. - $this->assertTrue($this->rerouteConfig->get(REROUTE_EMAIL_ADDRESS) === '', 'Reroute email destination address is an empty string.'); - $this->assertTrue($this->rerouteConfig->get(REROUTE_EMAIL_WHITELIST) === '', 'Whitelisted email address is an empty string.'); - - // Flush the Test Mail collector to ensure it is empty for this tests. - \Drupal::state()->set('system.test_mail_collector', []); - - // Submit a test email to check if it is aborted. - $this->drupalPostForm('admin/config/development/reroute_email/test', ['to' => 'to@example.com'], t('Send email')); - $mails = $this->getMails(); - $mail = end($mails); - $this->assertTrue(count($mails) == 0, 'Email sending was properly aborted because rerouting email address is an empty string.'); - - // Check status message is displayed properly after email form submission. - $this->assertPattern(t('/@message_id.*was aborted by reroute email/', ['@message_id' => $mail['id']]), - new FormattableMarkup('Status message displayed as expected to the user with the mail ID <em>(@message_id)</em> and a link to recent log entries.', ['@message_id' => $mail['id']])); - - // Check the watchdog entry logged with aborted email message. - $this->drupalGet('admin/reports/dblog'); - - // Check the link to the watchdog detailed message. - $dblog_link = $this->xpath('//table[@id="admin-dblog"]/tbody/tr[contains(@class,"dblog-reroute-email")][1]/td[text()="reroute_email"]/following-sibling::td/a[contains(text(),"reroute_email")]'); - $link_label = $dblog_link[0]->getText(); - $this->assertTrue(isset($dblog_link[0]), new FormattableMarkup('Logged a message in dblog: <em>@link</em>.', ['@link' => $link_label])); - - // Open the full view page of the log message found for reroute_email. - $this->clickLink($link_label); - - // Ensure the correct email is logged with default 'to' placeholder. - $this->assertPattern(t('/Aborted email sending for.*@message_id.*Detailed email data/', ['@message_id' => $mail['id']]), - new FormattableMarkup('The dblog entry recorded by Reroute Email contains a dump of the aborted email message <em>@message_id</em> and is formatted as expected.', ['@message_id' => $mail['id']])); - } - -} diff --git a/web/modules/reroute_email/tests/src/Functional/DomainWhitelistedTest.php b/web/modules/reroute_email/tests/src/Functional/DomainWhitelistedTest.php deleted file mode 100644 index 03f8d2b62d..0000000000 --- a/web/modules/reroute_email/tests/src/Functional/DomainWhitelistedTest.php +++ /dev/null @@ -1,42 +0,0 @@ -<?php - -namespace Drupal\Tests\reroute_email\Functional; - -use Drupal\Component\Render\FormattableMarkup; - -/** - * Test Reroute Email's with a domain whitelisted. - * - * @ingroup reroute_email_tests - * - * @group reroute_email - */ -class DomainWhitelistedTest extends RerouteEmailTestBase { - - /** - * Basic tests for the domain whitelisted addresses. - */ - public function testDomainWhitelistedEmail() { - // Set rerouting email and whitelisted domain. - $this->configureRerouteEmail(TRUE, $this->rerouteDestination, $this->whitelistedDomain); - - // Make sure configured emails were set. - $this->assertEqual($this->rerouteConfig->get(REROUTE_EMAIL_ADDRESS), $this->rerouteDestination, 'Reroute email address was set.'); - $this->assertEqual($this->rerouteConfig->get(REROUTE_EMAIL_WHITELIST), $this->whitelistedDomain, 'Whitelisted value was set.'); - - // Submit a test email (should be rerouted). - $to = 'some@not-exist.domain'; - $this->drupalPostForm('admin/config/development/reroute_email/test', ['to' => $to], t('Send email')); - - // Check if the email was rerouted properly. - $this->assertEmailOriginallyTo($to); - $this->assertMail('to', $this->rerouteDestination, new FormattableMarkup('Email was properly rerouted to the email address: @destination.', ['@destination' => $this->rerouteDestination])); - - // Submit a test email (should not be rerouted). - $this->drupalPostForm('admin/config/development/reroute_email/test', ['to' => $this->originalDestination], t('Send email')); - - // Check if the email was rerouted properly. - $this->assertMail('to', $this->originalDestination, new FormattableMarkup('Email was properly sent the email address: @destination.', ['@destination' => $this->originalDestination])); - } - -} diff --git a/web/modules/reroute_email/tests/src/Functional/MailKeysTest.php b/web/modules/reroute_email/tests/src/Functional/MailKeysTest.php deleted file mode 100644 index 1ee3fac961..0000000000 --- a/web/modules/reroute_email/tests/src/Functional/MailKeysTest.php +++ /dev/null @@ -1,53 +0,0 @@ -<?php - -namespace Drupal\Tests\reroute_email\Functional; - -use Drupal\Component\Render\FormattableMarkup; - -/** - * Test Reroute Email with mail keys filter. - * - * @ingroup reroute_email_tests - * - * @group reroute_email - */ -class MailKeysTest extends RerouteEmailTestBase { - - /** - * Test Reroute Email with mail keys filter. - */ - public function testMailKeysFilter() { - // Configure to reroute all outgoing emails. - $this->configureRerouteEmail(TRUE, $this->rerouteDestination); - - // Submit a test email (should be rerouted). - $this->drupalPostForm('admin/config/development/reroute_email/test', ['to' => $this->originalDestination], t('Send email')); - - // Check if the email was rerouted properly. - $this->assertEmailOriginallyTo(); - $this->assertMail('to', $this->rerouteDestination, new FormattableMarkup('Email was properly rerouted to the email address: @destination.', ['@destination' => $this->rerouteDestination])); - - // Configure to reroute outgoing emails only from our test module. - $this->configureRerouteEmail(NULL, NULL, NULL, NULL, NULL, 'not_existed_module'); - - // Submit a test email (should not be rerouted). - $this->drupalPostForm('admin/config/development/reroute_email/test', ['to' => $this->originalDestination], t('Send email')); - - // Check if the email was not rerouted. - $this->assertMail('to', $this->originalDestination, new FormattableMarkup('Email was properly sent the email addresses: @destination.', ['@destination' => $this->originalDestination])); - - // Configure to reroute only outgoing emails from our test form. - $this->configureRerouteEmail(NULL, NULL, NULL, NULL, NULL, 'reroute_email_test_email_form'); - - // Submit a test email (should be rerouted). - $this->drupalPostForm('admin/config/development/reroute_email/test', ['to' => $this->originalDestination], t('Send email')); - - // Check if the email was rerouted properly. - $this->assertEmailOriginallyTo(); - $this->assertMail('to', $this->rerouteDestination, new FormattableMarkup('Email was properly rerouted to the email address: @destination.', ['@destination' => $this->rerouteDestination])); - - // Configure to reroute outgoing emails only from our test module. - $this->configureRerouteEmail(NULL, NULL, NULL, NULL, NULL, 'reroute_email_test'); - } - -} diff --git a/web/modules/reroute_email/tests/src/Functional/MultipleRecipientsTest.php b/web/modules/reroute_email/tests/src/Functional/MultipleRecipientsTest.php deleted file mode 100644 index 8d06e7fa00..0000000000 --- a/web/modules/reroute_email/tests/src/Functional/MultipleRecipientsTest.php +++ /dev/null @@ -1,45 +0,0 @@ -<?php - -namespace Drupal\Tests\reroute_email\Functional; - -use Drupal\Component\Render\FormattableMarkup; - -/** - * Test Reroute Email with multiple recipients. - * - * @ingroup reroute_email_tests - * - * @group reroute_email - */ -class MultipleRecipientsTest extends RerouteEmailTestBase { - - /** - * Test Reroute Email with multiple recipients. - */ - public function testMultipleRecipients() { - // Set multiple whitelisted domain and rerouting emails. Multiple commas and - // semicolons are added for validation tests. - $this->configureRerouteEmail(TRUE, 'user1@example.com, user2@example.com,;;,,user@example.com', $this->whitelistedDomain); - - // Make sure configured emails were set properly. - $reroute_to = 'user1@example.com,user2@example.com,user@example.com'; - $this->assertEqual($this->rerouteConfig->get(REROUTE_EMAIL_ADDRESS), $reroute_to, 'Reroute email address was set.'); - $this->assertEqual($this->rerouteConfig->get(REROUTE_EMAIL_WHITELIST), $this->whitelistedDomain, 'Whitelisted value was set.'); - - // Submit a test email (should be rerouted). - $to = 'some@not-exist.domain, whitelisted@example.com'; - $this->drupalPostForm('admin/config/development/reroute_email/test', ['to' => $to], t('Send email')); - - // Check if the email was rerouted properly. - $this->assertEmailOriginallyTo($to); - $this->assertMail('to', $reroute_to, new FormattableMarkup('Email was properly rerouted to the email address: @destination.', ['@destination' => $reroute_to])); - - // Submit a test email (should not be rerouted). - $to = 'whitelisted@example.com, user2@example.com, allowed@example.com'; - $this->drupalPostForm('admin/config/development/reroute_email/test', ['to' => $to], t('Send email')); - - // Check if the email was not rerouted. - $this->assertMail('to', $to, new FormattableMarkup('Email was properly sent the email addresses: @destination.', ['@destination' => $to])); - } - -} diff --git a/web/modules/reroute_email/tests/src/Functional/RerouteEmailTestBase.php b/web/modules/reroute_email/tests/src/Functional/RerouteEmailTestBase.php deleted file mode 100644 index 620ef36f65..0000000000 --- a/web/modules/reroute_email/tests/src/Functional/RerouteEmailTestBase.php +++ /dev/null @@ -1,167 +0,0 @@ -<?php - -namespace Drupal\Tests\reroute_email\Functional; - -use Drupal\Component\Render\FormattableMarkup; -use Drupal\Core\Test\AssertMailTrait; -use Drupal\Tests\BrowserTestBase; - -/** - * @defgroup reroute_email_tests Test Suit - * - * @{ - * The automated test suit for Reroute Email. - * - * @} - */ - -/** - * Base test class for Reroute Email test cases. - */ -abstract class RerouteEmailTestBase extends BrowserTestBase { - - use AssertMailTrait; - - /** - * An editable config. - * - * @var \Drupal\Core\Config\Config - */ - protected $rerouteConfig; - - /** - * An array of helper modules for the reroute email tests. - * - * @var array - */ - public static $modules = ['reroute_email']; - - /** - * User object to perform site browsing. - * - * @var \Drupal\user\Entity\User - */ - protected $adminUser; - - /** - * Original email address used for the tests. - * - * @var string - */ - protected $originalDestination = 'original@example.com'; - - /** - * Reroute email destination address used for the tests. - * - * @var string - */ - protected $rerouteDestination = 'rerouted@example.com'; - - /** - * Whitelisted domain destination address used for the tests. - * - * @var string - */ - protected $whitelistedDomain = '*@example.com'; - - /** - * Permissions required by the user to perform the tests. - * - * @var array - */ - protected $permissions = [ - 'administer reroute email', - ]; - - /** - * {@inheritdoc} - */ - protected function setUp() { - parent::setUp(); - $this->rerouteConfig = $this->config('reroute_email.settings'); - - // Authenticate test user. - $this->adminUser = $this->drupalCreateUser($this->permissions); - $this->drupalLogin($this->adminUser); - } - - /** - * Helper function to configure Reroute Email Settings. - * - * @param bool $enable - * (optional) Set to TRUE to enable email Rerouting. - * @param string $addresses - * (optional) The email addresses to which emails should be rerouted. - * @param string $whitelisted - * (optional) The whitelisted email addresses. - * @param bool $description - * (optional) Set to TRUE to show rerouting description. - * @param bool $message - * (optional) Set to TRUE to display a status message after rerouting. - * @param string $mailkeys - * (optional) A list of modules or mail keys should be rerouted, defaults to - * empty string (all outgoing emails are rerouted). - */ - public function configureRerouteEmail($enable = NULL, $addresses = NULL, $whitelisted = NULL, $description = NULL, $message = NULL, $mailkeys = NULL) { - $current_values = $install_values = [ - REROUTE_EMAIL_ENABLE => FALSE, - REROUTE_EMAIL_ADDRESS => '', - REROUTE_EMAIL_WHITELIST => '', - REROUTE_EMAIL_DESCRIPTION => TRUE, - REROUTE_EMAIL_MESSAGE => TRUE, - REROUTE_EMAIL_MAILKEYS => '', - ]; - - foreach ($install_values as $key => $value) { - $current_values[$key] = NULL === $this->rerouteConfig->get($key) ? $value : $this->rerouteConfig->get($key); - } - - // Configure to Reroute Email settings form. - $post = [ - REROUTE_EMAIL_ENABLE => NULL === $enable ? $current_values[REROUTE_EMAIL_ENABLE] : $enable, - REROUTE_EMAIL_ADDRESS => NULL === $addresses ? $current_values[REROUTE_EMAIL_ADDRESS] : $addresses, - REROUTE_EMAIL_WHITELIST => NULL === $whitelisted ? $current_values[REROUTE_EMAIL_WHITELIST] : $whitelisted, - REROUTE_EMAIL_DESCRIPTION => NULL === $description ? $current_values[REROUTE_EMAIL_DESCRIPTION] : $description, - REROUTE_EMAIL_MESSAGE => NULL === $message ? $current_values[REROUTE_EMAIL_MESSAGE] : $message, - REROUTE_EMAIL_MAILKEYS => NULL === $mailkeys ? $current_values[REROUTE_EMAIL_MAILKEYS] : $mailkeys, - ]; - - // Submit Reroute Email Settings form and check if it was successful. - $this->drupalPostForm('admin/config/development/reroute_email', $post, t('Save configuration')); - $this->assertText(t('The configuration options have been saved.')); - - // Rebuild config values after form submit. - $this->rerouteConfig = $this->config('reroute_email.settings'); - } - - /** - * Assert whether the text "Originally to: @to_email" is found in email body. - * - * @param string $original_destination - * (optional) The original email address to be found in rerouted email - * body. Defaults to $this->originalDestination if set to NULL. - */ - public function assertEmailOriginallyTo($original_destination = NULL) { - // Check most recent email. - $mails = $this->getMails(); - if (empty($mails)) { - $this->assert(FALSE, 'Email was not sent.'); - return; - } - - // Initialize $original_destination by default if no value is provided. - if (NULL === $original_destination) { - $original_destination = $this->originalDestination; - } - - // Search in $mailbody for "Originally to: $original_destination". - $mail_body = end($mails)['body']; - $search_for = t('Originally to: @to', ['@to' => $original_destination]); - $has_info = preg_match("/{$search_for}/", $mail_body); - - // Asserts whether searched text was found. - $this->assertTrue($has_info, 'Found the correct "Originally to" line in the body.'); - $this->verbose(new FormattableMarkup('Email body was: <pre>@mail_body</pre>', ['@mail_body' => $mail_body])); - } - -} diff --git a/web/modules/reroute_email/tests/src/Functional/TestEmailFormTest.php b/web/modules/reroute_email/tests/src/Functional/TestEmailFormTest.php deleted file mode 100644 index e352e5f2a3..0000000000 --- a/web/modules/reroute_email/tests/src/Functional/TestEmailFormTest.php +++ /dev/null @@ -1,108 +0,0 @@ -<?php - -namespace Drupal\Tests\reroute_email\Functional; - -use Drupal\Component\Render\FormattableMarkup; - -/** - * Test Reroute Email's form for sending a test email. - * - * @ingroup reroute_email_tests - * - * @group reroute_email - */ -class TestEmailFormTest extends RerouteEmailTestBase { - - /** - * Basic tests for reroute_email Test Email form. - * - * Check if submitted form values are properly submitted and rerouted. - * Test Subject, To, Cc, Bcc and Body submitted values, form validation, - * default values, and submission with invalid email addresses. - */ - public function testFormTestEmail() { - - // Configure to reroute to {$this->rerouteDestination}. - $this->configureRerouteEmail(TRUE, $this->rerouteDestination); - - // Check Subject field default value. - $this->drupalGet('admin/config/development/reroute_email/test'); - $this->assertFieldByName('subject', t('Reroute Email Test'), 'The expected default value was found for the Subject field.'); - - // Submit the Test Email form to send an email to be rerouted. - $post = [ - 'to' => 'to@example.com', - 'cc' => 'cc@example.com', - 'bcc' => 'bcc@example.com', - 'subject' => 'Test Reroute Email Test Email Form', - 'body' => 'Testing email rerouting and the Test Email form', - ]; - $this->drupalPostForm('admin/config/development/reroute_email/test', $post, t('Send email')); - $this->assertText(t('Test email submitted for delivery from test form.')); - $mails = $this->getMails(); - $mail = end($mails); - - // Check rerouted email. - $this->assertMail('to', $this->rerouteDestination, new FormattableMarkup('To email address was rerouted to @address.', ['@address' => $this->rerouteDestination])); - $this->assertEmailOriginallyTo($post['to']); - - // Check the Cc and Bcc headers are the ones submitted through the form. - $this->assertTrue($mail['headers']['X-Rerouted-Original-Cc'] == $post['cc'], new FormattableMarkup('X-Rerouted-Original-Cc is correctly set to submitted value: @address', ['@address' => $post['cc']])); - $this->assertTrue($mail['headers']['X-Rerouted-Original-Bcc'] == $post['bcc'], new FormattableMarkup('X-Rerouted-Original-Cc is correctly set to submitted value: @address', ['@address' => $post['bcc']])); - - // Check that Cc and Bcc headers were added to the message body. - $copy_headers = [ - 'cc' => t('Originally cc: @cc', ['@cc' => $mail['headers']['X-Rerouted-Original-Cc']]), - 'bcc' => t('Originally bcc: @bcc', ['@bcc' => $mail['headers']['X-Rerouted-Original-Bcc']]), - ]; - foreach ($copy_headers as $header => $message_line) { - $has_header = preg_match("/{$message_line}/", $mail['body']); - $this->assertTrue($has_header, new FormattableMarkup('Found the correct "@header" line in the body.', ['@header' => $header])); - } - - // Check the Subject and Body field values can be found in rerouted email. - $this->assertMail('subject', $post['subject'], new FormattableMarkup('Subject is correctly set to submitted value: @subject', ['@subject' => $post['subject']])); - $this->assertFalse(strpos($mail['body'], $post['body']) === FALSE, 'Body contains the value submitted through the form.'); - - // Test form submission with email rerouting and invalid email addresses. - $post = [ - 'to' => 'To address invalid format', - 'cc' => 'Cc address invalid format', - 'bcc' => 'Bcc address invalid format', - ]; - $this->drupalPostForm('admin/config/development/reroute_email/test', $post, t('Send email')); - - // Successful submission with email rerouting enabled. - $this->assertText(t('Test email submitted for delivery from test form.')); - - // Check rerouted email to. - $this->assertMail('to', $this->rerouteDestination, new FormattableMarkup('To email address was rerouted to @address.', ['@address' => $this->rerouteDestination])); - $this->assertEmailOriginallyTo($post['to']); - - // Check the Cc and Bcc headers are the ones submitted through the form. - $mails = $this->getMails(); - $mail = end($mails); - $this->assertTrue($mail['headers']['X-Rerouted-Original-Cc'] == $post['cc'], new FormattableMarkup('X-Rerouted-Original-Cc is correctly set to submitted value: @address', ['@address' => $post['cc']])); - $this->assertTrue($mail['headers']['X-Rerouted-Original-Bcc'] == $post['bcc'], new FormattableMarkup('X-Rerouted-Original-Cc is correctly set to submitted value: @address', ['@address' => $post['bcc']])); - - // Now change the configuration to disable reroute and submit the Test form - // with the same invalid email address values. - $this->configureRerouteEmail(FALSE); - - // Submit the test email form again with previously used invalid addresses. - $this->drupalPostForm('admin/config/development/reroute_email/test', $post, t('Send email')); - - // Check invalid email addresses are still passed to the mail system. - $mails = $this->getMails(); - $mail = end($mails); - - // Check rerouted email to. - $this->assertMail('to', $post['to'], new FormattableMarkup('To email address is correctly set to submitted value: @address.', ['@address' => $post['to']])); - $this->verbose(new FormattableMarkup('Sent email values: <pre>@mail</pre>', ['@mail' => var_export($mail, TRUE)])); - - // Check the Cc and Bcc headers are the ones submitted through the form. - $this->assertTrue($mail['headers']['Cc'] == $post['cc'], new FormattableMarkup('Cc is correctly set to submitted value: @address', ['@address' => $post['cc']])); - $this->assertTrue($mail['headers']['Bcc'] == $post['bcc'], new FormattableMarkup('Bcc is correctly set to submitted value: @address', ['@address' => $post['bcc']])); - } - -} diff --git a/web/modules/reroute_email/tests/src/Functional/UnusualMessageFieldsTest.php b/web/modules/reroute_email/tests/src/Functional/UnusualMessageFieldsTest.php deleted file mode 100644 index 819816fb70..0000000000 --- a/web/modules/reroute_email/tests/src/Functional/UnusualMessageFieldsTest.php +++ /dev/null @@ -1,94 +0,0 @@ -<?php - -namespace Drupal\Tests\reroute_email\Functional; - -use Drupal\Component\Render\FormattableMarkup; - -/** - * Test handling of unusual fields. - * - * - message body passed as a string - * - Cc/Bcc header keys with an unexpected case. - * - * @ingroup reroute_email_tests - * - * @group reroute_email - */ -class UnusualMessageFieldsTest extends RerouteEmailTestBase { - - public static $modules = ['reroute_email', 'reroute_email_test', 'dblog']; - - /** - * Enable modules and create user with specific permissions. - */ - public function setUp() { - // Add more permissions to access recent log messages in test. - $this->permissions[] = 'access site reports'; - // Include hidden test helper sub-module. - parent::setUp(); - } - - /** - * Test handling of message body as a string and header keys' robustness. - * - * A test email is sent by the reroute_email_test module with a string for - * the body of the email message and Cc/Bcc header keys with an unexpected - * case. Test if Reroute Email handles message's body properly when it is a - * string and captures all Cc/Bcc header keys independently of the case. - */ - public function testBodyStringRobustHeaders() { - // Initialize Cc and Bcc keys with a special case. - $test_cc_key = 'cC'; - $test_bcc_key = 'bCc'; - - // Configure to reroute to {$this->rerouteDestination}. - $this->configureRerouteEmail(TRUE, $this->rerouteDestination); - - // Print test email values for comparing values on test results page. - $test_message = [ - 'to' => $this->originalDestination, - 'params' => [ - 'body' => 'Test Message body is a string.', - 'headers' => [ - 'test_cc_key' => $test_cc_key, - 'test_bcc_key' => $test_bcc_key, - $test_cc_key => 'test_cc_key@example.com', - $test_bcc_key => 'test_bcc_key@example.com', - ], - ], - ]; - // Send test helper sub-module's email. - $langcode = \Drupal::languageManager()->getCurrentLanguage()->getId(); - \Drupal::getContainer() - ->get('plugin.manager.mail') - ->mail('reroute_email_test', 'test_reroute_email', $test_message['to'], $langcode, $test_message['params']); - $this->verbose(new FormattableMarkup('Test email message values: <pre>@test_message</pre>', ['@test_message' => var_export($test_message, TRUE)])); - - $mails = $this->getMails(); - $mail = end($mails); - - // Check rerouted email to. - $this->assertMail('to', $this->rerouteDestination, new FormattableMarkup('To email address was rerouted to @address.', ['@address' => $this->rerouteDestination])); - - // Check if original destination email address is in rerouted email body. - $this->assertEmailOriginallyTo(); - - // Check if test message body is found although provided as a string. - $this->assertTrue(strpos($mail['body'], $test_message['params']['body']) !== FALSE, 'Email body contains original message body although it was provided as a string.'); - - // Check the watchdog entry logged by reroute_email_test_mail_alter. - $this->drupalGet('admin/reports/dblog'); - $this->assertRaw(t('A String was detected in the body'), 'Recorded in recent log messages: a String was detected in the body.'); - - // Test the robustness of the CC and BCC keys in headers. - $this->assertTrue($mail['headers']['X-Rerouted-Original-Cc'] == $test_message['params']['headers'][$test_cc_key], new FormattableMarkup('X-Rerouted-Original-Cc is correctly set to @test_cc_address, although Cc header message key provided was: @test_cc_key', [ - '@test_cc_address' => $test_message['params']['headers'][$test_cc_key], - '@test_cc_key' => $test_cc_key, - ])); - $this->assertTrue($mail['headers']['X-Rerouted-Original-Bcc'] == $test_message['params']['headers'][$test_bcc_key], new FormattableMarkup('X-Rerouted-Original-Bcc is correctly set to @test_bcc_address, although Bcc header message key provided was: @test_bcc_key', [ - '@test_bcc_address' => $test_message['params']['headers'][$test_bcc_key], - '@test_bcc_key' => $test_bcc_key, - ])); - } - -} -- GitLab