<?xml version="1.0" encoding="utf-8"?>
<rss version="2.0">
  <channel>
    <title>'How to match optional string while reading a email header' Thread RSS Feed</title>
    <link>http://www.programmersheaven.com/</link>
    <description>Contains the latest posts from the thread 'How to match optional string while reading a email header' posted on the 'Perl' forum at Programmer's Heaven.</description>
    <language>en</language>
    <copyright>Copyright 2012 Programmers Heaven</copyright>
    <pubDate>Wed, 23 May 2012 23:03:32 -0700</pubDate>
    <lastBuildDate>Wed, 23 May 2012 23:03:32 -0700</lastBuildDate>
    <generator>Argotic Syndication Framework 2007.3.0.1, http://www.codeplex.com/Argotic</generator>
    <docs>http://www.rssboard.org/rss-specification</docs>
    <ttl>360</ttl>
    <image>
      <url>http://www.programmersheaven.com/images/ph.gif</url>
      <title>Programmers Heaven</title>
      <link>http://www.programmersheaven.com/</link>
      <width>88</width>
      <height>31</height>
    </image>
    <item>
      <title>How to match optional string while reading a email header</title>
      <link>http://www.programmersheaven.com/mb/perl/418301/418301/how-to-match-optional-string-while-reading-a-email-header/</link>
      <description>Hello All,&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
My seacrh string is as given below.&lt;br /&gt;
===========================&lt;br /&gt;
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*)(.*)';&lt;br /&gt;
============================&lt;br /&gt;
&lt;br /&gt;
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. &lt;br /&gt;
For example I am getting the Subject line as below :&lt;br /&gt;
Subject=&amp;gt;test from test email ID Message-Id: &amp;lt;E1Ok1yC-0006AT-Co@domain_name.com&amp;gt;&lt;br /&gt;
&lt;br /&gt;
I want to select only subject filed. Is there any way to strip both of them using the regex. &lt;br /&gt;
&lt;br /&gt;
I also want to know if there is any way to replace new line character with string in a multi-line string. &lt;br /&gt;
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. &lt;br /&gt;
&lt;br /&gt;
Thank you&lt;br /&gt;</description>
      <guid isPermaLink="true">http://www.programmersheaven.com/mb/perl/418301/418301/how-to-match-optional-string-while-reading-a-email-header/</guid>
      <pubDate>Fri, 13 Aug 2010 15:08:04 -0700</pubDate>
      <category>Perl</category>
    </item>
  </channel>
</rss>
