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 :: Unread Messages :: Show Polls :: Message Navigator
| Subscribe to topic | Bookmark topic 
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 04:26 Go to next message
Peter Vendike is currently offline  Peter Vendike   Denmark
Messages: 65
Registered: February 2009
Location: Denmark
Karma: 0
Member
Translator
add to buddy list
ignore all messages by this user
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 04: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 06:21 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3624
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
remove from buddy list
ignore all messages by this user
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 02:55 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3624
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
remove from buddy list
ignore all messages by this user
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 09: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
add to buddy list
ignore all messages by this user
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 09: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 09:47 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3624
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
remove from buddy list
ignore all messages by this user
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 10: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
add to buddy list
ignore all messages by this user
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 10: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 10: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
add to buddy list
ignore all messages by this user
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 10: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 11:14 Go to previous messageGo to next message
naudefj is currently offline  naudefj   South Africa
Messages: 3624
Registered: December 2004
Karma: 17
Senior Member
Administrator
Core Developer
remove from buddy list
ignore all messages by this user
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 10:10 Go to previous message
Peter Vendike is currently offline  Peter Vendike   Denmark
Messages: 65
Registered: February 2009
Location: Denmark
Karma: 0
Member
Translator
add to buddy list
ignore all messages by this user
there was missing a "'" in the code from my last message, i edited it now
Quick Reply
Formatting Tools:   
  Switch to threaded view of this topic Create a new topic
Previous Topic: Message Navigator: No logical search function
Next Topic: avatar upload
Goto Forum:
  

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

Current Time: Mon Oct 23 13:08:40 EDT 2017

Total time taken to generate the page: 0.00681 seconds