Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

How to match optional string while reading a email header

singhpratapsinghpratap Posts: 1Member
Hello All,

I am trying to fetch some information from the email header. I am piping the mail to my script and want to fetch the particular content from the header but I am having difficulties to fetch it.

My seacrh string is as given below.
===========================
my $test = '(From) (S*@*S*)(s*)(S*s*S*s*S*s*S*s*S*)(s*)(.*)(s*)(id)(s*)(wwwwww-wwwwww-ww*)(s*)(for email@domain_name.com)(s*)(;)(s*)(S*s*S*s*S*s*S*)(s*)(dd:dd:dd)(.*)(s*)(Subject:)(s*)(.*)(s*)(From:|Message-Id:)(s*)(.*)';
============================

It is working well if mail header does not have any one value in it out of (From:|Message-Id:) but if the mail header have both of them then it is printing the Subject line along with the Message_Id or From: which ever is there in the header first.
For example I am getting the Subject line as below :
Subject=>test from test email ID Message-Id:

I want to select only subject filed. Is there any way to strip both of them using the regex.

I also want to know if there is any way to replace new line character with string in a multi-line string.
I tried to replace with it space and it is working but if I am trying it with string such as $$$$$ or :::: my script is not executing itself.

Thank you
Sign In or Register to comment.