Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting through thousands of email files and sorting them

Status
Not open for further replies.

Cyberdud

Technical User
Jan 25, 2008
6
CA
I've been trying to figure out how to setup a script that would look through all email files held in a folder for recipient email addresses(find the To: string) and then would send them in a folder named after said person(if the folder doesn't exist, it creates it). The files are all saved in a folder under .msg file extensions(readable in any text editor)

example:

100 spam emails get sent to the folder, the script runs, sorts all the emails in folders(10 spam are sent to julie@fakecompany.com, so theres a folder named julie with all her emails in there.)

We want to give people access to their spam so they can see if we filtered the wrong emails without having to manually sort through thousands of emails

Doesn't have to be fast, but I'm hitting a brick wall here

 
I'm really rusty vbscript wise so I'm struggling with finding a way to look for the To: string and then extract the name before the @ (test@blabla.com would be test)
 
Have a look at the InStr and Mid functions.

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Here's an update

here's my code so far:

Dim objFSO
dim objfile
dim email
dim rangestart
dim rangeEnd
dim ending
dim store
dim user
dim MailFolder
' only need one file object really.
Set objFSO = CreateObject("Scripting.FileSystemObject")

' Note: once you get this working for ideal cases, look into some try / catch error handling
' to wrap around the whole thing and then some logging to show you which files caused
' problems in the event of a failure.

MailFolder = objFSO.getFolder("Spam")

' Go through the files in the folder.
if MailFolder.Files.Count > 0 then
for each MailFile in MailFolder.Files

' Even better if you test here to ensure the file is a .msg file and meets any other
' criteria you need it to.

' Get a file to inspect
Set objFile = objFSO.OpenTextFile( MailFile, 1)

ending = 0
while ending = 0
email = cstr(objfile.readline)
if inStr(email, "-To:") > 0 then
ending = 1
store = email
end if
if objFile.AtEndOfStream = True then
ending = 1
else
objfile.skipline
end if
wend

' Determine the user
user = mid(store ,inStr(email, "-To:")+4, (inStr(email , "@")) - (inStr(email, "-To:")+4 ))

' Check to see if a folder exists for this user

' Copy this file to the user's folder

' Delete this copy of the file?

' done with the file.
objfile.close

next
end if

The error I get is " Object required C:\VB\Spam"

am I missing something really obvious?
 
Try changing this:

MailFolder = objFSO.getFolder("Spam")

to use the full path.

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
I changed it to:

MailFolder = objFSO.getFolder("C:\VB\Spam")


It gives the same error ( on line 16 character 0)
 
[!]Set [/!]MailFolder = objFSO.getFolder("C:\VB\Spam")

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Ooops...that's why he is the Stars leader. :)

[red]"... isn't sanity really just a one trick pony anyway?! I mean, all you get is one trick, rational thinking, but when you are good and crazy, oooh, oooh, oooh, the sky is the limit!" - The Tick[/red]
 
'On Error Resume Next
Dim objFSO
dim objfile
dim email
dim rangestart
dim rangeEnd
dim ending
dim store
dim user
dim MailFolder
dim pathcomplet


Const FOR_READING = 1

strFolder = "c:\vb\Spam\"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set objFolder = objFSO.GetFolder(strFolder)


'WScript.Echo objFolder.Path

Set colFiles = objFolder.Files

For Each objFile In colFiles
Set objFileRead = objFSO.OpenTextFile( objFile , 1)
ending = 0
store =""
while ending = 0
email = cstr(objFileRead.readline)
if inStr(email, "-To:") > 0 then
ending = 1
store = email
end if

if objFileRead.AtEndOfStream = True then
ending = 1
store=" "
else
objFileRead.skipline
end if
wend
user = trim(mid(store ,inStr(store, "-To:")+4, (inStr(store , "@")) - (inStr(store, "-To:")+4 )))
pathcomplet = strFolder+user+"\"
pathfile = objFile.path
wscript.echo pathfile + pathcomplet ' test to see if both paths are well written
if objFSO.FolderExists(user) = False Then
objFSO.CreateFolder (user)
objFSO.copyFile pathfile, pathcomplet, true
Else
objFSO.copyFile pathfile, pathcomplet, true
end if
objfileRead.close
Next


Here's the full script as it stands right now, The problem is in the objFSO.copyFile. I give it both parameters, and they look fine in the wscript.echo but they give me the error "PATH NOT FOUND", if i enter a path manually it works but not with the variables

What can I do?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top