Jump to content
Sign in to follow this  

Change text in eml file to undelete

Recommended Posts

To make a long story short, I fat fingered in Thunderbird, and deleted all my inbox. I didn't compact yet, so I have followed some instructions that I got on a Thunderbird site, and now have created a directory that has all my emails that I deleted in them, but each email is an .eml file.

Each eml file contains something similar to this:

X-Mozilla-Status: 0009

X-Mozilla-Status2: 00000000


To: asawyer@chambersddd.xxx

Date: Sun, 27 Nov 2005 15:13:30 -0500

Subject: Your post "Excel Templates" on the LogiXML discussion board has a

new reply.

From: Discussion@logixml.com

Content-type: text/plain; charset=windows-1252; format=flowed

MIME-Version: 1.0

Content-transfer-encoding: 8bit

Thread: "Excel Templates"

Replied On: 11/27/2005 10:13:30

See details, go to http://www.logixml.com/rdPage.aspx?rdRepor...p;ThreadID=3404

Okay the line that says X-Mozilla-Status: 0009 needs to be changed to X-Mozilla-Status: 0000

but the 0009 can be a random number, I just need to change it to 0000.

I need to do this for all 5000 eml files.

As anybody done this before? If so, it sure would save me some time. I'm not an Autoit expert, but could maybe figure it out, but it would probably take me a while.

Any help would be appreciated.


Share this post

Link to post
Share on other sites

Have a look at FileFindFirstFile, FileFindNextfile, FileOpen, FileRead, StringReplace, and FileWrite.

That's probably what you need to fulfill your goal. :)

Share this post

Link to post
Share on other sites

I guess the biggest issue that I wouldn't know how to do is

basically I need to replace

X-Mozilla-Status: 0009


X-Mozilla-Status: 0000

and the 0009 could be anything, so I need to replace X-Mozilla-Status: nnnn

with X-Mozilla-Status: 0000.

How can I string search for that?


Share this post

Link to post
Share on other sites

FileRead the the file, and use StringSplit on the data it returns, split @CRLF, or @LF, depends on the file format..

Then loop through the array StringSplit returns(use a For loop for this), until you're at the element containing the text(use StringInStr to determine when), then do this:

$Array[$i] = StringLeft($Array[$i], StringInstr($Array[$i], ":")) & " 0000"

$Array being the array that StringSplit returns, $i being the variable used in your For loop.


This example should give you an idea:

#include <Array.au3>

$fileContent = FileRead(@DesktopDir & "\Test.eml")
$Array = StringSplit($fileContent, @CRLF, 1)

For $i = 1 To $Array[0]
    If StringInStr($Array[$i], "X-Mozilla-Status:") Then
        $Array[$i] = StringLeft($Array[$i], StringInstr($Array[$i], ":")) & " 0000"
        ConsoleWrite($Array[$i] & @LF)

_ArrayDelete($Array, 0)

FileDelete(@DesktopDir & "\Test.eml")
FileWrite(@DesktopDir & "\Test.eml", _ArrayToString($Array, @CRLF))

Put one of our eml files on your desktop, and rename it to Test, and run the script, I took the content you posted in your first post and tried it against that, and it worked fine. :)

Edited by FreeFry

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...