Reputation: 165
I have text file containing text from email as mentioned above . I need to extract values for E2, E1, E0 and each of those for From:, Sent: , To: , Subject: Can we do it using regex expression ?
we can do like "^(From|Sent|To|Subject):(.*)" regex in java . But is there any comprehensive regex for above example of text ?
Upvotes: 0
Views: 187
Reputation: 148880
Unsure if related, but some mail readers (thunderbird among others) store the mails in a text file with a determined format :
From
(ie From followed by a space and not a column) : this line is the begin of a mailFrom
line is the body of the mailIf you are reading such a file, I strongly advice you to not rely on known HEARDERNAMES but to parse the file according to the above rules, or even better use the mailbox
module that will do that for you and :
Upvotes: 1
Reputation: 818
Take a look at the raw message source. You'll see there should be a uniform first header and there's always and always, only, a blank line separating the headers from the actual message (the part you want).
You can create a regex to look for the first blank line after the first header, then extract the body.
Upvotes: 1