A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2009 yearBest way to chop a signature off an email body - page 1
User InfoPosts
Best way to chop a signature off an email body#1
I am parsing out some emails. Mobile Mail, iPhone and I assume iPod touch append a signature as a separate boundary, making it simple to remove. Not all mail clients do, and just use (--( as a signature delimiter.

I need to chop off the (--( from a string, but only the last occurrence of it.

Sample copy

 hello, this is some email copy-- check this out
--
Tom Foolery


I thougth about splitting on (--(, removing the last part, and I would have it, but explode() and split() neither seem to return great values for letting me know if it did anything, in the event there is not a match.

I can not get preg_replace to go across more than one line. I have standardized all line endings to \n

What is the best suggestion to end up with "hello, this is some email copy-- check this out", taking not, there will be cases where there is no signature, and there are of course going to be cases where I can not cover all the cases.

posted date: 2009-04-07 04:17:00


Re: Best way to chop a signature off an email body#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2009-04-07 04:17:01


Re: Best way to chop a signature off an email body#3
Actually correct signature delimiter is "-- \n" (note the space before newline), thus the delimiter regexp should be (^-- $(. Although you might consider using (^--\s*$(, so it(ll work with OE, which gets it wrong.

posted date: 2009-04-07 04:22:00


Re: Best way to chop a signature off an email body#4
Try this:preg_replace((/--[\r\n]+.*/s(, ((, $body)This will remove everything after the first occurence of -- followed by one or more line break characters. If you just want to remove the last occurence, use /.*--[\r\n]+.*/s instead.

posted date: 2009-04-07 04:24:00


Re: Best way to chop a signature off an email body#5
I was unaware there was a standard for signature format. Can you cite?

posted date: 2009-04-07 04:26:00


Re: Best way to chop a signature off an email body#6
RFC3676 section 4.3

posted date: 2009-04-07 04:28:00


Re: Best way to chop a signature off an email body#7
Which would be tools.ietf.org/html/rfc3676#section-4.3. As the RFC states, it's more a widely accepted convention than a real standard.

posted date: 2009-04-07 04:29:00


Re: Best way to chop a signature off an email body#8
Instead of just chopping of everything after -- could you not cache the last few emails sent by that user or service and compare. The bit at the bottom that looks like the others can be safely removed leaving the proper message intact.

posted date: 2009-04-07 04:40:00


Re: Best way to chop a signature off an email body#9
Just to clarify: the final /s makes the regex treat the whole string as a [S]ingle line

posted date: 2009-04-07 04:58:00


Re: Best way to chop a signature off an email body#10
good information but I highly doubt that you could expect it to be consistent.

posted date: 2009-04-07 05:24:00


Re: Best way to chop a signature off an email body#11
I think in the interest of being more bulletproof, I will take the non regex route echo substr($body, 0, strrpos($body, "\n--"));

posted date: 2009-04-07 14:57:00


Re: Best way to chop a signature off an email body#12
@scott: true, but then there's nothing that can be done about signatures that don't comply.

posted date: 2009-04-07 23:02:00


select page: « 1 2 »
Copyright ©2008-2017 www.momige.com, all rights reserved.