~ubuntu-branches/debian/sid/ampache/sid

« back to all changes in this revision

Viewing changes to lib/class/ampachemail.class.php

  • Committer: Package Import Robot
  • Author(s): Charlie Smotherman
  • Date: 2013-08-27 13:19:48 UTC
  • mfrom: (1.2.9)
  • Revision ID: package-import@ubuntu.com-20130827131948-1czew0zxn6u70dtv
Tags: 3.6-rzb2752+dfsg-1
* New upsteam snapshot.  Contains important bug fixes to the installer.
* Correct typo in ampache-common.postrm.
* Remove courtousy copy of php-getid3, during repack.  Closes: #701526
* Update package to use dh_linktree to make the needed sym links to the
  needed system libs that were removed during repack.
* Update debian/rules to reflect upstreams removing/moving of modules.
* Update debian/ampache-common.install to reflect upstreams removal of files.
* Updated to use new apache2.4 API. Closes: #669756
* Updated /debian/po/de.po thx David Prévot for the patch.  Closes:  #691963
* M3U import is now ordered, fixed upstream.  Closes: #684984
* Text input area has been resized so IPv6 addresses will now fit, fixed
  upstream.  Closes:  #716230
* Added ampache-common.preinst to make sure that the courtousy copies of code
  dirs are empty so dh_linktree can do it's magic on upgrades.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
<?php
2
 
/* vim:set tabstop=8 softtabstop=8 shiftwidth=8 noexpandtab: */
3
 
/**
4
 
 * AmpacheMail Class
5
 
 *
6
 
 *
7
 
 * LICENSE: GNU General Public License, version 2 (GPLv2)
8
 
 * Copyright (c) 2001 - 2011 Ampache.org All Rights Reserved
9
 
 *
10
 
 * This program is free software; you can redistribute it and/or
11
 
 * modify it under the terms of the GNU General Public License v2
12
 
 * as published by the Free Software Foundation.
13
 
 *
14
 
 * This program is distributed in the hope that it will be useful,
15
 
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16
 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17
 
 * GNU General Public License for more details.
18
 
 *
19
 
 * You should have received a copy of the GNU General Public License
20
 
 * along with this program; if not, write to the Free Software
21
 
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22
 
 *
23
 
 * @package     Ampache
24
 
 * @authro      Karl Vollmer <vollmer@ampache.org>
25
 
 * @copyright   2001 - 2011 Ampache.org
26
 
 * @license     http://opensource.org/licenses/gpl-2.0 GPLv2
27
 
 * @link        http://www.ampache.org/
28
 
 */
29
 
 
30
 
/**
31
 
 * AmpacheMail Class
32
 
 *
33
 
 * This class handles the Mail
34
 
 *
35
 
 * @package     Ampache
36
 
 * @copyright   2001 - 2011 Ampache.org
37
 
 * @license     http://opensource.org/licenses/gpl-2.0 GPLv2
38
 
 * @link        http://www.ampache.org/
39
 
 */
40
 
class AmpacheMail {
41
 
 
42
 
        // The message, recipient and from
43
 
        public $message;
44
 
        public $subject;
45
 
        public $recipient;
46
 
        public $recipient_name;
47
 
        public $sender;
48
 
        public $sender_name;
49
 
 
50
 
        /**
51
 
         * Constructor
52
 
         *
53
 
         * This does nothing. Much like goggles.
54
 
         */
55
 
        public function __construct() {
56
 
 
57
 
                // Eh bien.
58
 
 
59
 
        } // Constructor
60
 
 
61
 
        /**
62
 
         * set_default_sender
63
 
         *
64
 
         * Does the config magic to figure out the "system" email sender and
65
 
         * sets it as the sender.
66
 
         */
67
 
        public function set_default_sender() {
68
 
                $user = Config::get('mail_user');
69
 
                if (!$user) {
70
 
                        $user = 'info';
71
 
                }
72
 
 
73
 
                $domain = Config::get('mail_domain');
74
 
                if (!$domain) {
75
 
                        $domain = 'example.com';
76
 
                }
77
 
                
78
 
                $fromname = Config::get('mail_name');
79
 
                if (!$fromname) {
80
 
                        $fromname = 'Ampache';
81
 
                }
82
 
 
83
 
                $this->sender = $user . '@' . $domain;
84
 
                $this->sender_name = $fromname;
85
 
        } // set_default_sender
86
 
 
87
 
        /**
88
 
         * get_users
89
 
         * This returns an array of userids for people who have e-mail
90
 
         * addresses based on the passed filter
91
 
         */
92
 
