ChiliProject is not maintained anymore.
Please be advised that there will be no more updates.
We do not recommend that you setup new ChiliProject instances and
we urge all existing users to migrate their data to a maintained
system, e.g. Redmine. We will
provide a migration script later. In the meantime, you can use the
instructions by
Christian Daehn.
Forums » Discuss »
incoming HTML email with no plain text enhancement to mail_handler.rb
Added by Anthony Ordner at 2011-11-15 05:20 pm
I have been having problems with Exchange / Outlook sometimes sending only the HTML portion of the email and it was a real mess trying to read it with all of the tags stripped. I hacked an enhancement that first converts the </p> and </br> tags to \n and then strips the tags. This is much nicer to read. It changes plain_text_body within mail_handler.rb... I thought I would share in case it is helpful. Please remember this is a hack job as I do not know much about Ruby yet but have done a fair share of other programming over the years.... Be kind.
So instead of this:
Just testing again. Just testing again 2.Just testing again 3. Part 1. Part 2. Thank youtony Anthony Ordner
I now get this:
Again
Again, testing, again
Testing
tony
Anyhow enjoy if it helps...
tony
1
2
3 def plain_text_body
4 return @plain_text_body unless @plain_text_body.nil?
5 parts = @email.parts.collect {|c| (c.respond_to?(:parts) && !c.parts.empty?) ? c.parts : c}.flatten
6 if parts.empty?
7 parts << @email
8 end
9 plain_text_part = parts.detect {|p| p.content_type == 'text/plain'}
10 if plain_text_part.nil?
11
12
13 @plain_text_body = @email.body.to_s.gsub("</p>", "\n");
14
15 @plain_text_body = @plain_text_body.gsub("</br>", "\n");
16
17 @plain_text_body = strip_tags(@plain_text_body)
18
19 @plain_text_body.gsub! %r{^<!DOCTYPE .*$}, ''
20 else
21 @plain_text_body = plain_text_part.body.to_s
22 end
23 @plain_text_body.strip!
24 @plain_text_body
25 end
I'm not sure I really like this kind of solution. Doesn't redcloth (the textile library) a function to convert html to somewhat equivalent textile?
Thanks for sharing though, I'm sure you're not the only one having to use Exchange/Outlook ;-)
I did a fair amount of googling and could not find much going from html to text.... most of it was text to html. If there is a cleaner way let me know.
Wowsher aka tony