Merge pull request #288 from Fraenkiman/Mail---robust-character-encoding

character encoding via core utils
- Instead of providing the mail subject with MIME base64 in different places, this has now been centralized.
This commit is contained in:
Frank Hochmuth 2023-12-25 02:24:36 +01:00 committed by GitHub
commit acf4cebdd3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 26 additions and 11 deletions

View File

@ -222,8 +222,8 @@ function commentform() {
$fp_config ['general'] ['title'] $fp_config ['general'] ['title']
), $lang ['comments'] ['mail']); ), $lang ['comments'] ['mail']);
// for non-ASCII characters in the e-mail header use RFC 1342 — Encodes data with MIME base64 and splits the encrypted subject // for non-ASCII characters in the e-mail header use RFC RFC 1342 — Encodes $subject with MIME base64 via core.utils.php
@utils_mail($from_mail, '=?utf-8?B?' . base64_encode($lang ['comments'] ['newcomment']) . '=?= =?utf-8?B?' . base64_encode($fp_config ['general'] ['title']) . '==?=', $mail); @utils_mail($from_mail, "{$lang['comments']['newcomment']} {$lang['comments']['newcomment']} {$fp_config['general']['title']}", $mail);
} }
// if comment is valid, this redirect will clean the postdata // if comment is valid, this redirect will clean the postdata

View File

@ -111,8 +111,8 @@ function contact_form() {
$msg .= "{$lang['contact']['notification']['content']} \n{$validationResult['content']}\n"; $msg .= "{$lang['contact']['notification']['content']} \n{$validationResult['content']}\n";
// send notification mail to site admin // send notification mail to site admin
// for non-ASCII characters in the e-mail header use RFC 1342 — Encodes data with MIME base64 and splits the encrypted subject // for non-ASCII characters in the e-mail header use RFC RFC 1342 — Encodes $subject with MIME base64 via core.utils.php
$success = @utils_mail((isset($validationResult ['email']) ? $validationResult ['email'] : $fp_config ['general'] ['email']), '=?utf-8?B?' . base64_encode($lang ['contact'] ['notification'] ['subject']) . '=?= =?utf-8?B?' . base64_encode($fp_config ['general'] ['title']) . '==?=', $msg); $success = @utils_mail((isset($validationResult ['email']) ? $validationResult ['email'] : $fp_config ['general'] ['email']), "{$lang['contact']['notification']['subject']} {$fp_config['general']['title']}", $msg);
system_seterr('contact', $success ? 1 : -1); system_seterr('contact', $success ? 1 : -1);
utils_redirect(basename(__FILE__)); utils_redirect(basename(__FILE__));
} }

View File

@ -287,13 +287,28 @@ function utils_countdashes($string, &$rest) {
return $i; return $i;
} }
function utils_mail($from, $subject, $message, $headers = '') { function utils_mail($from = '', $subject, $message, $headers = '') {
global $fp_config; global $fp_config;
if ($headers == '') { /*
$headers = "MIME-Version: 1.0\n" . "From: " . $from . "\n" . "Content-Type: text/plain; charset=\"" . $fp_config ['general'] ['charset'] . "\"\n"; * Fraenkiman: Many e-mail providers only allow e-mail addresses from domains that are known to the mail server via their mail server (SMTP host).
* As a rule, these are all e-mail addresses for domains that are registered with the provider.
* In some cases, however, there may be further restrictions, which you should ask your mail provider about.
* When using the PHP mail() function, clarify directly with your provider what restrictions and regulations there are for sending e-mails.
* For this reason, you should have set a sender e-mail address that is permitted for sending by the mail system used (e.g. SMTP).
*/
if ($from == '') {
$from = $fp_config ['general'] ['email'];
} }
if ($headers == '') {
return mail($fp_config ['general'] ['email'], $subject, $message, $headers); $headers = "MIME-Version: 1.0\r\n" . //
"From: " . $from . "\r\n" . //
"Content-Type: text/plain; charset=\"" . $fp_config ['general'] ['charset'] . "\"\r\n";
}
/*
* for non-ASCII characters in the e-mail header use RFC 1342 Encodes $subject with MIME base64
* https://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/
*/
return mail($fp_config ['general'] ['email'], '=?' . $fp_config ['general'] ['charset'] . '?B?' . base64_encode($subject) . '?=', $message, $headers);
} }
/* /*

View File

@ -438,8 +438,8 @@ class plugin_commentcenter {
$fp_config ['general'] ['title'] $fp_config ['general'] ['title']
), $text); ), $text);
// for non-ASCII characters in the e-mail header use RFC 1342 — Encodes data with MIME base64 // for non-ASCII characters in the e-mail header use RFC RFC 1342 — Encodes $subject with MIME base64 via core.utils.php
return @utils_mail($from_mail, '=?utf-8?B?' . base64_encode($subject) . '?=', $text); return @utils_mail($from_mail, $subject, $text);
} }
} }