Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Added a new config option, 'expose user emails', which defaults to tr…

…ue (to mimic old behaviour). If set to false, then all e-mail will come from the site address defined in the Mail From field (or automatically calculated if not set). I also split the code that generates the site e-mail address into a getSiteEmailAddress() function, so that we encapsulate the logic to generate it better - it can now be called from elsewhere, if needed.

This will involve a change to the DB data (to add the new option to the config_options table, and to modify the ordering of a subsequent item).  I have added the necessary changes to initial_data.sql, but I don't know how to manage updates to existing systems.  Here is the code that will need to be run, but I have no idea where to put it, I'm afraid!

    INSERT INTO `<?php echo $table_prefix ?>config_options`
     (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`)
    VALUES
     ('mailing', 'mail_expose_user_emails', '1', 'BoolConfigHandler', 0, 12,
      'Enable to expose user e-mails in the from/reply-to field, or disable to always use the site address, below.');

    UPDATE `<?php echo $table_prefix ?>config_options`
    SET `option_order` = 13
    WHERE `category_name` = 'mailing' AND `name` = 'mail_from';
  • Loading branch information...
commit 427aab77db6e8e1e2998701ac000ec496bb14103 1 parent fbd062f
@MarkMaldaba MarkMaldaba authored
View
53 application/models/notifier/Notifier.class.php
@@ -584,23 +584,28 @@ static function sendEmail($to, $from, $subject, $body = false, $type = 'text/pla
throw new NotifierConnectionError();
} // if
+ /**
+ * If the 'expose user e-mail' flag is cleared, then replace the user's
+ * email with the site e-mail.
+ */
+ if (config_option('mail_expose_user_emails', 0)==0) {
+ $from = self::getSiteEmailAddress();
+ }
/**
* Set name address in ReplyTo, some MTA think we're usurpators
* (which is quite true actually...)
+ * We only do this if we aren't already set to use the site e-mail for
+ * all communications.
*/
- if (config_option('mail_use_reply_to', 0)==1) {
+ elseif (config_option('mail_use_reply_to', 0)==1) {
$i = strpos($from, ' <');
- $name = '?';
+ $name = '';
if ($i!==false) {
$name = substr($from, 0, $i);
}
$mailer->setReplyTo($from);
- $mail_from = trim(config_option('mail_from'));
- if ($mail_from=='') {
- $mail_from = 'projectpier@'.$_SERVER['SERVER_NAME'];
- }
- $from = "$name <$mail_from>";
+ $from = self::getSiteEmailAddress($name);
}
// from must be address known on server when authentication is selected
@@ -616,6 +621,40 @@ static function sendEmail($to, $from, $subject, $body = false, $type = 'text/pla
} // sendEmail
/**
+ * This function will return the e-mail address that should be used as the 'from'
+ * address, if we are using the site address, rather than a user's own address.
+ * $display_name is the name that will be displayed. If blank or omitted then
+ * the project name will be used.
+ *
+ * @param void
+ * @return string
+ */
+ static function getSiteEmailAddress($display_name = '') {
+ static $site_email;
+ static $default_name;
+
+ if (!isset($site_email)) {
+ $site_email = trim(config_option('mail_from'));
+ if ($site_email=='') {
+ $site_email = 'projectpier@'.$_SERVER['SERVER_NAME'];
+ }
+ }
+
+ $display_name = trim($display_name);
+ if ($display_name == '') {
+ if (!isset($default_name)) {
+ $default_name = config_option('site_name', '');
+ if ($default_name == '') {
+ $default_name = "ProjectPier";
+ }
+ }
+ $display_name = $default_name;
+ }
+
+ return self::prepareEmailAddress($site_email, $display_name);
+ }
+
+ /**
* This function will return SMTP connection. It will try to load options from
* config and if it fails it will use settings from php.ini
*
View
2  language/en_us/administration.php
@@ -97,6 +97,8 @@
'config option desc mail_transport' => 'You can use the default PHP settings for sending emails or specify an SMTP server',
'config option name mail_from' => 'Mail From: address',
'config option name mail_use_reply_to' => 'Use Reply-To: for From',
+ 'config option name mail_expose_user_emails' => 'Expose user e-mails',
+ 'config option desc mail_expose_user_emails' => 'Enable to expose user e-mails in the from/reply-to field, or disable to always use the Mail From address.',
'config option name smtp_server' => 'SMTP server',
'config option name smtp_port' => 'SMTP port',
'config option name smtp_authenticate' => 'Use SMTP authentication',
View
3  public/install/installation/templates/db/mysql/initial_data.php
@@ -30,7 +30,8 @@
INSERT INTO `<?php echo $table_prefix ?>config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES ('mailing', 'exchange_compatible', '0', 'BoolConfigHandler', 0, 90, NULL);
INSERT INTO `<?php echo $table_prefix ?>config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES ('mailing', 'mail_transport', 'mail()', 'MailTransportConfigHandler', 0, 10, 'Values: ''mail()'' - try to emulate mail() function, ''smtp'' - use SMTP connection');
INSERT INTO `<?php echo $table_prefix ?>config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES ('mailing', 'mail_use_reply_to', '0', 'BoolConfigHandler', 0, 11, 'Enable to use Reply-To header in mails');
-INSERT INTO `<?php echo $table_prefix ?>config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES ('mailing', 'mail_from', '', 'StringConfigHandler', 0, 12, 'The From address in every mail sent out');
+INSERT INTO `<?php echo $table_prefix ?>config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES ('mailing', 'mail_expose_user_emails', '1', 'BoolConfigHandler', 0, 12, 'Enable to expose user e-mails in the from/reply-to field, or disable to always use the site address, below.');
+INSERT INTO `<?php echo $table_prefix ?>config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES ('mailing', 'mail_from', '', 'StringConfigHandler', 0, 13, 'The From address in every mail sent out');
INSERT INTO `<?php echo $table_prefix ?>config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES ('mailing', 'smtp_server', '', 'StringConfigHandler', 0, 20, '');
INSERT INTO `<?php echo $table_prefix ?>config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES ('mailing', 'smtp_port', '25', 'IntegerConfigHandler', 0, 21, NULL);
INSERT INTO `<?php echo $table_prefix ?>config_options` (`category_name`, `name`, `value`, `config_handler_class`, `is_system`, `option_order`, `dev_comment`) VALUES ('mailing', 'smtp_authenticate', '0', 'BoolConfigHandler', 0, 22, 'Use SMTP authentication');
Please sign in to comment.
Something went wrong with that request. Please try again.