831 |
florian |
1 |
<?php
|
|
|
2 |
|
|
|
3 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
4 |
// //
|
|
|
5 |
// Copyright (C) 2006 Phorum Development Team //
|
|
|
6 |
// http://www.phorum.org //
|
|
|
7 |
// //
|
|
|
8 |
// This program is free software. You can redistribute it and/or modify //
|
|
|
9 |
// it under the terms of either the current Phorum License (viewable at //
|
|
|
10 |
// phorum.org) or the Phorum License that was distributed with this file //
|
|
|
11 |
// //
|
|
|
12 |
// This program is distributed in the hope that it will be useful, //
|
|
|
13 |
// but WITHOUT ANY WARRANTY, without even the implied warranty of //
|
|
|
14 |
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. //
|
|
|
15 |
// //
|
|
|
16 |
// You should have received a copy of the Phorum License //
|
|
|
17 |
// along with this program. //
|
|
|
18 |
////////////////////////////////////////////////////////////////////////////////
|
|
|
19 |
|
|
|
20 |
if(!defined("PHORUM")) return;
|
|
|
21 |
|
|
|
22 |
function phorum_valid_email($email){
|
|
|
23 |
$PHORUM = $GLOBALS["PHORUM"];
|
|
|
24 |
|
|
|
25 |
$ret = false;
|
|
|
26 |
|
|
|
27 |
$email = trim($email);
|
|
|
28 |
|
|
|
29 |
if(preg_match('/^([a-z0-9\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+(\.[a-z0-9\!\#\$\%\&\'\*\+\-\/\=\?\^\_\`\{\|\}\~]+)*)@(((([-a-z0-9]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))\.)*((([-a-z0-9]*[a-z0-9])?)|(#[0-9]+)|(\[((([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\.){3}(([01]?[0-9]{0,2})|(2(([0-4][0-9])|(5[0-5]))))\]))$/i', $email)){
|
|
|
30 |
if(!$PHORUM["dns_lookup"]){
|
|
|
31 |
// format is valid
|
|
|
32 |
// don't look up mail server
|
|
|
33 |
$ret = true;
|
|
|
34 |
}else{
|
|
|
35 |
// get the domain name from the mail address
|
|
|
36 |
$fulldomain = substr(strstr($email, "@"), 1).".";
|
|
|
37 |
|
|
|
38 |
// check if a mailserver exists for the domain
|
|
|
39 |
if(function_exists('checkdnsrr') && checkdnsrr($fulldomain, "MX")) {
|
|
|
40 |
$ret = true;
|
|
|
41 |
}
|
|
|
42 |
|
|
|
43 |
// some hosts don't have an MX record, but accept mail themselves
|
|
|
44 |
if(!$ret){
|
|
|
45 |
// default timeout of 60 seconds makes the user way too long
|
|
|
46 |
// in case of problems.
|
|
|
47 |
ini_set('default_socket_timeout', 10);
|
|
|
48 |
if(@fsockopen($fulldomain, 25)){
|
|
|
49 |
$ret = true;
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
|
|
|
55 |
return $ret;
|
|
|
56 |
}
|
|
|
57 |
|
|
|
58 |
/**
|
|
|
59 |
* function for sending email to users, gets addresses-array and data-array
|
|
|
60 |
*/
|
|
|
61 |
function phorum_email_user($addresses, $data)
|
|
|
62 |
{
|
|
|
63 |
$PHORUM = $GLOBALS['PHORUM'];
|
|
|
64 |
|
|
|
65 |
$mailmessage = $data['mailmessage'];
|
|
|
66 |
unset($data['mailmessage']);
|
|
|
67 |
$mailsubject = $data['mailsubject'];
|
|
|
68 |
unset($data['mailsubject']);
|
|
|
69 |
|
|
|
70 |
if(is_array($data) && count($data)) {
|
|
|
71 |
foreach(array_keys($data) as $key){
|
|
|
72 |
$mailmessage = str_replace("%$key%", $data[$key], $mailmessage);
|
|
|
73 |
$mailsubject = str_replace("%$key%", $data[$key], $mailsubject);
|
|
|
74 |
}
|
|
|
75 |
}
|
|
|
76 |
|
|
|
77 |
$num_addresses = count($addresses);
|
|
|
78 |
$from_address = "\"".$PHORUM['system_email_from_name']."\" <".$PHORUM['system_email_from_address'].">";
|
|
|
79 |
|
|
|
80 |
$hook_data = array(
|
|
|
81 |
'addresses' => $addresses,
|
|
|
82 |
'from' => $from_address,
|
|
|
83 |
'subject' => $mailsubject,
|
|
|
84 |
'body' => $mailmessage,
|
|
|
85 |
'bcc' => $PHORUM['use_bcc']
|
|
|
86 |
);
|
|
|
87 |
|
|
|
88 |
$send_messages = phorum_hook("send_mail", $hook_data);
|
|
|
89 |
|
|
|
90 |
if(isset($data["msgid"])){
|
|
|
91 |
$msgid="\nMessage-ID: {$data['msgid']}";
|
|
|
92 |
} else {
|
|
|
93 |
$msgid="";
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
if($send_messages != 0 && $num_addresses > 0){
|
|
|
97 |
$phorum_major_version = substr(PHORUM, 0, strpos(PHORUM, '.'));
|
|
|
98 |
$mailer = "Phorum" . $phorum_major_version;
|
|
|
99 |
$mailheader ="Content-Type: text/plain; charset={$PHORUM["DATA"]["CHARSET"]}\nContent-Transfer-Encoding: {$PHORUM["DATA"]["MAILENCODING"]}\nX-Mailer: $mailer$msgid\n";
|
|
|
100 |
|
|
|
101 |
if(isset($PHORUM['use_bcc']) && $PHORUM['use_bcc'] && $num_addresses > 3){
|
|
|
102 |
mail(" ", $mailsubject, $mailmessage, $mailheader."From: $from_address\nBCC: " . implode(",", $addresses));
|
|
|
103 |
} else {
|
|
|
104 |
foreach($addresses as $address){
|
|
|
105 |
mail($address, $mailsubject, $mailmessage, $mailheader."From: $from_address");
|
|
|
106 |
}
|
|
|
107 |
}
|
|
|
108 |
}
|
|
|
109 |
|
|
|
110 |
return $num_addresses;
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
function phorum_email_pm_notice($message, $langusers)
|
|
|
114 |
{
|
|
|
115 |
$mail_data = array(
|
|
|
116 |
"pm_message_id" => $message["pm_message_id"],
|
|
|
117 |
"author" => $message["from_username"],
|
|
|
118 |
"subject" => $message["subject"],
|
|
|
119 |
"full_body" => $message["message"],
|
|
|
120 |
"plain_body" => wordwrap(phorum_strip_body($message["message"]),72),
|
|
|
121 |
"read_url" => phorum_get_url(PHORUM_PM_URL, "page=read", "pm_id=" . $message["pm_message_id"]),
|
|
|
122 |
);
|
|
|
123 |
|
|
|
124 |
if (isset($_POST[PHORUM_SESSION_LONG_TERM])) {
|
|
|
125 |
// strip any auth info from the read url
|
|
|
126 |
$mail_data["read_url"] = preg_replace("!,{0,1}" . PHORUM_SESSION_LONG_TERM . "=" . urlencode($_POST[PHORUM_SESSION_LONG_TERM]) . "!", "", $mail_data["read_url"]);
|
|
|
127 |
}
|
|
|
128 |
|
|
|
129 |
foreach ($langusers as $language => $users)
|
|
|
130 |
{
|
|
|
131 |
$PHORUM = $GLOBALS["PHORUM"];
|
|
|
132 |
|
|
|
133 |
if ( file_exists( "./include/lang/$language.php" ) ) {
|
|
|
134 |
include( "./include/lang/$language.php" );
|
|
|
135 |
} else {
|
|
|
136 |
include("./include/lang/{$PHORUM['language']}.php");
|
|
|
137 |
}
|
|
|
138 |
|
|
|
139 |
$mail_data["mailmessage"] = $PHORUM["DATA"]["LANG"]['PMNotifyMessage'];
|
|
|
140 |
$mail_data["mailsubject"] = $PHORUM["DATA"]["LANG"]['PMNotifySubject'];
|
|
|
141 |
|
|
|
142 |
$addresses = array();
|
|
|
143 |
foreach ($users as $user) {
|
|
|
144 |
$addresses[] = $user["email"];
|
|
|
145 |
}
|
|
|
146 |
|
|
|
147 |
phorum_email_user($addresses, $mail_data);
|
|
|
148 |
}
|
|
|
149 |
}
|
|
|
150 |
|
|
|
151 |
function phorum_email_notice($message)
|
|
|
152 |
{
|
|
|
153 |
$PHORUM=$GLOBALS["PHORUM"];
|
|
|
154 |
|
|
|
155 |
// do we allow email-notification for that forum?
|
|
|
156 |
if(!$PHORUM['allow_email_notify']) {
|
|
|
157 |
return;
|
|
|
158 |
}
|
|
|
159 |
|
|
|
160 |
include_once("./include/format_functions.php");
|
|
|
161 |
|
|
|
162 |
$mail_users_full = phorum_db_get_subscribed_users($PHORUM['forum_id'], $message['thread'], PHORUM_SUBSCRIPTION_MESSAGE);
|
|
|
163 |
|
|
|
164 |
if (count($mail_users_full)) {
|
|
|
165 |
$mail_data = array(
|
|
|
166 |
"forumname" => strip_tags($PHORUM["DATA"]["NAME"]),
|
|
|
167 |
"forum_id" => $PHORUM['forum_id'],
|
|
|
168 |
"message_id" => $message['message_id'],
|
|
|
169 |
"author" => $message['author'],
|
|
|
170 |
"subject" => $message['subject'],
|
|
|
171 |
"full_body" => $message['body'],
|
|
|
172 |
"plain_body" => phorum_strip_body($message['body']),
|
|
|
173 |
"read_url" => phorum_get_url(PHORUM_READ_URL, $message['thread'], $message['message_id']),
|
|
|
174 |
"remove_url" => phorum_get_url(PHORUM_FOLLOW_URL, $message['thread'], "remove=1"),
|
|
|
175 |
"noemail_url" => phorum_get_url(PHORUM_FOLLOW_URL, $message['thread'], "noemail=1"),
|
|
|
176 |
"followed_threads_url" => phorum_get_url(PHORUM_CONTROLCENTER_URL, "panel=" . PHORUM_CC_SUBSCRIPTION_THREADS),
|
|
|
177 |
"msgid" => $message["msgid"]
|
|
|
178 |
);
|
|
|
179 |
if (isset($_POST[PHORUM_SESSION_LONG_TERM])) {
|
|
|
180 |
// strip any auth info from the read url
|
|
|
181 |
$mail_data["read_url"] = preg_replace("!,{0,1}" . PHORUM_SESSION_LONG_TERM . "=" . urlencode($_POST[PHORUM_SESSION_LONG_TERM]) . "!", "", $mail_data["read_url"]);
|
|
|
182 |
$mail_data["remove_url"] = preg_replace("!,{0,1}" . PHORUM_SESSION_LONG_TERM . "=" . urlencode($_POST[PHORUM_SESSION_LONG_TERM]) . "!", "", $mail_data["remove_url"]);
|
|
|
183 |
$mail_data["noemail_url"] = preg_replace("!,{0,1}" . PHORUM_SESSION_LONG_TERM . "=" . urlencode($_POST[PHORUM_SESSION_LONG_TERM]) . "!", "", $mail_data["noemail_url"]);
|
|
|
184 |
$mail_data["followed_threads_url"] = preg_replace("!,{0,1}" . PHORUM_SESSION_LONG_TERM . "=" . urlencode($_POST[PHORUM_SESSION_LONG_TERM]) . "!", "", $mail_data["followed_threads_url"]);
|
|
|
185 |
}
|
|
|
186 |
// go through the user-languages and send mail with their set lang
|
|
|
187 |
foreach($mail_users_full as $language => $mail_users) {
|
|
|
188 |
if ( file_exists( "./include/lang/$language.php" ) ) {
|
|
|
189 |
include( "./include/lang/$language.php" );
|
|
|
190 |
} else {
|
|
|
191 |
include("./include/lang/{$PHORUM['language']}.php");
|
|
|
192 |
}
|
|
|
193 |
$mail_data["mailmessage"] = $PHORUM["DATA"]["LANG"]['NewReplyMessage'];
|
|
|
194 |
$mail_data["mailsubject"] = $PHORUM["DATA"]["LANG"]['NewReplySubject'];
|
|
|
195 |
phorum_email_user($mail_users, $mail_data);
|
|
|
196 |
|
|
|
197 |
}
|
|
|
198 |
}
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
function phorum_email_moderators($message)
|
|
|
202 |
{
|
|
|
203 |
$PHORUM=$GLOBALS["PHORUM"];
|
|
|
204 |
|
|
|
205 |
$mail_users = phorum_user_get_moderators($PHORUM['forum_id'],false,true);
|
|
|
206 |
|
|
|
207 |
if (count($mail_users)) {
|
|
|
208 |
include_once("./include/format_functions.php");
|
|
|
209 |
if($message["status"] > 0) { // just notification of a new message
|
|
|
210 |
$mailtext = $PHORUM["DATA"]["LANG"]['NewUnModeratedMessage'];
|
|
|
211 |
} else { // posts needing approval
|
|
|
212 |
$mailtext = $PHORUM["DATA"]["LANG"]['NewModeratedMessage'];
|
|
|
213 |
}
|
|
|
214 |
$mail_data = array(
|
|
|
215 |
"mailmessage" => $mailtext,
|
|
|
216 |
"mailsubject" => $PHORUM["DATA"]["LANG"]['NewModeratedSubject'],
|
|
|
217 |
"forumname" => strip_tags($PHORUM["DATA"]["NAME"]),
|
|
|
218 |
"forum_id" => $PHORUM['forum_id'],
|
|
|
219 |
"message_id" => $message['message_id'],
|
|
|
220 |
"author" => $message['author'],
|
|
|
221 |
"subject" => $message['subject'],
|
|
|
222 |
"full_body" => $message['body'],
|
|
|
223 |
"plain_body" => phorum_strip_body($message['body']),
|
|
|
224 |
"approve_url" => phorum_get_url(PHORUM_PREPOST_URL),
|
|
|
225 |
"read_url" => phorum_get_url(PHORUM_READ_URL, $message['thread'], $message['message_id'])
|
|
|
226 |
);
|
|
|
227 |
if (isset($_POST[PHORUM_SESSION_LONG_TERM])) {
|
|
|
228 |
// strip any auth info from the read url
|
|
|
229 |
$mail_data["read_url"] = preg_replace("!,{0,1}" . PHORUM_SESSION_LONG_TERM . "=" . urlencode($_POST[PHORUM_SESSION_LONG_TERM]) . "!", "", $mail_data["read_url"]);
|
|
|
230 |
$mail_data["approve_url"] = preg_replace("!,{0,1}" . PHORUM_SESSION_LONG_TERM . "=" . urlencode($_POST[PHORUM_SESSION_LONG_TERM]) . "!", "", $mail_data["approve_url"]);
|
|
|
231 |
}
|
|
|
232 |
phorum_email_user($mail_users, $mail_data);
|
|
|
233 |
}
|
|
|
234 |
}
|
|
|
235 |
|
|
|
236 |
?>
|