1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290
|
<?php
/*
* Gallery - a web based photo album viewer and editor
* Copyright (C) 2000-2006 Bharat Mediratta
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or (at
* your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301, USA.
*
* $Id: mail.php 13338 2006-03-27 15:32:14Z jenst $
*/
/**
* @package Mail
*/
?>
<?php
/**
*
*/
function check_email($email) {
if (preg_match ("/(@.*@)|(\.\.)|(@\.)|(\.@)|(^\.)/", $email) || !preg_match ("/^.+\@(\[?)[a-zA-Z0-9\-\.]+\.([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$/", $email)) {
$mail_ok = false;
} else {
$mail_ok = true;
}
return $mail_ok;
}
function emailDisclaimer() {
global $gallery;
$msg = unhtmlentities(sprintf(_("Note: This is an automatically generated email message sent from the %s website. If you have received this in error, please ignore this message."),$gallery->app->photoAlbumURL).
" \r\n".
sprintf(_("Report abuse to %s"),$gallery->app->adminEmail));
$msg2 = sprintf("Note: This is an automatically generated email message sent from the %s website. If you have received this in error, please ignore this message. \r\nReport abuse to %s",
$gallery->app->photoAlbumURL, $gallery->app->adminEmail);
if ($msg != $msg2) {
return "\r\n\r\n$msg\r\n\r\n$msg2";
} else {
return "\r\n\r\n$msg";
}
}
/**
* This function is a wrapper around the Mail classes
* It has currently the same structure as gallery_mail_old
* Return is true when succesfully send, otherise false
* Errormessages are printed immediately
*/
function gallery_mail($to, $subject, $msg, $logmsg, $hide_recipients = false, $from = NULL, $isNotifyMail = false, $isHTML = false) {
global $gallery;
$bcc = array();
if(!is_array($to)) {
$to = array($to);
}
/* Begin Catch errors */
if ($gallery->app->emailOn == "no") {
echo "\n<br>". gallery_error(_("Email not sent as it is disabled for this gallery"));
return false;
}
foreach($to as $rcpnr => $mail) {
if (! check_email($mail)) {
echo "\n<br>". gallery_error(sprintf(_("Email not sent to %s as it is not a valid address"),
'<i>' . $mail . "</i>"));
unset ($to[$rcpnr]);
}
}
if (empty($to)) {
echo "\n<br>". gallery_error(_("Email not sent as no reciepient address provided"));
return false;
}
if ($hide_recipients) {
$bcc = $to;
$to = array();
}
if (! check_email($from)) {
if (isDebugging() && $from) {
echo "\n<br>". gallery_error(sprintf(_("Sender address %s is invalid, using %s."),
$from, $gallery->app->senderEmail));
}
$from = $gallery->app->senderEmail;
$reply_to = $gallery->app->adminEmail;
} else {
$reply_to = $from;
}
/* End catch errors */
if(!empty($gallery->app->emailSubjPrefix)) {
$subject = $gallery->app->emailSubjPrefix .' '. $subject;
}
if (isset($gallery->app->email_notification) &&
in_array("bcc", $gallery->app->email_notification)) {
$bcc[] = $gallery->app->adminEmail;
}
if (get_magic_quotes_gpc()) {
$msg = stripslashes($msg);
}
$gallery_mail = new htmlMimeMail();
$gallery_mail->setSubject($subject);
$gallery_mail->setHeadCharset($gallery->charset);
if($isHTML) {
$gallery_mail->setHtmlCharset($gallery->charset);
$gallery_mail->setHtml($msg, _("This is a HTML mail, please have a look at the Attachment."));
}
else {
$gallery_mail->setText($msg);
$gallery_mail->setTextCharset($gallery->charset);
}
$gallery_mail->setFrom($from);
$gallery_mail->setReturnPath($reply_to);
/* As bccs are set as headers, they nead to be a string. Converting former array. */
if (!empty($bcc)) {
$gallery_mail->setBcc(implode(", ", $bcc));
}
if ($gallery->app->useOtherSMTP == "yes") {
$gallery_mail->setSMTPParams(
$gallery->app->smtpHost,
$gallery->app->smtpPort,
$gallery->app->smtpUserName,
FALSE,
$gallery->app->smtpUserName,
$gallery->app->smtpPassword
);
}
$result = $gallery_mail->send($to, ($gallery->app->useOtherSMTP != "yes") ? 'mail' : 'smtp');
if(! $isNotifyMail) {
emailLogMessage($logmsg, $result, $isNotifyMail);
}
return $result;
}
function welcome_email($show_default=false) {
global $gallery;
$default=_("Hi !!FULLNAME!!,
Congratulations. You have just been subscribed to %s at %s. Your account name is !!USERNAME!!. Please visit the gallery soon, and create a password by clicking this link:
!!NEWPASSWORDLINK!!
Gallery @ %s Administrator.");
if ($show_default) {
return sprintf($default,
"<b><nobr><" . _("gallery title") . "></nobr></b>",
"<b><nobr><" . _("gallery URL") . "></nobr></b>",
"<b><nobr><" . _("gallery title") . "></nobr></b>");
} elseif (empty($gallery->app->emailGreeting)) {
return sprintf($default,
$gallery->app->galleryTitle,
$gallery->app->photoAlbumURL,
$gallery->app->galleryTitle);
} else {
return $gallery->app->emailGreeting;
}
}
function welcomeMsgPlaceholderList() {
$placeholders = array(
'galleryurl' => _("The Url to your Gallery."),
'gallerytitle' => _("Title of your Gallery."),
'adminemail' => _("Admin email(s)"),
'password' => _("Password for the newly created user."),
'username' => _("Username"),
'fullname' => _("Fullname"),
'newpasswordlink' => _("Will be replaced by a link the new user can click on to create a new password.")
);
return $placeholders;
}
/**
* This function substitutes placeholder like !!USERNAME!!
* with the corresponding value in the welcome message for new users.
*/
function resolveWelcomeMsg($placeholders = array()) {
global $gallery;
$welcomeMsg = welcome_email();
$placeholders['galleryurl'] = $gallery->app->photoAlbumURL;
$placeholders['gallerytitle'] = $gallery->app->galleryTitle;
$placeholders['adminemail'] = $gallery->app->adminEmail;
foreach (welcomeMsgPlaceholderList() as $key => $trash) {
$welcomeMsg = str_replace('!!'. strtoupper($key) .'!!',
isset($placeholders[$key]) ? $placeholders[$key] : '', $welcomeMsg);
}
return $welcomeMsg;
}
/**
* This functions sends a notification to all people that request an email when a comment was added
* to an item.
* @param string $photoid
* @param string $comment_text
* @param string $commenter_name
*/
function emailComments($id, $comment_text, $commenter_name) {
global $gallery;
$to = $gallery->album->getEmailMeList('comments', $id);
$subject = sprintf(_("New comment for %s"), $id);
$text = '';
if (!empty($to)) {
$text .= '<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">';
$text .= "\n\n<html>";
$text .= "\n <head>";
$text .= "\n <title>$subject</title>";
$text .= "\n </head>\n<body>\n<p>";
$text .= sprintf(_("A new comment has been added to Gallery: %s"), $gallery->app->galleryTitle);
$text .= "\n</p>";
$text .= sprintf(_("The comment was added by %s to this %s in this %s."),
$commenter_name,
'<a href="'. makeAlbumHeaderUrl($gallery->session->albumName, $id) .'">'. _("Item") .'</a>',
'<a href="'. makeAlbumHeaderUrl($gallery->session->albumName) .'">'. _("Album") .'</a>');
$text .= "\n<br>". _("*** Begin comment ***") ."<br>\n";
$text .= nl2br($comment_text);
$text .= "<br>\n". _("***End comment ***") . "\n<p>\n";
$text .= _("If you no longer wish to receive emails about this image, follow the links above and ensure that 'Email me when comments are added' is unchecked in both the photo and album page (You'll need to login first).");
$text .= "\n</p>\n</body>\n</html>";
$logmsg = sprintf(_("New comment for %s."), makeAlbumHeaderUrl($gallery->session->albumName, $id));
gallery_mail($to, $subject, $text, $logmsg, true, NULL, false, true);
}
}
function emailLogMessage($logmsg, $result, $isNotifyMail) {
global $gallery;
if (!$result) {
$logmsg = sprintf(_("FAILED") ." / FAILED: %s", $logmsg);
}
if (isset($gallery->app->email_notification) &&
in_array("logfile", $gallery->app->email_notification)) {
$logfile = $gallery->app->userDir."/email.log";
logMessage($logmsg, $logfile);
}
if (isset($gallery->app->email_notification) &&
in_array("email", $gallery->app->email_notification)) {
$subject = _("Email activity");
if ($subject != "Email activity") {
$subject .= "/Email activity";
}
$subject .= ": ". $gallery->app->galleryTitle;
$subject = unhtmlentities($subject);
gallery_mail($gallery->app->adminEmail,
$subject,
$logmsg . emailDisclaimer(),
'',
false,
$gallery->app->senderEmail,
true
);
}
}
?>
|