summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-10-09 08:06:12 +0000
committerPaul 'flowerysong' Arthur <flowerysong00@yahoo.com>2010-10-09 08:06:12 +0000
commitf82f5454f9832303ef5075b73e5017549c3a19ae (patch)
tree71805afd7285d8d1829ec593ca787140eaea7c4e
parentb18ff601386b5f59c264b554e7ded04890c4283e (diff)
downloadampache-f82f5454f9832303ef5075b73e5017549c3a19ae.tar.gz
ampache-f82f5454f9832303ef5075b73e5017549c3a19ae.tar.bz2
ampache-f82f5454f9832303ef5075b73e5017549c3a19ae.zip
Refactor mail handling a bit and make registration use the same method as the
other places that send mail.
-rw-r--r--admin/mail.php50
-rw-r--r--config/ampache.cfg.php.dist76
-rw-r--r--lib/class/ampachemail.class.php128
-rw-r--r--lib/class/registration.class.php62
-rw-r--r--lostpassword.php16
-rw-r--r--modules/validatemail/validateEmail.php24
-rw-r--r--templates/show_mail_users.inc.php9
7 files changed, 200 insertions, 165 deletions
diff --git a/admin/mail.php b/admin/mail.php
index 18bcb100..b0bc55cc 100644
--- a/admin/mail.php
+++ b/admin/mail.php
@@ -43,43 +43,31 @@ switch ($_REQUEST['action']) {
mb_language("uni");
}
- $clients = AmpacheMail::get_users($_REQUEST['to']);
-
- foreach ($clients as $client) {
- if(function_exists('mb_encode_mimeheader')) {
- $recipient .= mb_encode_mimeheader($client['fullname']) ." <" . $client['email'] . ">, ";
- } else {
- $recipient .= $client['fullname'] ." <" . $client['email'] . ">, ";
- }
- }
-
- // Remove the last , from the recipient
- $recipient = rtrim($recipient,", ");
+ $mailer = new AmpacheMail();
// Set the vars on the object
- AmpacheMail::$recipient = $recipient;
- if(function_exists('mb_encode_mimeheader')) {
- AmpacheMail::$fullname = mb_encode_mimeheader($GLOBALS['user']->fullname);
- } else {
- AmpacheMail::$fullname = $GLOBALS['user']->fullname;
+ $mailer->subject = scrub_in($_REQUEST['subject']);
+ $mailer->message = scrub_in($_REQUEST['message']);
+
+ if ($_REQUEST['from'] == 'system') {
+ $mailer->set_default_sender();
}
- AmpacheMail::$to = $GLOBALS['user']->email;
- AmpacheMail::$subject = scrub_in($_REQUEST['subject']);
- if(function_exists('mb_eregi_replace')) {
- AmpacheMail::$message = mb_eregi_replace("\r\n", "\n", scrub_in($_REQUEST['message']));
- } else {
- AmpacheMail::$message = scrub_in($_REQUEST['message']);
+ else {
+ $mailer->sender = $GLOBALS['user']->email;
+ $mailer->sender_name = $GLOBALS['user']->fullname;
}
- AmpacheMail::$sender = $GLOBALS['user']->email;
-
- AmpacheMail::$fromname = $fullname;
- AmpacheMail::send();
- /* Confirmation Send */
- $url = Config::get('web_path') . '/admin/mail.php';
- $title = _('E-mail Sent');
- $body = _('Your E-mail was successfully sent.');
+ if($mailer->send_to_group($_REQUEST['to'])) {
+ $title = _('E-mail Sent');
+ $body = _('Your E-mail was successfully sent.');
+ }
+ else {
+ $title = _('E-mail Not Sent');
+ $body = _('Your E-mail was not sent.');
+ }
+ $url = Config::get('web_path') . '/admin/mail.php';
show_confirmation($title,$body,$url);
+
break;
default:
require_once Config::get('prefix') . '/templates/show_mail_users.inc.php';
diff --git a/config/ampache.cfg.php.dist b/config/ampache.cfg.php.dist
index 3b85efeb..deed6b27 100644
--- a/config/ampache.cfg.php.dist
+++ b/config/ampache.cfg.php.dist
@@ -462,24 +462,23 @@ refresh_limit = "60"
; DEFAULT: false
;captcha_public_reg = "false"
-; This setting defines the mail domain your in.
-; It tries to deliver a test mail before the user can register and uses
-; the from address info@"domain.tld". No mail is send from this address it's
-; only used to test the existence of a mailbox before accepting user registration.
-; DEFAULT: domain.tld
-;mail_domain = "domain.tld"
-
-; This setting will be used as mail from address.
-; It will also be used to notify if a registration occurred.
-; You need to change this when you activate public_registration.
-;mail_from = "info@domain.tld"
-
-; It defines whether this setup checks a mail address strictly.
+; This setting defines the mail domain you're in.
+; DEFAULT: example.com
+;mail_domain = "example.com"
+
+; This setting will be used as the user part of the mail address for notifications.
+; For example, setting this to 'me' will set the sender to 'me@example.com'.
+; DEFAULT: info
+;mail_user = "info"
+
+; This setting affects how strictly candidate email addresses are checked.
; You can select "strict" or "easy" or "none".
+; "easy" does a regex match, "strict" actually performs some SMTP transactions to see if
+; we can send to this address.
; DEFAULT: strict
;mail_check = "strict"
-; This setting turns on/off admin notify off registration.
+; This setting turns on/off admin notification of registration.
; DEFAULT: false
;admin_notify_reg = "false"
@@ -582,38 +581,59 @@ use_rss = true
;#############################
; Mail Settings #
;#############################
-; This is needed to use phpmailer
-; Mail Send Type.
-; smtp or sendmail or php.
+;Method used to send mail
+;POSSIBLE VALUES: smtp sendmail php
;DEFAULT: php
-;mail_type = "smtp"
+;mail_type = "php"
+
+;Mail domain.
+;DEFAULT: example.com
+;mail_domain = "example.com"
+
+;This will be combined with mail_domain and used as the source address for
+;emails generated by Ampache. For example, setting this to 'me' will set the
+;sender to 'me@example.com'.
+;DEFAULT: info
+;mail_user = "info"
+
+;A name to go with the email address.
+;DEFAULT: Ampache
+;mail_name = "Ampache"
+
+;How strictly email addresses should be checked.
+;easy does a regex match, strict actually performs some SMTP transactions
+;to see if we can send to this address.
+;POSSIBLE VALUES: strict easy none
+; DEFAULT: strict
+;mail_check = "strict"
+
+
+;############################
+; sendmail Settings #
+;############################
-; Sendmail path
-; if you are using sendmail, please set to sendmail path.
;DEFAULT: /usr/sbin/sendmail
;sendmail_path = "/usr/sbin/sendmail"
;#############################
-; Mail SMTP Settings #
+; SMTP Settings #
;#############################
-; If you want to use smtp on phpmailer,
-; please set following configs.
-; Mail server hostname or IP address
+;Mail server (hostname or IP address)
;DEFAULT: localhost
;mail_host = "localhost"
-; Mail server port
+; SMTP port
;DEFAULT: 25
;mail_port = 25
-; SMTPAuth true or false
+;Enable SMTP authentication
;DEFAULT: false
;mail_auth = true
-; SMTP Username
-; your mail auth username.
+;SMTP Username
+;your mail auth username.
;mail_auth_user = ""
; SMTP Password
diff --git a/lib/class/ampachemail.class.php b/lib/class/ampachemail.class.php
index 0fcc10b5..cfb7d02f 100644
--- a/lib/class/ampachemail.class.php
+++ b/lib/class/ampachemail.class.php
@@ -23,28 +23,52 @@
class AmpacheMail {
// The message, recipient and from
- public static $message;
- public static $recipient;
- public static $fromname;
- public static $subject;
- public static $to;
- public static $fullname;
- public static $sender;
+ public $message;
+ public $subject;
+ public $recipient;
+ public $recipient_name;
+ public $sender;
+ public $sender_name;
/**
* Constructor
- * This isn't used
+ * This does nothing. Much like goggles.
*/
- private function __construct($name) {
+ public function __construct($name) {
- // Rien a faire
+ // Eh bien.
} // Constructor
/**
+ * set_default_sender
+ * Does the config magic to figure out the "system" email sender and
+ * sets it as the sender.
+ */
+ public function set_default_sender() {
+ $user = Config::get('mail_user');
+ if (!$user) {
+ $user = 'info';
+ }
+
+ $domain = Config::get('mail_domain');
+ if (!$domain) {
+ $domain = 'example.com';
+ }
+
+ $fromname = Config::get('mail_name');
+ if (!$fromname) {
+ $fromname = 'Ampache';
+ }
+
+ $this->sender = $user . '@' . $domain;
+ $this->sender_name = $fromname;
+ } // set_default_sender
+
+ /**
* get_users
- * This returns an array of userid's for people who have e-mail addresses
- * based on the passed filter
+ * This returns an array of userids for people who have e-mail
+ * addresses based on the passed filter
*/
public static function get_users($filter) {
@@ -79,9 +103,10 @@ class AmpacheMail {
/**
* add_statistics
- * This should be run if we want to add some statistics to this e-mail, appends to self::$message
+ * This should be run if we want to add some statistics to this e-mail,
+ * appends to self::$message
*/
- public static function add_statistics($methods) {
+ public function add_statistics($methods) {
@@ -91,39 +116,61 @@ class AmpacheMail {
* send
* This actually sends the mail, how amazing
*/
- public static function send() {
+ public function send($phpmailer = null) {
$mailtype = Config::get('mail_type');
- $mail = new PHPMailer();
+
+ if ($phpmailer == null) {
+ $mail = new PHPMailer();
+
+ $recipient_name = $this->recipient_name;
+ if(function_exists('mb_encode_mimeheader')) {
+ $recipient_name = mb_encode_mimeheader($recipient_name);
+ }
+ $mail->AddAddress($this->recipient, $recipient_name);
+ }
+ else {
+ $mail = $phpmailer;
+ }
- $mail->AddAddress(self::$to, self::$fullname);
$mail->CharSet = Config::get('site_charset');
- $mail->Encoding = "base64";
- $mail->From = self::$sender;
- $mail->Sender = self::$sender;
- $mail->FromName = self::$fromname;
- $mail->Subject = self::$subject;
- $mail->Body = self::$message;
- $mailhost = Config::get('mail_host');
- $mailport = Config::get('mail_port');
- $mailauth = Config::get('mail_auth');
+ $mail->Encoding = 'base64';
+ $mail->From = $this->sender;
+ $mail->Sender = $this->sender;
+ $mail->FromName = $this->sender_name;
+ $mail->Subject = $this->subject;
+
+ if(function_exists('mb_eregi_replace')) {
+ $this->message = mb_eregi_replace("\r\n", "\n", $this->message);
+ }
+ $mail->Body = $this->message;
+
+ $sendmail = Config::get('sendmail_path');
+ $sendmail = $sendmail ? $sendmail : '/usr/sbin/sendmail';
+ $mailhost = Config::get('mail_host');
+ $mailhost = $mailhost ? $mailhost : 'localhost';
+ $mailport = Config::get('mail_port');
+ $mailport = $mailport ? $mailport : 25;
+ $mailauth = Config::get('mail_auth');
+ $mailuser = Config::get('mail_auth_user');
+ $mailuser = $mailuser ? $mailuser : '';
+ $mailpass = Config::get('mail_auth_pass');
+ $mailpass = $mailpass ? $mailpass : '';
+
switch($mailtype) {
case 'smtp':
$mail->IsSMTP();
- isset($mailhost) ? $mail->Host = $mailhost : $mail->Host = "localhost";
- isset($mailport) ? $mail->Port = $mailport : $mail->Port = 25;
+ $mail->Host = $mailhost;
+ $mail->Port = $mailport;
if($mailauth == true) {
$mail->SMTPAuth(true);
- $mailuser = Config::get('mail_auth_user');
- $mailpass = Config::get('mail_auth_pass');
- isset($mailuser) ? $mail->Username = $mailuser : $mail->Username = "";
- isset($mailpass) ? $mail->Password = $mailpass : $mail->Password = "";
+ $mail->Username = $mailuser;
+ $mail->Password = $mailpass;
}
break;
case 'sendmail':
$mail->IsSendmail();
- $sendmail = Config::get('sendmail_path');
- isset($sendmail) ? $mail->Sendmail = $sendmail : $mail->Sendmail = "/usr/sbin/sendmail";
+ $mail->Sendmail = $sendmail;
break;
case 'php':
default:
@@ -139,5 +186,18 @@ class AmpacheMail {
}
} // send
+ public function send_to_group($group_name) {
+ $mail = new PHPMailer();
+
+ foreach(self::get_users($group_name) as $member) {
+ if(function_exists('mb_encode_mimeheader')) {
+ $member['fullname'] = mb_encode_mimeheader($member['fullname']);
+ }
+ $mail->AddBCC($member['email'], $member['fullname']);
+ }
+
+ return $this->send($mail);
+ }
+
} // AmpacheMail class
?>
diff --git a/lib/class/registration.class.php b/lib/class/registration.class.php
index ae85670d..832718a9 100644
--- a/lib/class/registration.class.php
+++ b/lib/class/registration.class.php
@@ -40,34 +40,15 @@ class Registration {
* send_confirmation
* This sends the confirmation e-mail for the specified user
*/
- public static function send_confirmation($username,$fullname,$email,$password,$validation) {
+ public static function send_confirmation($username, $fullname, $email, $password, $validation) {
+ $mailer = new AmpacheMail();
- // Multi-byte Character Mail
- if(function_exists('mb_language')) {
- ini_set("mbstring.internal_encoding","UTF-8");
- mb_language("uni");
- }
+ // We are the system
+ $mailer->set_default_sender();
- if(function_exists('mb_encode_mimeheader')) {
- $from = mb_encode_mimeheader(_("From: Ampache "));
- } else {
- $from = _("From: Ampache ");
- }
- /* HINT: Site Title */
- $subject = sprintf(_("New User Registration at %s"), Config::get('site_title'));
-
- $additional_header = array();
- $additional_header[] = 'X-Ampache-Mailer: 0.0.1';
- $additional_header[] = $from . "<" .Config::get('mail_from') . ">";
- if(function_exists('mb_send_mail')) {
- $additional_header[] = 'Content-Type: text/plain; charset=UTF-8';
- $additional_header[] = 'Content-Transfer-Encoding: 8bit';
- } else {
- $additional_header[] = 'Content-Type: text/plain; charset=us-ascii';
- $additional_header[] = 'Content-Transfer-Encoding: 7bit';
- }
+ $mailer->subject = sprintf(_("New User Registration at %s"), Config::get('site_title'));
- $body = sprintf(_("Thank you for registering\n\n
+ $mailer->message = sprintf(_("Thank you for registering\n\n
Please keep this e-mail for your records. Your account information is as follows:
----------------------
Username: %s
@@ -81,23 +62,14 @@ Your account is currently inactive. You cannot use it until you've visited the f
Thank you for registering
"), $username, $password, Config::get('web_path') . "/register.php?action=validate&username=$username&auth=$validation");
- if(function_exists('mb_eregi_replace')) {
- $body = mb_eregi_replace("\r\n", "\n", $body);
- }
- // Send the mail!
- if(function_exists('mb_send_mail')) {
- mb_send_mail ($email,
- $subject,
- $body,
- implode("\n", $additional_header),
- '-f'.Config::get('mail_from'));
- } else {
- mail($email,$subject,$body,implode("\r\n", $additional_header),'-f'.Config::get('mail_from'));
- }
+ $mailer->recipient = $email;
+ $mailer->recipient_name = $fullname;
+
+ $mailer->send();
// Check to see if the admin should be notified
if (Config::get('admin_notify_reg')) {
- $body = sprintf(_("A new user has registered
+ $mailer->message = sprintf(_("A new user has registered
The following values were entered.
Username: %s
@@ -106,17 +78,9 @@ E-mail: %s
"), $username, $fullname, $email);
- if(function_exists('mb_send_mail')) {
- mb_send_mail (Config::get('mail_from'),
- $subject,
- $body,
- implode("\n", $additional_header),
- '-f'.Config::get('mail_from'));
- } else {
- mail(Config::get('mail_from'),$subject,$body,implode("\r\n", $additional_header),'-f'.Config::get('mail_from'));
- }
+ $mailer->send_to_group('admins');
}
-
+
return true;
} // send_confirmation
diff --git a/lostpassword.php b/lostpassword.php
index 5804bcf8..0daa9df6 100644
--- a/lostpassword.php
+++ b/lostpassword.php
@@ -54,18 +54,18 @@ function send_newpassword($email,$current_ip){
$newpassword = generate_password(6);
$client->update_password($newpassword);
- AmpacheMail::$subject = _("Lost Password");
- AmpacheMail::$fullname = $client->fullname;
- AmpacheMail::$to = $client->email;
- AmpacheMail::$fromname = "Ampache";
- AmpacheMail::$sender = $GLOBALS['user']->email;
+ $mailer = new AmpacheMail();
+ $mailer->set_default_sender();
+ $mailer->subject = _("Lost Password");
+ $mailer->recipient_name = $client->fullname;
+ $mailer->recipient = $client->email;
- $message = sprintf(_("A user from %s has requested a new password."), $current_ip);
+ $message = sprintf(_("A user from %s has requested a password reset for '%s'."), $current_ip, $client->username);
$message .= "\n";
$message .= sprintf(_("The password has been set to: %s"), $newpassword);
- AmpacheMail::$message = $message;
+ $mailer->message = $message;
- return AmpacheMail::send();
+ return $mailer->send();
}
return false;
}
diff --git a/modules/validatemail/validateEmail.php b/modules/validatemail/validateEmail.php
index 78bbf5f6..14121078 100644
--- a/modules/validatemail/validateEmail.php
+++ b/modules/validatemail/validateEmail.php
@@ -149,25 +149,19 @@ function validateEmail ( $email, $verbose=0 ) {
// Leave blank to use $SERVER_NAME.
// Note that most modern MTAs will ignore (but require) whatever you say here ...
// the server will determine your domain via other means.
- if (Config::get('mail_check')) {
- $mail_check = Config::get('mail_check');
- } else {
- $mail_check = "strict";
- }
+ $mail_check = Config::get('mail_check');
+ $mail_check = $mail_check ? $mail_check : 'strict';
+ if ($mail_check == 'strict' && strncmp(PHP_OS, 'WIN', 3) === true) {
+ $mail_check = "easy";
+ }
- if ($mail_check == 'strict' && strncmp(PHP_OS,'WIN',3) === TRUE) {
- $mail_check = "easy";
- }
+ $serverName = Config::get('mail_domain');
+ $serverName = $serverNam ? $serverName : 'example.com';
- if (Config::get('mail_domain')) {
- $serverName = Config::get('mail_domain');
- }
- else {
- $serverName = "domain.tld";
- }
// MAIL FROM -- who's asking?
// Good values: nobody, postmaster, info, buckwheat, gumby
- $from = "info";
+ $from = Config::get('mail_user');
+ $from = $from ? $from : 'info';
// fsockopen() timeout - in seconds
$socketTimeout = 15;
diff --git a/templates/show_mail_users.inc.php b/templates/show_mail_users.inc.php
index 5a328b5d..46aefe31 100644
--- a/templates/show_mail_users.inc.php
+++ b/templates/show_mail_users.inc.php
@@ -95,6 +95,15 @@
</tr>
-->
<tr>
+ <td><?php echo _('From'); ?>:</td>
+ <td>
+ <select name="from">
+ <option value="self" title="Self"><?php echo _('Yourself'); ?></option>
+ <option value="system" title="System"><?php echo _('Ampache'); ?></option>
+ </select>
+ </td>
+ </tr>
+ <tr>
<td><?php echo _('Subject'); ?>:</td>
<td colspan="3">
<input name="subject" value="<?php echo scrub_out($_POST['subject']); ?>" size="50"></input>