Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

When an application allows emails to be sent to it to either reply to comments or add todos, trimming those emails for just the relevant text becomes a problem, since there are many different standards. Many times you'll end up seeing things like this:

Hey Joe, good to hear from you. Let me know when you'll be back in town.
Posted by Bob, 30 minutes ago


I'll be back on the 13th.

--
Sincerely,
Joseph R. Roberts
Senior Partner

This communication is confidential and is property of Whatever Law Firm.
Posted by Joe, 10 seconds ago

Signatures are probably the most difficult to get rid of, and quoted text the easiest. I imagine any comprehensive strategy for trimming will be multi-facted, and ideally, learning. I think a good system should:

  1. Remove quoted body
  2. Remove quote headers ("On 15 October, Joe wrote:")
  3. Remove signatures
  4. Preserve anything that was typed manually.

What steps would a system need to take to accomplish this, and what pitfalls should it be aware of?


This answer is a good example of a useful answer to a similar question

share|improve this question
    
Be carefull with removing actual information while parsing because it removes context, probably better mark/index lines as discardable instead of removing them. –  Carlo Kuip Oct 29 '11 at 7:59
    
There's an unwritten standard signature delimiter, which is two hyphens and a space on a line by itself. –  Blrfl Oct 29 '11 at 15:11
    
But two hyphens don't always mean that, e.g. when the sender want to split something but the second half end up cut out. That hurts... –  Erica Xu Nov 1 '11 at 23:31
1  
The "-- " is used because eMail software usually discards trailing spaces, so it should only occur as a .sig delimiter. As with HTML and MIME in general, YMMV, but I haven't run across accidental occurences of this in practice. Among other things, Evolution and Gmail do the "-- " parsing. –  BRPocock Dec 28 '11 at 3:42

2 Answers 2

You can just trim the email as people usually do with their eye lasers. Ignore quoted parts and signature.

But make sure to save a copy in case the trimming messes up. Or you can let the customer cut a few emails first and follow his/her habits.

However carefully and considerate, I don't think there's any way to make sure all emails are trimmed property. Some weird things manually written will be cut off.

(Or you can change the way emails are written - make marks while people actually type or copy and paste and preserve those parts. But this change may take a long time...)

share|improve this answer

Properly formatted signatures are easy to identify by the '-- ' (dash dash space) line which precedes them. Good luck finding many. Although netiquette requires signatures to be no more than three lines many organizations have standards signatures and disclaimers which far exceed this.

Properly formatted quoted text will begin with one ore more '>' characters. This assumes that you have a plain text copy of the body to extract data from.

HTML formatted messages may have CSS styling which will help do what you want.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.