I have a bash script that extracts headers from the MIME Source of an email. The idea is that I only want to capture the headers of the message nothing else. It's not quite working right though.
I want it to do the following:
1) Start at the top of the email.
2) Isolate just the part that starts with "From" (my particular upstream mail server ALWAYS starts the header with a line containing this).
3) Capture all lines below it UNTIL the first line break.
4) Don't bother capture stuff from the remainder of the email.
I thought I could do it with this sed pattern:
sed -n "/From/,/^$/p"
Unfortunately it triggers on other instances of "From". For example, if someone forwardes a message and there is content like:
---------- Forwarded message ---------- From: Newsletter <email@example.com> Date: Wed, Jan 28, 2015 at 9:16 PM Subject: Blargenflugent To: firstname.lastname@example.org
How can I have sed ignore content after the first line break?