Advertisement

09.06.2007 at 05:42PM PDT, ID: 22812403
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

Parsing email messages in perl??

Tags: perl, parse, email
Hi,

I was gonna play around and fix the bug but I need to process two batches of  data for my client by tomorrow and I am not yet efficient to write this up in short time.
I got some help already to write up this script here but it is not process the file correctly.
It just print out each line from the data file.

I just want to parse them into one cvs file under this headings.
File,Full Path,Extension,Subject,Email Date,From,To,CC,AttachementInfo,BCC,Exported,Attachments

Some of these fields might run off more than one line. I checked a few files and definitely know (Full Path,To, CC, BCC and attachemnts might run on multiple lines)

There are multiple files in a folder and each file contains multiple messages separated by == lines and white space.
Your help will be greatly appreciated.


script:
#!/usr/bin/perl
#Parse email - exchange data
#ParseExchangeMessage.pl
use strict;

my $record;
open (IN, "C:/Project/Perl/some mesage.txt") or die "We have a problem: $!";
{local $/; $record = <IN>;}
close IN;

print "File,Full Path,Extension,Subject,Email Date,From,To,CC,Attachement,BCC,Exported\n";

$record = "_-_\n" . $record . "_-_\n";

my ($match1, $fileName) = ($record =~ /(File\s*:\s*(.+)\n)/i);
$record =~ s/$match1/_-_/;
print "$fileName,";


my($fullpath) = ($record =~ /Full Path\s*:\s*(.+?)\n_-_/si);
print "$fullpath,";


my ($match3, $extension) = ($record =~ /(Extension\s*:\s*(.+)\n)/i);
$record =~ s/$match3/_-_/;
print "$extension,";

my ($match4, $subject) = ($record =~ /(Subject\s*:\s*(.+)\n)/i);
$record =~ s/$match4/_-_/;
print "$subject,";

my ($match5, $email) = ($record =~ /(Email Date\s*:\s*(.+)\n)/i);
$record =~ s/$match5/_-_/;
print "$email,";

my ($match6, $from) = ($record =~ /(From\s*:\s*(.+)\n)/i);
$record =~ s/$match6/_-_/;
print "$from,";

my ($match7, $to) = ($record =~ /(To\s*:\s*(.+)\n)/i);
$record =~ s/$match7/_-_/;
print "$to,";

my ($match8, $cc) = ($record =~ /(CC\s*:\s*(.+)\n)/i);
$record =~ s/$match8/_-_/;
print "$cc,";

my ($match9, $attachment) = ($record =~ /(Attachment Info\s*:\s*(.+)\n)/i);
$record =~ s/$match9/_-_/;
print "$attachment,";

my ($match10, $bcc) = ($record =~ /(BCC\s*:\s*(.+)\n)/i);
$record =~ s/$match10/_-_/;
print "$bcc,";

my ($match11, $exp) = ($record =~ /(Exported as\s*:\s*(.+)\n)/i);
$record =~ s/$match11/_-_/;
print "$exp,";


my($attachment) = ($record =~ /Attachments\s*:\s*(.+?)\n_-_/si);
print "$attachment\n";


Sample Data:

some text here
===========================================================================

File: Message0004
Full Path: D:\user\some email accounts\sh_Other Misc aol
Accts\xxx.xxx.mbox>>Message0004
Extension:
Subject: "RE: Email ID/s"
Created: N/A
Modified: N/A
Logical Size: 6,858
Deleted:
MD5: B0B88F5C5268D60C8DCA539FD720BD32
Email Date: Tue, 9 Jan 2007 16:06:07 +0330
From: "xxx xxx" <xxx.xxx@xx.com>
To: "'xxxxxxx'" <xxx.xxx@xx.com>
CC: "'xxxxxxx'" <xxx.xxx@xx.com>, <xxx.xxx@xx.com>,<xxx.xxx@xx.com>,
<xxx.xxx@xx.com>,<xxx.xxx@xx.com>,<xxx.xxx@xx.com>,
<xxx.xxx@xx.com>,<xxx.xxx@xx.com>,<xxx.xxx@xx.com>,<xxx.xxx@xx.com>
Attachment Info:
BCC:
Exported as: file1.html (Link: Export/file1.html)
Attachments: Message0004&#62;&#62;Attachment1 (Link: Export/file1)

===========================================================================


File: Message0016
Full Path: C:\users\some email accounts\ur7_Other Misc some
Accts\xxx.xxxmbox>>Message0016
Extension:
Subject: "xxxxxxxxx"
Created: N/A
Modified: N/A
Logical Size: 5,672
Deleted:
MD5: 358683D75A7079ABCB8BB30C7134A3A0
Email Date: Sun, 21 Jan 2007 17:40:23 +0400
From: "xxxxx xxx" <xxx.xxx@xx.com>
To: <xxx.xxx@xx.com>
CC: xxx.xxx@xx.com, xxx.xxx@xx.com, xxx.xxx@xx.com,
xxx.xxx@xx.com,xxx.xxx@xx.com
Attachment Info:
BCC:
Exported as: sdddd2.html (Link: Export/sdddd2.html)
Attachments: Message0016&#62;&#62;Attachment1 (Link: Export/sdddd2)
    Message0016&#62;&#62;xxxxxxxxP1.jpg (Link:
Export/sdddd2.jpg)
    Message0016&#62;&#62;xxxxxxxxxP2.jpg (Link:
Export/sdddd2.jpg)
    Message0016&#62;&#62;xxxxxxxxxx.jpg (Link:
Export/sdddd2.jpg)
    Message0016&#62;&#62;xxxxxxxxxxx.jpg (Link:
Export/sdddd2.jpg)
    Message0016&#62;&#62;xxxxxxx).jpg (Link: Export/sdd3.jpg)
    Message0016&#62;&#62;xxxx.jpg (Link: Export/xxxxxx.jpg)

===========================================================================
Start your free trial to view this solution
Question Stats
Zone: Programming
Question Asked By: dkim18
Solution Provided By: mjcoyne
Participating Experts: 3
Solution Grade: A
Views: 74
Translate:
Loading Advertisement...
09.06.2007 at 06:01PM PDT, ID: 19844728

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.06.2007 at 06:34PM PDT, ID: 19844851

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.06.2007 at 10:30PM PDT, ID: 19845592

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.07.2007 at 07:56AM PDT, ID: 19848220

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.07.2007 at 08:55AM PDT, ID: 19848814

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.07.2007 at 10:37AM PDT, ID: 19849611

Rank: Sage

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
09.07.2007 at 01:54PM PDT, ID: 19850920

Rank: Genius

All comments and solutions are available to Premium Service Members only.

Start your 7-day free trial and see for yourself why Experts Exchange is the easiest and most proven technology resource in the world. Get Started

Already a member? Login to view this solution.

 
 
Loading Advertisement...
20080236-EE-VQP-29 / EE_QW_1_20070628