Get data from a file via script

Associate
Joined
6 Oct 2006
Posts
375
Location
Luton
Hi All

I hope somebody could help with produce a script (I am useless at scripting).

Basically I need a script that will parse an eml file, and put the main body text into a variable, which I can then use to update a database. This is for use for an helpdesk system and we use Lotus notes which makes things more difficult for us.

The eml files will be in a folder, for example, c:\eml

The script will need to get the files from this folder and parse the files and the the main body of the email into a variable. An example of an eml file is shown below:

Code:
x-sender: [EMAIL="[email protected]"][email protected][/EMAIL]
x-receiver: [EMAIL="[email protected]"][email protected][/EMAIL]
Received: from VSV-HUB-01.company.co.uk ([x.x.x.x]) by helpdesk.company.co.uk with Microsoft SMTPSVC(7.5.7601.17514);
  Thu, 27 Oct 2011 13:20:40 +0100
To: [EMAIL="[email protected]"][email protected][/EMAIL]
MIME-Version: 1.0
Subject: Fw: New Incident Ref: [IR5776]. created.
X-KeepSent: 6249F802:92027064-80257936:0043BA12;
 type=4; name=$KeepSent
X-Mailer: Lotus Notes Release 8.5.2 August 10, 2010
From: <[EMAIL="[email protected]"][email protected][/EMAIL]>
Message-ID: <[EMAIL="OF6249F802.92027064-ON80257936.0043BA12-80257936.0043C3A6@company.co.uk"]OF6249F802.92027064-ON80257936.0043BA12-80257936.0043C3A6@company.co.uk[/EMAIL]>
Date: Thu, 27 Oct 2011 13:20:09 +0100
X-MIMETrack: Serialize by Router on HUB01/Servers/company(Release 8.5.2FP2|March 22, 2011) at
 27/10/2011 13:20:40,
 Serialize complete at 27/10/2011 13:20:40
Content-Type: multipart/alternative; boundary="=_alternative 0043C37F80257936_="
Return-Path: [EMAIL="[email protected]"][email protected][/EMAIL]
X-OriginalArrivalTime: 27 Oct 2011 12:20:40.0374 (UTC) FILETIME=[D73EED60:01CC94A2]
This is a multipart message in MIME format.
--=_alternative 0043C37F80257936_=
Content-Type: text/plain; charset="US-ASCII"
Still not working
Thanks
user
----- Forwarded by user/company on 27/10/2011 13:19 -----
From:   [EMAIL="[email protected]"][email protected][/EMAIL]
To:     [EMAIL="[email protected]"][email protected][/EMAIL]
Date:   27/10/2011 13:12
Subject:        New Incident Ref: [IR5776]. created.
 
Thank you for logging a call with company Help Desk. 
Your Incident Reference Number is: [IR5776] 27/10/2011 13:05:25
Call Description - [To:[email protected]] Help me
Please reference the IR number in any communication relating to this 
incident.
Regards
company HelpDesk
Tel: xxxxxx
Short Dial: xxxx
Email: [EMAIL="[email protected]"][email protected][/EMAIL]
--=_alternative 0043C37F80257936_=
Content-Type: text/html; charset="US-ASCII"
<font size=2 face="sans-serif">Still not working</font>
<br>
<br><font size=2 face="sans-serif">Thanks</font>
<br><font size=2 face="sans-serif">User</font>
<br><font size=1 color=#800080 face="sans-serif">----- Forwarded by user/company on 27/10/2011 13:19 -----</font>
<br>
<br><font size=1 color=#5f5f5f face="sans-serif">From: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">[email protected]</font>
<br><font size=1 color=#5f5f5f face="sans-serif">To: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">[email protected]</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Date: &nbsp; &nbsp; &nbsp;
&nbsp;</font><font size=1 face="sans-serif">27/10/2011 13:12</font>
<br><font size=1 color=#5f5f5f face="sans-serif">Subject: &nbsp; &nbsp;
&nbsp; &nbsp;</font><font size=1 face="sans-serif">New Incident
Ref: [IR5776]. created.</font>
<br>
<hr noshade>
<br>
<br>
<br><font size=3>Thank you for logging a call with company Help Desk.
<br>
Your Incident Reference Number is: [IR5776] 27/10/2011 13:05:25</font>
<p><font size=3>Call Description - [To:[email protected]]
Help me</font>
<p><font size=3>Please reference the IR number in any communication relating
to this incident.</font>
<p><font size=3><br>
Regards<br>
company HelpDesk<br>
Tel: xxxxxx<br>
Short Dial: xxxxx<br>
Email: [EMAIL="[email protected]"][email protected][/EMAIL]</font>
--=_alternative 0043C37F80257936_=--

Basically it is everything from the line Content-Type: text/plain; charset="US-ASCII" to the end of the main body. I haven't taken into consideration yet if the eml file has an attachment as I believe that this information will appear as base64 encoded text after the main body.

Once I have this information into a variable I can use this variable to update the record of this call. i will be using a powershell script to update the call from the vbscipt. I know how to do this bit, I just don't know how to get the information that I need.

Can anybody help with this.

Cheers
Richard
 
What are the conditions for the eml files in the folder. i.e are they being constantly added to the folder. You have to distinguish between what is new and what has already been read. Or is this just a one off operation parsing every file in the folder?
 
This should work, but is just for 1 file, but will show you how to read that file.

Code:
Const ForReading = 1

Set objFSO = CreateObject("Scripting.FileSystemObject")
Set objT = objFSO.OpenTextFile("c:\eml\file_1.txt", ForReading)

strS = objT.ReadAll
emLVar=  Mid(strS,InStr(lcase(strS),("content-type")),len(strS)-InStr(lcase(strS),("content-type"))+1)

objT.Close
 
Back
Top Bottom