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

Home » FUDforum Development » Bug Reports » Maillist.php patch for pure html mails
Show: Today's Messages :: Polls :: Message Navigator
Switch to threaded view of this topic Create a new topic Submit Reply
Maillist.php patch for pure html mails [message #159246] Fri, 15 May 2009 08:26 Go to next message
Peter Vendike is currently offline  Peter Vendike   Denmark
Messages: 65
Registered: February 2009
Location: Denmark
Karma: 0
Member
Translator
In (rare) cases where the imported mail has no 'text/plain' alternative and is pure html, the body-text showed up as one long line, barely readable (of cause only if 'Allow HTML in Mailing List Messages' is off).

This small patch saves the line breaks and the text formatting is kept for the imported message.




*** maillist.php	2009-05-14 17:39:33.000000000 +0200
--- maillist_pat.php	2009-05-15 09:44:54.000000000 +0200
***************
*** 121,126 ****
--- 121,129 ----
  
  			case 'text/html':
  				$this->decode_message_body();
+ 				// We need to keep line breaks for textformatting befor using 'strip_tags'
+ 				$l_breaks = array("<br />", "</p>", "<p>", "<br>" );
+ 				$this->body = str_replace($l_breaks, "\n", $this->body);
  				$this->body = (!$html ? strip_tags($this->body) : $this->body);
  				break;
  

[Updated on: Fri, 15 May 2009 08:55]

Report message to a moderator

Re: Maillist.php patch for pure html mails [message #159247 is a reply to message #159246] Fri, 15 May 2009 10:21 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
Will this also work:

Index: maillist.php
===================================================================
RCS file: /forum21/install/forum_data/scripts/maillist.php,v
retrieving revision 1.78
diff -u -r1.78 maillist.php
--- maillist.php        3 May 2009 18:43:45 -0000       1.78
+++ maillist.php        15 May 2009 10:20:02 -0000
@@ -121,7 +121,11 @@

                        case 'text/html':
                                $this->decode_message_body();
-                               $this->body = (!$html ? strip_tags($this->body) : $this->body);
+                               if (!$html) {
+                                       $this->body = str_ireplace(array('<br />', '<br>'), "\n", $this->body);
+                                       $this->body = str_ireplace(array('<p>', '</p>'),  "\n\n", $this->body);
+                                       $this->body = strip_tags($this->body);
+                               }
                                break;

                        case 'multipart/parallel': // Apparently same as multipart/mixed but order of body parts does not matter
Re: Maillist.php patch for pure html mails [message #159251 is a reply to message #159247] Sat, 16 May 2009 06:55 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
Many thanks! Your patch was committed - see http://cvs.prohost.org/c/index.cgi/FUDforum/chngview?cn=11926
Re: Maillist.php patch for pure html mails [message #159253 is a reply to message #159251] Sat, 16 May 2009 13:02 Go to previous messageGo to next message
Peter Vendike is currently offline  Peter Vendike   Denmark
Messages: 65
Registered: February 2009
Location: Denmark
Karma: 0
Member
Translator
Hej Frank

I tried your patch today, the "\n\n" for "<p>" looks more like the original html, so i think we could use your model, still keeping only 1 "\n" for "</p>" , and i also don't believe its necessary to ask for html=true ones again.

Peter

				$this->decode_message_body();
				$this->body = str_replace("<p>", "\n\n", $this->body);
				$this->body = str_replace(array("<br />", "</p>", "<br>" ), "\n", $this->body);
				$this->body = strip_tags($this->body);
				break;

[Updated on: Sat, 16 May 2009 13:05]

Report message to a moderator

Re: Maillist.php patch for pure html mails [message #159254 is a reply to message #159253] Sat, 16 May 2009 13:47 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
Are you sure we can remove the HTML test? The function can be called with html=0 or 1.

Also, note the str_ireplace instead of str_replace.

Best regards.

Frank
Re: Maillist.php patch for pure html mails [message #159255 is a reply to message #159254] Sat, 16 May 2009 14:01 Go to previous messageGo to next message
Peter Vendike is currently offline  Peter Vendike   Denmark
Messages: 65
Registered: February 2009
Location: Denmark
Karma: 0
Member
Translator
Yes I was just thinking the same, if that is used for the multipart bodies? I just can't deduct that.

Just to say, it work for some multipart test messages without that test:

$this->body = (!$html ? strip_tags($this->body) : $this->body);


else one could do something like $html => break earlier?

also, i don't now if these tags are sometimes used in capitals, so we need the case-insensitive version?

Peter

[Updated on: Sat, 16 May 2009 14:35]

Report message to a moderator

Re: Maillist.php patch for pure html mails [message #159256 is a reply to message #159255] Sat, 16 May 2009 14:47 Go to previous messageGo to next message
Peter Vendike is currently offline  Peter Vendike   Denmark
Messages: 65
Registered: February 2009
Location: Denmark
Karma: 0
Member
Translator
So I think I accept this version:


+                               if (!$html) {
+                                       $this->body = str_ireplace(array('<br />', '<br>', '</p>'), "\n", $this->body);
+                                       $this->body = str_ireplace('<p>', "\n\n", $this->body);
+                                       $this->body = strip_tags($this->body);
+                               }
                                break;

[Updated on: Mon, 18 May 2009 14:10]

Report message to a moderator

Re: Maillist.php patch for pure html mails [message #159257 is a reply to message #159256] Sat, 16 May 2009 15:14 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
Done. Thanks for reporting the problem and helping us to get it fixed.
Re: Maillist.php patch for pure html mails [message #159273 is a reply to message #159257] Mon, 18 May 2009 14:10 Go to previous message
Peter Vendike is currently offline  Peter Vendike   Denmark
Messages: 65
Registered: February 2009
Location: Denmark
Karma: 0
Member
Translator
there was missing a "'" in the code from my last message, i edited it now
  Switch to threaded view of this topic Create a new topic Submit Reply
Previous Topic: Message Navigator: No logical search function
Next Topic: avatar upload
Goto Forum:
  

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

Current Time: Sat Nov 23 10:21:26 GMT 2024

Total time taken to generate the page: 0.04092 seconds