FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » FUDforum Development » Bug Reports » Why is "backslash n" replaced in outgoing mail?
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Why is "backslash n" replaced in outgoing mail? [message #158952] Sun, 19 April 2009 12:11 Go to next message
tgtaft is currently offline  tgtaft   United States
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 #158964 is a reply to message #158952] Sun, 19 April 2009 20:18 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
To be honest, I don't know why it is there. If there's no objection, we can remove it.
Re: Why is "backslash n" replaced in outgoing mail? [message #158993 is a reply to message #158952] Tue, 21 April 2009 12:28 Go to previous messageGo to next message
tgtaft is currently offline  tgtaft   United States
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
Re: Why is "backslash n" replaced in outgoing mail? [message #158996 is a reply to message #158993] Tue, 21 April 2009 20:46 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Great patch. However, moving forward it will be better if we can remove the munge_newlines code altogether and convert the message files to GNU gettext (*.po files).
Re: Why is "backslash n" replaced in outgoing mail? [message #159055 is a reply to message #158996] Wed, 29 April 2009 20:37 Go to previous message
naudefj is currently offline  naudefj   South Africa
Messages: 3771
Registered: December 2004
Karma: 28
Senior Member
Administrator
Core Developer
Thanks. Patch was committed. For details, see http://cvs.prohost.org/c/index.cgi/FUDforum/chngview?cn=11918
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: change ROOT path and time problem
Next Topic: NNTP Errors
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sat Nov 23 20:15:48 GMT 2024

Total time taken to generate the page: 0.03283 seconds