        public static function get_users($filter) {
93
 
 
94
 
                switch ($filter) {
95
 
                        default:
96
 
                        case 'all':
97
 
                                $sql = "SELECT * FROM `user` WHERE `email` IS NOT NULL";
98
 
                        break;
99
 
                        case 'users':
100
 
                                $sql = "SELECT * FROM `user` WHERE `access`='25' AND `email` IS NOT NULL";
101
 
                        break;
102
 
                        case 'admins':
103
 
                                $sql = "SELECT * FROM `user` WHERE `access`='100' AND `email` IS NOT NULL";
104
 
                        break ;
105
 
                        case 'inactive':
106
 
                                $inactive = time() - (30*86400);
107
 
                                $sql = "SELECT * FROM `user` WHERE `last_seen` <= '$inactive' AND `email` IS NOT NULL";
108
 
                        break;
109
 
                } // end filter switch
110
 
 
111
 
                $db_results = Dba::read($sql);
112
 
 
113
 
                $results = array();
114
 
 
115
 
                while ($row = Dba::fetch_assoc($db_results)) {
116
 
                        $results[] = array('id'=>$row['id'],'fullname'=>$row['fullname'],'email'=>$row['email']);
117
 
                }
118
 
 
119
 
                return $results;
120
 
 
121
 
        } // get_users
122
 
 
123
 
        /**
124
 
         * add_statistics
125
 
         * This should be run if we want to add some statistics to this e-mail,
126
 
         * appends to self::$message
127
 
         */
128
 
        public function add_statistics($methods) {
129
 
 
130
 
 
131
 
 
132
 
        } // add_statistics
133
 
 
134
 
        /**
135
 
         * send
136
 
         * This actually sends the mail, how amazing
137
 
         */
138
 
        public function send($phpmailer = null) {
139
 
 
140
 
                $mailtype = Config::get('mail_type');
141
 
                
142
 
                if ($phpmailer == null) {
143
 
                        $mail = new PHPMailer();
144
 
 
145
 
                        $recipient_name = $this->recipient_name;
146
 
                        if(function_exists('mb_encode_mimeheader')) {
147
 
                                $recipient_name = mb_encode_mimeheader($recipient_name);
148
 
                        }
149
 
                        $mail->AddAddress($this->recipient, $recipient_name);
150
 
                }
151
 
                else {
152
 
                        $mail = $phpmailer;
153
 
                }
154
 
 
155
 
                $mail->CharSet  = Config::get('site_charset');
156
 
                $mail->Encoding = 'base64';
157
 
                $mail->From     = $this->sender;
158
 
                $mail->Sender   = $this->sender;
159
 
                $mail->FromName = $this->sender_name;
160
 
                $mail->Subject  = $this->subject;
161
 
 
162
 
                if(function_exists('mb_eregi_replace')) {
163
 
                        $this->message = mb_eregi_replace("\r\n", "\n", $this->message);
164
 
                }
165
 
                $mail->Body     = $this->message;
166
 
 
167
 
                $sendmail       = Config::get('sendmail_path');
168
 
                $sendmail       = $sendmail ? $sendmail : '/usr/sbin/sendmail';
169
 
                $mailhost       = Config::get('mail_host');
170
 
                $mailhost       = $mailhost ? $mailhost : 'localhost';
171
 
                $mailport       = Config::get('mail_port');
172
 
                $mailport       = $mailport ? $mailport : 25;
173
 
                $mailauth       = Config::get('mail_auth');
174
 
                $mailuser       = Config::get('mail_auth_user');
175
 
                $mailuser       = $mailuser ? $mailuser : '';
176
 
                $mailpass       = Config::get('mail_auth_pass');
177
 
                $mailpass       = $mailpass ? $mailpass : '';
178
 
 
179
 
                switch($mailtype) {
180
 
                        case 'smtp':
181
 
                                $mail->IsSMTP();
182
 
                                $mail->Host = $mailhost;
183
 
                                $mail->Port = $mailport;
184
 
                                if($mailauth == true) {
185
 
                                        $mail->SMTPAuth = true;
186
 
                                        $mail->Username = $mailuser;
187
 
                                        $mail->Password = $mailpass;
188
 
                                }
189
 
                                if ($mailsecure = Config::get('mail_secure_smtp')) {
190
 
                                        $mail->SMTPSecure = ($mailsecure == 'ssl') ? 'ssl' : 'tls';
191
 
                                }
192
 
                        break;
193
 
                        case 'sendmail':
194
 
                                $mail->IsSendmail();
195
 
                                $mail->Sendmail = $sendmail;
196
 
                        break;
197
 
                        case 'php':
198
 
                        default:
199
 
                                $mail->IsMail();
200
 
                        break;
201
 
                }
202
 
 
203
 
                $retval = $mail->send();
204
 
                if( $retval == true ) {
205
 
                        return true;
206
 
                } else {
207
 
                        return false;
208
 
                }
209
 
        } // send
210
 
 
211
 
        public function send_to_group($group_name) {
212
 
                $mail = new PHPMailer();
213
 
 
214
 
                foreach(self::get_users($group_name) as $member) {
215
 
                        if(function_exists('mb_encode_mimeheader')) {
216
 
                                $member['fullname'] = mb_encode_mimeheader($member['fullname']);
217
 
                        }
218
 
                        $mail->AddBCC($member['email'], $member['fullname']);
219
 
                }
220
 
 
221
 
                return $this->send($mail);
222
 
        }
223
 
 
224
 
} // AmpacheMail class
225
 
?>