Is it possible to programmatically 'clean' emails?

后端 未结 6 1069
一向
一向 2021-01-03 08:36

Does anyone have any suggestions as to how I can clean the body of incoming emails? I want to strip out disclaimers, images and maybe any previous email text that may be als

6条回答
  •  一生所求
    2021-01-03 09:09

    In email, there is couple of agreed markings that mean something you wish to strip. You can look for these lines using regular expressions. I doubt you can't really well "sanitize" your emails, but some things you can look for:

    1. Line starting with "> " (greater than then whitespace) marks a quote
    2. Line with "-- " (two hyphens then whitespace then linefeed) marks the beginning of a signature, see Signature block on Wikipedia
    3. Multipart messages, boundaries start with --, beyond that you need to do some searching to separate the message body parts from unwanted parts (like base64 images)

    As for an actual C# implementation, I leave that for you or other SOers.

提交回复
热议问题