FINAL suepr merge step : added all modules to this super repos

This commit is contained in:
Bachir Soussi Chiadmi
2015-04-19 16:46:59 +02:00
7585 changed files with 1723356 additions and 18 deletions

View File

@@ -0,0 +1,339 @@
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.

View File

@@ -0,0 +1,101 @@
Copyright 2007 Khalid Baheyeldin and http://2bits.com
Description
-----------
This module intercepts all outgoing emails from a Drupal site and
reroutes them to a predefined configurable email address.
This is useful in case where you do not want email sent from a Drupal
site to reach the users. For example, if you copy a live site to a test
site for the purpose of development, and you do not want any email sent
to real users of the original site. Or you want to check the emails sent
for uniform formatting, footers, ...etc.
This is also a good demonstration of what hook_mail_alter(), available in
Drupal 5.x and later, can do.
Installation
------------
To install this module, do the following:
1. Extract the tar ball that you downloaded from Drupal.org.
2. Upload the entire directory and all its contents to your
modules directory.
Configuration
-------------
To enable this module do the following:
1. Go to Admin -> Modules, and enable reroute email.
2. Go to Admin -> Configuration -> Development -> Reroute email, and enter an
email address to route all email to.
Tips and Tricks
---------------
Reroute Email provides configuration variables that you can directly override
in the settings.php file of a site. This is useful for moving sites from live
to test and vice versa.
To use this variable, you add the following line in the settings.php file
for the test environment:
$conf['reroute_email_enable'] = 1;
And for the live site, you set it as follows:
$conf['reroute_email_enable'] = 0;
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.
$conf['reroute_email_enable'] = 1;
// Space, comma, or semicolon-delimited list of email addresses to pass
// through. Every destination email address which is not on this list will be
// rerouted to the first address on the list.
$conf['reroute_email_address'] = "example@example.com";
// Enable inserting a message into the email body when the mail is being
// rerouted.
$conf['reroute_email_enable_message'] = 1;
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
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
---------------------
If you want to report bugs, feature requests, or submit a patch, please do so
at the project page on the Drupal web site.
http://drupal.org/project/reroute_email
Author
------
Khalid Baheyeldin (http://baheyeldin.com/khalid and http://2bits.com)
Maintainers
-----------
rfay (http://drupal.org/user/30906)
DYdave (http://drupal.org/user/467284)
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.
The author can also be contacted for paid customizations of this and other
modules.

View File

@@ -0,0 +1,104 @@
<?php
/**
* @file
* Reroute Email admin configuration functions.
*/
/**
* Settings form.
*/
function reroute_email_settings() {
$form[REROUTE_EMAIL_ENABLE] = array(
'#type' => 'checkbox',
'#title' => t('Enable rerouting'),
'#default_value' => variable_get(REROUTE_EMAIL_ENABLE, 0),
'#description' => t('Check this box if you want to enable email rerouting. Uncheck to disable rerouting.'),
);
$form[REROUTE_EMAIL_ADDRESS] = array(
'#type' => 'textfield',
'#title' => t('Email addresses'),
'#default_value' => variable_get(REROUTE_EMAIL_ADDRESS, variable_get('site_mail', ini_get('sendmail_from'))),
'#description' => t('Provide a space, comma, or semicolon-delimited list of email addresses to pass through. Every destination email address which is not on this list will be rerouted to the first address on the list.'),
'#states' => array(
'visible' => array(':input[name=reroute_email_enable]' => array('checked' => TRUE)),
),
);
$form[REROUTE_EMAIL_ENABLE_MESSAGE] = array(
'#type' => 'checkbox',
'#title' => t('Show rerouting description in mail body'),
'#default_value' => variable_get(REROUTE_EMAIL_ENABLE_MESSAGE, 1),
'#description' => 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' => array(
'visible' => array(':input[name=reroute_email_enable]' => array('checked' => TRUE)),
),
);
return system_settings_form($form);
}
/**
* Validation callback for reroute_email_settings() form.
*/
function reroute_email_settings_validate($form, $form_state) {
if ($form_state['values']['reroute_email_enable'] == TRUE) {
// Allow splitting emails by space, comma, semicolon.
$addresslist = preg_split(REROUTE_EMAIL_EMAIL_SPLIT_RE, $form_state['values']['reroute_email_address'], -1, PREG_SPLIT_NO_EMPTY);
foreach ($addresslist as $address) {
if (!valid_email_address($address)) {
form_set_error('reroute_email_address', t('@address is not a valid email address', array('@address' => $address)));
}
}
}
}
/**
* Form for sending test messages.
*/
function reroute_email_test_email_form() {
return array(
'addresses' => array(
'#type' => 'fieldset',
'#description' => t('Email addresses are not validated: any valid or invalid email address format could be submitted.'),
'to' => array(
'#type' => 'textfield',
'#title' => t('To'),
'#required' => TRUE,
),
'cc' => array(
'#type' => 'textfield',
'#title' => t('Cc'),
),
'bcc' => array(
'#type' => 'textfield',
'#title' => t('Bcc'),
),
),
'subject' => array(
'#type' => 'textfield',
'#title' => t('Subject'),
'#default_value' => t('Reroute Email Test'),
),
'body' => array(
'#type' => 'textarea',
'#title' => t('Body'),
),
'submit' => array(
'#type' => 'submit',
'#value' => t('Send email'),
),
);
}
/**
* Submit handler for email test.
*/
function reroute_email_test_email_form_submit(&$form, &$form_state) {
$to = $form_state['values']['to'];
$param_keys = array('cc', 'bcc', 'subject', 'body');
$params = array_intersect_key($form_state['values'], array_flip($param_keys));
$message = drupal_mail('reroute_email', 'test_email_form', $to, language_default(), $params);
if (!empty($message['result'])) {
drupal_set_message(t("Test email submitted for delivery."));
}
}

View File

@@ -0,0 +1,13 @@
name = Reroute emails
description = Reroutes emails send from the site to a predefined email. Useful for test sites.
package = Development
core = "7.x"
files[] = reroute_email.test
configure = admin/config/development/reroute_email
; Information added by drupal.org packaging script on 2013-10-24
version = "7.x-1.1+28-dev"
core = "7.x"
project = "reroute_email"
datestamp = "1382643190"

View File

@@ -0,0 +1,39 @@
<?php
/**
* @file
* Reroute Email module installation functions.
*/
/**
* Implements hook_uninstall().
*/
function reroute_email_uninstall() {
variable_del('reroute_email_address');
variable_del('reroute_email_enable');
variable_del('reroute_email_enable_message');
}
/**
* Implements hook_install().
*/
function reroute_email_install() {
db_update('system')
->fields(array('weight' => 99))
->condition('type', 'module', '=')
->condition('name', 'reroute_email')
->execute();
}
/**
* Update module's weight.
*/
function reroute_email_update_7100() {
db_update('system')
->fields(array('weight' => 99))
->condition('type', 'module', '=')
->condition('name', 'reroute_email')
->execute();
return t('The weight of the Reroute Email module was updated to 99.');
}

View File

@@ -0,0 +1,158 @@
<?php
/**
* @file
* Reroute Email module
*/
define('REROUTE_EMAIL_ADDRESS', 'reroute_email_address');
define('REROUTE_EMAIL_ENABLE_MESSAGE', 'reroute_email_enable_message');
define('REROUTE_EMAIL_ENABLE', 'reroute_email_enable');
// Regular expression used to split email addresses provided in form.
// This allows the use of any number of spaces, commas, or semicolons
// between email addresses.
define('REROUTE_EMAIL_EMAIL_SPLIT_RE', '/[\s,;]+/');
/**
* Implements of hook_permission().
*/
function reroute_email_permission() {
return array(
'administer reroute email' => array(
'title' => t('Administer Reroute Email'),
'description' => t('Administer the Reroute Email module.'),
),
);
}
/**
* Implements hook_menu().
*/
function reroute_email_menu() {
$items = array();
$items['admin/config/development/reroute_email'] = array(
'title' => 'Reroute Email',
'description' => 'Reroute emails to a test address.',
'page callback' => 'drupal_get_form',
'page arguments' => array('reroute_email_settings'),
'access arguments' => array('administer reroute email'),
'file' => 'reroute_email.admin.inc',
);
$items['admin/config/development/reroute_email/settings'] = array(
'title' => 'Settings',
'type' => MENU_DEFAULT_LOCAL_TASK,
'weight' => -10,
);
$items['admin/config/development/reroute_email/test'] = array(
'title' => 'Test email form',
'type' => MENU_LOCAL_TASK,
'description' => 'Form for sending test email.',
'page callback' => 'drupal_get_form',
'page arguments' => array('reroute_email_test_email_form'),
'access arguments' => array('administer reroute email'),
'file' => 'reroute_email.admin.inc',
);
return $items;
}
/**
* Implements hook_mail_alter().
*
* This hook is required to change the destination of outgoing emails.
*/
function reroute_email_mail_alter(&$message) {
if (variable_get(REROUTE_EMAIL_ENABLE, 0)) {
global $base_url;
if (!variable_get(REROUTE_EMAIL_ADDRESS, '')) {
// If email address not in settings, then do nothing.
return;
}
if (empty($message)) {
return;
}
if (!is_array($message)) {
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 = array();
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]);
}
}
}
// Split the address string on whitespace, ignoring any empty results.
$addresslist = preg_split(REROUTE_EMAIL_EMAIL_SPLIT_RE, variable_get(REROUTE_EMAIL_ADDRESS, variable_get('site_mail', ini_get('sendmail_from'))), -1, PREG_SPLIT_NO_EMPTY);
if (!in_array($to, $addresslist)) {
// Not on the list, so reroute to the first address in the list.
$message['headers']['X-Rerouted-Original-To'] = $to;
$message['to'] = $addresslist[0];
if (variable_get(REROUTE_EMAIL_ENABLE_MESSAGE, 1)) {
// Format a message to show at the top.
$msg = t("This email was rerouted.") . "\n";
$msg .= t("Web site: @site", array('@site' => $base_url)) . "\n";
$msg .= t("Mail key: @key", array('@key' => $mailkey)) . "\n";
$msg .= t("Originally to: @to", array('@to' => $to)) . "\n";
$msg .= "-----------------------\n";
// 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);
}
}
}
}
}
/**
* Implements hook_mail().
*/
function reroute_email_mail($key, &$message, $params) {
if ($key != 'test_email_form') {
return;
}
$message['headers']['Cc'] = $params['cc'];
$message['headers']['Bcc'] = $params['bcc'];
$message['subject'] = $params['subject'];
$message['body'][] = $params['body'];
}

