Feature #5864

Regex Text on Receiver Email

Added by Sam Bo almost 3 years ago. Updated 4 months ago.

Status:NewStart date:2010-07-10
Priority:NormalDue date:
Assignee:-% Done:

0%

Category:Email receiving
Target version:-
Resolution:

Description

Modify the "Truncate Email after these lines" section or add a new section that allows a regex to be added.. This would make the truncation of emails much easier and the ability for anyone to support their specific requirements for truncating after the email system replied to text ("On Wed June 24th 2010 Johnny wrote:" ).

This is related to #2852

I modified the controller for the mail hander to look for both the text truncation and hard coded the reply line that my email system uses.. It could easily be adapted to use a similar approach and regex check multiple expressions to handle different scenarios.

My Hard Coded Example:
regex = Regexp.new("(^(#{ delimiters.join('|') })\s*[\r\n].*)|(On (.*)wrote:[\r\n].*)", Regexp::MULTILINE)

A proposed generic pseudo-code controller example:
regex = Regexp.new("(^(#{ delimiters.join('|') })\s*[\r\n].*)|(#{ delimitersregex.join('|') })", Regexp::MULTILINE)

History

#1 Updated by Bart Stuyckens almost 3 years ago

+1

#2 Updated by Terence Mill almost 3 years ago

+1

#3 Updated by Akshat Pradhan almost 3 years ago

Sam, where did you put this? I'm looking in mail_handler_controller.rb and that doesn't look like the correct place to put this. I also want to be able to regex out a certain portion of all incoming emails. I use google apps/smtp for all received emails.

Sam Bo wrote:

My Hard Coded Example:
regex = Regexp.new("(^(#{ delimiters.join('|') })\s*[\r\n].*)|(On (.*)wrote:[\r\n].*)", Regexp::MULTILINE)

A proposed generic pseudo-code controller example:
regex = Regexp.new("(^(#{ delimiters.join('|') })\s*[\r\n].*)|(#{ delimitersregex.join('|') })", Regexp::MULTILINE)

#5 Updated by Sam Bo over 1 year ago

I'm going to 1 (not the G kind mind you) this since it has been over a year. I'd love to see this so we don't have to manually update the model on each upgrade! If I knew anything about Ruby I'd submit a patch.

#6 Updated by Sam Bo over 1 year ago

Ouch, the plus 1 didn't come through correctly. Sorry for the double posting here.

#7 Updated by Nick Caballero 12 months ago

diff -r 146377aeb5a8 app/models/mail_handler.rb
--- a/app/models/mail_handler.rb    Sun May 13 19:09:35 2012 +0000
+++ b/app/models/mail_handler.rb    Fri May 25 23:00:22 2012 +0000
@@ -415,9 +415,9 @@

   # Removes the email body of text after the truncation configurations.
   def cleanup_body(body)
-    delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?).map {|s| Regexp.escape(s)}
+    delimiters = Setting.mail_handler_body_delimiters.to_s.split(/[\r\n]+/).reject(&:blank?)
     unless delimiters.empty?
-      regex = Regexp.new("^[> ]*(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE)
+      regex = Regexp.new("^(#{ delimiters.join('|') })\s*[\r\n].*", Regexp::MULTILINE)
       body = body.gsub(regex, '')
     end
     body.strip

#8 Updated by Jens Schneider 4 months ago

+1

This would be extremly helpfull for filtering multilingual email replys.

Depending on the users email programm, the sender could be displayed as:

Von: [mailto:]
or
From: [mailto:]

With a regular expression, this could be filtered out with a single line in the redmine configuration.

Also available in: Atom PDF