Perl

Moderators: Jonathan
Number of threads: 1257
Number of posts: 3636

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
How to match optional string while reading a email header Posted by singhpratap on 13 Aug 2010 at 3:08 PM
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*)(\w\w\w\w\w\w-\w\w\w\w\w\w-\w\w*)(\s*)(for email@domain_name.com)(\s*)(;)(\s*)(\S*\s*\S*\s*\S*\s*\S*)(\s*)(\d\d:\d\d:\d\d)(.*)(\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: <E1Ok1yC-0006AT-Co@domain_name.com>

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



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.