View File

@@ -0,0 +1,434 @@
<?php
/**
* @file
* Test the Reroute Email module.
*/
/**
* Provides common functionality for the Reroute Email test classes.
*/
class RerouteEmailTestCase extends DrupalWebTestCase {
/**
* User object to perform site browsing
* @var object
*/
protected $adminUser;
/**
* Reroute email destination address used for the tests.
* @var string
*/
protected $rerouteDestination = "rerouted@example.com";
/**
* Original email address used for the tests.
* @var string
*/
protected $originalDestination = "original@example.com";
/**
* Permissions required by the user to perform the tests.
* @var array
*/
protected $permissions = array(
'administer reroute email',
);
/**
* Enable modules and create user with specific permissions.
*/
public function setUp() {
// Merge inherited classes modules, see FieldUITestCase for an example.
$modules = func_get_args();
if (isset($modules[0]) && is_array($modules[0])) {
$modules = $modules[0];
}
$modules[] = 'reroute_email';
parent::setUp($modules);
// Authenticate test user.
$this->admin_user = $this->drupalCreateUser($this->permissions);
$this->drupalLogin($this->admin_user);
}
/**
* Helper function to configure Reroute Email Settings.
*
* @param string $reroute_destination
* (optional) The email address to which emails should be rerouted.
* Defaults to $this->rerouteDestination if set to NULL.
* @param bool $reroute_email_enable
* (optional) Set to TRUE to enable email Rerouting, defaults to TRUE.
* @param bool $reroute_email_enable_message
* (optional) Set to TRUE to show rerouting description, defaults to TRUE.
*/
public function configureRerouteEmail($reroute_destination = NULL, $reroute_email_enable = TRUE, $reroute_email_enable_message = TRUE) {
// Initialize $reroute_destination by default if no value is provided.
if (!isset($reroute_destination)) {
$reroute_destination = $this->rerouteDestination;
}
// Configure to Reroute Email settings form.
$post = array(
'reroute_email_address' => $reroute_destination,
'reroute_email_enable' => $reroute_email_enable,
'reroute_email_enable_message' => $reroute_email_enable_message,
);
// Submit Reroute Email Settings form and check if it was successful.
$this->drupalPost("admin/config/development/reroute_email", $post, t('Save configuration'));
$this->assertText(t("The configuration options have been saved."));
}
/**
* Assert whether the text "Originally to: @to_email" is found in email body.
*
* @param string $mail_body
* The email body in which the line of text should be searched for.
* @param bool $message
* Message to display in test case results.
* @param bool $original_destination
* (optional) The original email address to be found in rerouted email
* body. Defaults to $this->originalDestination if set to NULL.
*/
public function assertOriginallyTo($mail_body, $message, $original_destination = NULL) {
// Initialize $original_destination by default if no value is provided.
if (!isset($original_destination)) {
$original_destination = $this->originalDestination;
}
// Search in $mailbody for "Originally to: $original_destination".
$search_for = t("Originally to: @to", array('@to' => $original_destination));
$has_info = preg_match("/$search_for/", $mail_body);
// Asserts whether searched text was found.
$this->assertTrue($has_info, $message);
$this->verbose(t('Email body was: <pre>@mail_body</pre>', array('@mail_body' => $mail_body)));
}
}
/**
* Tests email rerouting for the site-wide Core Contact form.
*/
class RerouteEmailContactTestCase extends RerouteEmailTestCase {
/**
* Implements DrupalWebTestCase::getInfo().
*/
public static function getInfo() {
return array(
'name' => 'Site-wide Core Contact form email rerouting',
'description' => "Test Reroute Email module's ability to reroute mail sent from the Core Contact module forms.",
'group' => 'Reroute Email',
);
}
/**
* 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';
// Include Core Contact module.
parent::setUp('contact');
}
/**
* 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 normally to rerouted@example.com.
$this->configureRerouteEmail();
// Configure the contact settings to send to $original_destination.
$this->drupalPost('admin/structure/contact/edit/1', array('recipients' => $this->originalDestination), t('Save'));
// Go to the contact page and send an email.
$post = array('subject' => "Test test test", 'message' => 'This is a test');
$this->drupalPost("contact", $post, t("Send message"));
$this->assertText(t("Your message has been sent"));
$mails = $this->drupalGetMails();
$mail = end($mails);
$this->assertMail('to', $this->rerouteDestination, format_string("Email was rerouted to @address", array('@address' => $this->rerouteDestination)));
// Check if original destination email address is in rerouted email body.
$this->assertOriginallyTo($mail['body'], 'Found the correct "Originally to" line in the body');
$this->assertTrue(strpos($mail['body'], 'Originally to') !== FALSE, 'Body does contain "Originally to"');
// 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("{$this->rerouteDestination}, $additional_destination");
// Configure the contact settings to point to the additional recipient.
$this->drupalPost('admin/structure/contact/edit/1', array('recipients' => $additional_destination), t('Save'));
// Go to the contact page and send an email.
$post = array('subject' => "Test test test", 'message' => 'This is a test');
$this->drupalPost("contact", $post, t("Send message"));
$this->assertText(t("Your message has been sent"));
$mails = $this->drupalGetMails();
$mail = end($mails);;
$this->assertMail('to', $additional_destination, 'Email was not rerouted because destination was in whitelist');
// Now change the configuration to disable reroute and set the original
// email recipients.
$this->configureRerouteEmail(NULL, FALSE);
// Set the contact form to send to original_destination.
$this->drupalPost('admin/structure/contact/edit/1', array('recipients' => $this->originalDestination), t('Save'));
// Go to the contact page and send an email.
$post = array('subject' => "Test test test", 'message' => 'This is a test');
$this->drupalPost("contact", $post, t("Send message"));
$this->assertText(t("Your message has been sent"));
$mails = $this->drupalGetMails();
$mail = end($mails);
// Mail should not be rerouted - should go to $original_destination.
$this->assertMail('to', $this->originalDestination, 'Mail not rerouted - sent to original destination.');
$this->verbose(t("Email 'to' was: <pre>@mail_to</pre>", array('@mail_to' => $mail['to'])));
// Configure to reroute without body injection.
$this->configureRerouteEmail(NULL, TRUE, FALSE);
// Go to the contact page and send an email.
$post = array('subject' => "Test test test", 'message' => 'This is a test');
$this->drupalPost("contact", $post, t("Send message"));
$this->assertText(t("Your message has been sent"));
$mails = $this->drupalGetMails();
$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->assertTrue($mail['headers']['X-Rerouted-Original-To'] == $this->originalDestination, 'X-Rerouted-Original-To is correctly set to the original destination email');
}
}
/**
* Tests email rerouting for the Test Email form.
*/
class RerouteEmailTestEmailTestCase extends RerouteEmailTestCase {
/**
* Implements DrupalWebTestCase::getInfo().
*/
public static function getInfo() {
return array(
'name' => 'Test Email form',
'description' => "Test Reroute Email's form for sending a test email.",
'group' => 'Reroute Email',
);
}
/**
* 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 normally to rerouted@example.com.
$this->configureRerouteEmail();
// 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 = array(
'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->drupalPost("admin/config/development/reroute_email/test", $post, t("Send email"));
$this->assertText(t("Test email submitted for delivery."));
$mails = $this->drupalGetMails();
$mail = end($mails);
// Check rerouted email to.
$this->assertMail('to', $this->rerouteDestination, format_string('To email address was rerouted to @address.', array('@address' => $this->rerouteDestination)));
// Check the To passed through the Test Email Form.
$this->assertOriginallyTo($mail['body'], 'Found submitted "To" email address in the body', $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'], format_string('X-Rerouted-Original-Cc is correctly set to submitted value: @address', array('@address' => $post['cc'])));
$this->assertTrue($mail['headers']['X-Rerouted-Original-Bcc'] == $post['bcc'], format_string('X-Rerouted-Original-Cc is correctly set to submitted value: @address', array('@address' => $post['bcc'])));
// Check the Subject and Body field values can be found in rerouted email.
$this->assertMail('subject', $post['subject'], format_string('Subject is correctly set to submitted value: @subject', array('@subject' => $post['subject'])));
$this->assertFalse(strpos($mail['body'], $post['body']) === FALSE, 'Body contains the value submitted through the form');
// Check required To field.
$this->drupalPost("admin/config/development/reroute_email/test", array('to' => ''), t("Send email"));
$this->assertText(t("To field is required."));
// Test form submission with email rerouting and invalid email addresses.
$post = array(
'to' => "To address invalid format",
'cc' => "Cc address invalid format",
'bcc' => "Bcc address invalid format",
);
$this->drupalPost("admin/config/development/reroute_email/test", $post, t("Send email"));
// Successful submission with email rerouting enabled.
$this->assertText(t("Test email submitted for delivery."));
$mails = $this->drupalGetMails();
$mail = end($mails);
// Check rerouted email to.
$this->assertMail('to', $this->rerouteDestination, format_string('To email address was rerouted to @address.', array('@address' => $this->rerouteDestination)));
// Check the To passed through the Test Email Form.
$this->assertOriginallyTo($mail['body'], 'Found submitted "To" email address in the body', $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'], format_string('X-Rerouted-Original-Cc is correctly set to submitted value: @address', array('@address' => $post['cc'])));
$this->assertTrue($mail['headers']['X-Rerouted-Original-Bcc'] == $post['bcc'], format_string('X-Rerouted-Original-Cc is correctly set to submitted value: @address', array('@address' => $post['bcc'])));
// Now change the configuration to disable reroute and submit the Test
// Email form with the same invalid email address values.
$this->configureRerouteEmail(NULL, FALSE);
// Submit the test email form again with previously used invalid addresses.
$this->drupalPost("admin/config/development/reroute_email/test", $post, t("Send email"));
// Check invalid email addresses are still passed to the mail system.
$mails = $this->drupalGetMails();
$mail = end($mails);
// Check rerouted email to.
$this->assertMail('to', $post['to'], format_string('To email address is correctly set to submitted value: @address.', array('@address' => $post['to'])));
$this->verbose(t('Sent email values: <pre>@mail</pre>', array('@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'], format_string('Cc is correctly set to submitted value: @address', array('@address' => $post['cc'])));
$this->assertTrue($mail['headers']['Bcc'] == $post['bcc'], format_string('Bcc is correctly set to submitted value: @address', array('@address' => $post['bcc'])));
}
}
/**
* Test handling of special cases for body as a string and Cc/Bcc robustness.
*/
class RerouteEmailSpecialTestCase extends RerouteEmailTestCase {
/**
* Implements DrupalWebTestCase::getInfo().
*/
public static function getInfo() {
return array(
'name' => 'Body as a string and robust headers',
'description' => "Support message's body passed as a string and Cc/Bcc header keys with an unexpected case.",
'group' => 'Reroute Email',
);
}
/**
* 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('reroute_email_test');
}
/**
* 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 normally to rerouted@example.com.
$this->configureRerouteEmail();
// Print test email values for comparing values on test results page.
$test_message = array(
'to' => $this->originalDestination,
'params' => array(
'body' => "Test Message body is a string.",
'headers' => array(
'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.
drupal_mail('reroute_email_test', 'test_reroute_email', $test_message['to'], language_default(), $test_message['params']);
$this->verbose(t('Test email message values: <pre>@test_message</pre>', array('@test_message' => var_export($test_message, TRUE))));
$mails = $this->drupalGetMails();
$mail = end($mails);
// Check rerouted email to.
$this->assertMail('to', $this->rerouteDestination, format_string('To email address was rerouted to @address.', array('@address' => $this->rerouteDestination)));
// Check if original destination email address is in rerouted email body.
$this->assertOriginallyTo($mail['body'], 'Found the correct "Originally to" line in the body');
// 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], format_string('X-Rerouted-Original-Cc is correctly set to @test_cc_address, although Cc header message key provided was: @test_cc_key', array('@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], format_string('X-Rerouted-Original-Bcc is correctly set to @test_bcc_address, although Bcc header message key provided was: @test_bcc_key', array('@test_bcc_address' => $test_message['params']['headers'][$test_bcc_key], '@test_bcc_key' => $test_bcc_key)));
}
}
/**
* Test default reroute destination email address when it is not configured.
*/
class RerouteEmailDefaultAddressTestCase extends RerouteEmailTestCase {
/**
* Implements DrupalWebTestCase::getInfo().
*/
public static function getInfo() {
return array(
'name' => 'Default reroute destination email address',
'description' => "When reroute email addresses field is not configured, attempt to use the site email address, otherwise use sendmail_from system variable.",
'group' => 'Reroute Email',
);
}
/**
* Test default destination address is set to site_mail or sendmail_from.
*
* 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 a fallbacks.
*/
public function testRerouteDefaultAddress() {
// Check default value for reroute_email_address when not configured.
// If Site email is not empty, it should be the default value.
$default_destination = variable_get('site_mail', NULL);
$this->assertTrue(isset($default_destination), format_string('Site mail is not empty: @default_destination', array('@default_destination' => $default_destination)));
// Load the Reroute Email Settings form page.
$this->drupalGet("admin/config/development/reroute_email/reroute_email");
// Check Email addresses field default value.
$this->assertFieldByName(REROUTE_EMAIL_ADDRESS, $default_destination, format_string('Site email address is configured and is the default value of the Email addresses field: @default_destination', array('@default_destination' => $default_destination)));
// Now unset site_mail to check if system sendmail_from is properly used.
variable_del('site_mail');
$default_destination = ini_get('sendmail_from');
// Reload the Reroute Email Settings form page.
$this->drupalGet("admin/config/development/reroute_email/reroute_email");
// Check Email addresses field default value.
$this->assertFieldByName('reroute_email_address', $default_destination, format_string('Site email address is not configured, Email addresses field defaults to system sendmail_from: @default_destination', array('@default_destination' => $default_destination)));
}
}

View File

@@ -0,0 +1,50 @@
<?php
/**
* @file
* Variable module integration.
*/
/**
* Implements hook_variable_info().
*/
function reroute_email_variable_info() {
$variable = array();
$variable[REROUTE_EMAIL_ENABLE] = array(
'title' => t('Enable rerouting'),
'description' => t('Check this box if you want to enable email rerouting. Uncheck to disable rerouting.'),
'type' => 'boolean',
'default' => 0,
'group' => 'reroute_email',
);
$variable[REROUTE_EMAIL_ADDRESS] = array(
'title' => t('Email addresses'),
'description' => t('Provide a space, comma, or semicolon-delimited list of email addresses to pass through. Every destination email address which is not on this list will be rerouted to the first address on the list.'),
'default' => variable_get('site_mail', ini_get('sendmail_from')),
'group' => 'reroute_email',
);
$variable[REROUTE_EMAIL_ENABLE_MESSAGE] = array(
'title' => t('Show rerouting description in mail body'),
'description' => 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.'),
'type' => 'boolean',
'default' => 1,
'group' => 'reroute_email',
);
return $variable;
}
/**
* Implements hook_variable_group_info().
*/
function reroute_email_variable_group_info() {
$groups['reroute_email'] = array(
'title' => t('Reroute Email'),
'description' => t('Reroute email configuration settings'),
'access' => 'administer reroute email',
'path' => array('admin/config/development/reroute_email'),
);
return $groups;
}

View File

@@ -0,0 +1,12 @@
name = "Reroute Email Test"
description = "Helper module for the reroute email tests."
core = 7.x
package = Testing
hidden = TRUE
; Information added by drupal.org packaging script on 2013-10-24
version = "7.x-1.1+28-dev"
core = "7.x"
project = "reroute_email"
datestamp = "1382643190"

View File

@@ -0,0 +1,18 @@
<?php
/**
* @file
* Reroute Email Test module installation functions.
*/
/**
* Implements hook_install().
*/
function reroute_email_test_install() {
// Ensure Reroute Email Test runs after Reroute Email.
db_update('system')
->fields(array('weight' => 100))
->condition('type', 'module', '=')
->condition('name', 'reroute_email_test', '=')
->execute();
}

View File

@@ -0,0 +1,54 @@
<?php
/**
* @file
* Provides Mail hook implementations for testing the Reroute Email module.
*/
/**
* 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.
if (is_string($message['body'])) {
// Record to be checked in test in the log entries.
watchdog('reroute_email_test', 'A String was detected in the body: <pre>!body</pre>', array('!body' => $message['body']), WATCHDOG_NOTICE);
// Convert body to an Array.
$message['body'] = array($message['body']);
}
}