Why is "backslash n" replaced in outgoing mail? [message #158952] |
Sun, 19 April 2009 12:11 |
tgtaft
Messages: 3 Registered: March 2009
Karma: 0
|
Junior Member |
|
|
I've noticed that when a post contains the two characters "backslash n" (i.e., '\n'), FUDforum replaces them with a single newline (i.e., "\n") in mail notifications. I tracked this down to line 78 of src/iemail.inc.t:
$body = str_replace(array('\n',"\r"), array("\n",""), $body);
If I change this to:
$body = str_replace("\r", "", $body);
The problem goes away. But why was the code there? Is it OK to change it or will that cause another problem?
I can't see any reason to suppress the "backslash n" character sequence; in fact, the current behaviour is very annoying when posting code snippets (e.g., I suspect the code above with its sequence of backslash n's will appear corrupted in email).
|
|
|
|
Re: Why is "backslash n" replaced in outgoing mail? [message #158993 is a reply to message #158952] |
Tue, 21 April 2009 12:28 |
tgtaft
Messages: 3 Registered: March 2009
Karma: 0
|
Junior Member |
|
|
I think I discovered why the original substitution code was there. Many of the pre-written email notices that the forum sends out (e.g., when a password reset is requested) are defined in, e.g., thm/default/i18n/english/msg, and they use two-character backslash n sequences to define newlines. With my original patch, none of these messages (e.g., reset_reset on line 423 in english/msg) look right when sent.
This new patch restricts the fix to notifications.
--- iemail.inc.t.orig 2009-04-21 08:23:54.000000000 -0400
+++ iemail.inc.t 2009-04-21 08:25:57.000000000 -0400
@@ -45,7 +45,7 @@
return $text;
}
-function send_email($from, $to, $subj, $body, $header='')
+function send_email($from, $to, $subj, $body, $header='', $munge_newlines=1)
{
if (empty($to)) {
return;
@@ -75,7 +75,10 @@
}
$header = "From: ".$from."\nErrors-To: ".$from."\nReturn-Path: ".$from."\nX-Mailer: FUDforum v".$GLOBALS['FORUM_VERSION'].$header;
- $body = str_replace(array('\n',"\r"), array("\n",""), $body);
+ $body = str_replace("\r", "", $body);
+ if ($munge_newlines) {
+ $body = str_replace('\n', "\n", $body);
+ }
$subj = encode_subject($subj);
if (version_compare("4.3.3RC2", phpversion(), ">")) {
$body = str_replace("\n.", "\n..", $body);
--- tmp/imsg_edt.inc.t.orig 2009-04-21 08:15:19.000000000 -0400
+++ tmp/imsg_edt.inc.t 2009-04-21 08:15:25.000000000 -0400
@@ -785,6 +785,6 @@
$subj = $frm_descr." ".$subj;
}
- send_email($GLOBALS['NOTIFY_FROM'], $to, $subj, $body_email, $headers);
+ send_email($GLOBALS['NOTIFY_FROM'], $to, $subj, $body_email, $headers, 0);
}
?>
\ No newline at end of file
|
|
|
|
|