From dbe7d5695dbbb052f8c7cc23269b2ca6b0b768db Mon Sep 17 00:00:00 2001 From: Paul Arthur Date: Tue, 29 Jan 2013 14:10:26 -0500 Subject: Rename Ampache_Mail to Mailer --- admin/mail.php | 2 +- lib/class/ampache_mail.class.php | 214 --------------------------------------- lib/class/mailer.class.php | 214 +++++++++++++++++++++++++++++++++++++++ lib/class/registration.class.php | 2 +- lostpassword.php | 2 +- 5 files changed, 217 insertions(+), 217 deletions(-) delete mode 100644 lib/class/ampache_mail.class.php create mode 100644 lib/class/mailer.class.php diff --git a/admin/mail.php b/admin/mail.php index b5f9c802..20d4986b 100644 --- a/admin/mail.php +++ b/admin/mail.php @@ -43,7 +43,7 @@ switch ($_REQUEST['action']) { mb_language("uni"); } - $mailer = new Ampache_Mail(); + $mailer = new Mailer(); // Set the vars on the object $mailer->subject = $_REQUEST['subject']; diff --git a/lib/class/ampache_mail.class.php b/lib/class/ampache_mail.class.php deleted file mode 100644 index 278a374f..00000000 --- a/lib/class/ampache_mail.class.php +++ /dev/null @@ -1,214 +0,0 @@ -sender = $user . '@' . $domain; - $this->sender_name = $fromname; - } // set_default_sender - - /** - * get_users - * This returns an array of userids for people who have e-mail - * addresses based on the passed filter - */ - public static function get_users($filter) { - - switch ($filter) { - default: - case 'all': - $sql = "SELECT * FROM `user` WHERE `email` IS NOT NULL"; - break; - case 'users': - $sql = "SELECT * FROM `user` WHERE `access`='25' AND `email` IS NOT NULL"; - break; - case 'admins': - $sql = "SELECT * FROM `user` WHERE `access`='100' AND `email` IS NOT NULL"; - break ; - case 'inactive': - $inactive = time() - (30 * 86400); - $sql = 'SELECT * FROM `user` WHERE `last_seen` <= ? AND `email` IS NOT NULL'; - break; - } // end filter switch - - $db_results = Dba::read($sql, isset($inactive) ? array($inactive) : null); - - $results = array(); - - while ($row = Dba::fetch_assoc($db_results)) { - $results[] = array('id'=>$row['id'],'fullname'=>$row['fullname'],'email'=>$row['email']); - } - - return $results; - - } // get_users - - /** - * add_statistics - * This should be run if we want to add some statistics to this e-mail, - * appends to self::$message - */ - public function add_statistics($methods) { - - - - } // add_statistics - - /** - * send - * This actually sends the mail, how amazing - */ - public function send($phpmailer = null) { - - $mailtype = Config::get('mail_type'); - - 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->CharSet = Config::get('site_charset'); - $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(); - $mail->Host = $mailhost; - $mail->Port = $mailport; - if($mailauth == true) { - $mail->SMTPAuth = true; - $mail->Username = $mailuser; - $mail->Password = $mailpass; - } - if ($mailsecure = Config::get('mail_secure_smtp')) { - $mail->SMTPSecure = ($mailsecure == 'ssl') ? 'ssl' : 'tls'; - } - break; - case 'sendmail': - $mail->IsSendmail(); - $mail->Sendmail = $sendmail; - break; - case 'php': - default: - $mail->IsMail(); - break; - } - - $retval = $mail->send(); - if( $retval == true ) { - return true; - } else { - return false; - } - } // 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); - } - -} // Ampache_Mail class -?> diff --git a/lib/class/mailer.class.php b/lib/class/mailer.class.php new file mode 100644 index 00000000..1e5bffa5 --- /dev/null +++ b/lib/class/mailer.class.php @@ -0,0 +1,214 @@ +sender = $user . '@' . $domain; + $this->sender_name = $fromname; + } // set_default_sender + + /** + * get_users + * This returns an array of userids for people who have e-mail + * addresses based on the passed filter + */ + public static function get_users($filter) { + + switch ($filter) { + default: + case 'all': + $sql = "SELECT * FROM `user` WHERE `email` IS NOT NULL"; + break; + case 'users': + $sql = "SELECT * FROM `user` WHERE `access`='25' AND `email` IS NOT NULL"; + break; + case 'admins': + $sql = "SELECT * FROM `user` WHERE `access`='100' AND `email` IS NOT NULL"; + break ; + case 'inactive': + $inactive = time() - (30 * 86400); + $sql = 'SELECT * FROM `user` WHERE `last_seen` <= ? AND `email` IS NOT NULL'; + break; + } // end filter switch + + $db_results = Dba::read($sql, isset($inactive) ? array($inactive) : null); + + $results = array(); + + while ($row = Dba::fetch_assoc($db_results)) { + $results[] = array('id'=>$row['id'],'fullname'=>$row['fullname'],'email'=>$row['email']); + } + + return $results; + + } // get_users + + /** + * add_statistics + * This should be run if we want to add some statistics to this e-mail, + * appends to self::$message + */ + public function add_statistics($methods) { + + + + } // add_statistics + + /** + * send + * This actually sends the mail, how amazing + */ + public function send($phpmailer = null) { + + $mailtype = Config::get('mail_type'); + + 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->CharSet = Config::get('site_charset'); + $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(); + $mail->Host = $mailhost; + $mail->Port = $mailport; + if($mailauth == true) { + $mail->SMTPAuth = true; + $mail->Username = $mailuser; + $mail->Password = $mailpass; + } + if ($mailsecure = Config::get('mail_secure_smtp')) { + $mail->SMTPSecure = ($mailsecure == 'ssl') ? 'ssl' : 'tls'; + } + break; + case 'sendmail': + $mail->IsSendmail(); + $mail->Sendmail = $sendmail; + break; + case 'php': + default: + $mail->IsMail(); + break; + } + + $retval = $mail->send(); + if( $retval == true ) { + return true; + } else { + return false; + } + } // 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); + } + +} // Mailer class +?> diff --git a/lib/class/registration.class.php b/lib/class/registration.class.php index 5df8e563..72a4af5d 100644 --- a/lib/class/registration.class.php +++ b/lib/class/registration.class.php @@ -43,7 +43,7 @@ class Registration { * This sends the confirmation e-mail for the specified user */ public static function send_confirmation($username, $fullname, $email, $password, $validation) { - $mailer = new Ampache_Mail(); + $mailer = new Mailer(); // We are the system $mailer->set_default_sender(); diff --git a/lostpassword.php b/lostpassword.php index b7e1d520..1b5fae00 100644 --- a/lostpassword.php +++ b/lostpassword.php @@ -54,7 +54,7 @@ function send_newpassword($email,$current_ip){ $newpassword = generate_password(6); $client->update_password($newpassword); - $mailer = new Ampache_Mail(); + $mailer = new Mailer(); $mailer->set_default_sender(); $mailer->subject = T_("Lost Password"); $mailer->recipient_name = $client->fullname; -- cgit