Post by everett3rdIf anyon is interested I will post the code.
-Everett3rd
I would love to see the code on this. This is quite the issue for me
right now....
Here is the code I wrote.....VBscript
Feel free to ask any questions.
I have tried to comment everything enough for good reference.
It should be easy to modify for your situation.
I apologize for any code sloppiness, this is my 1st "production"
VBScript
There is some line wraping in the code below.
Let me know what you think.
My first full run against my server renamed 44976 messages with no
issues.
It took about 45 hours to go through 37000+ folders.
The "update runs" only take about 15-20 minutes to climb the entire
project tree and rename 50-100 messages per day.
Let me know what you think. If you come up with ways to make it
better, please share...
My next project is to write a script to move an email to the proper
folder based on the standardized subject.
Example...
Move and RFI email to the RFI folder, Move a PR email to the PR
Folder, and move Meeting Minutes to the Meeting Minutes folder. The
Ladies were kind enough to give me 43 different folders and codes to
evaluate for each email.
When I get this new one working I will be happy to share it as well.
-Everett
'*************************************************************************************************************
'***This script scans a folder tree and renames all .msg files to
comply with the
'***standard for project email retension as set forth in the E-File
standards document.
'***This Script was written by Everett E. Reilly III
'***Last Modified on: February 14, 2008
'***
'***
'*** to run this script open a command window and type "Email-
Efile.vbs" at the command prompt.
'*** this script generates a text log file
'***
'*************************************************************************************************************
'Declare object names
Dim olkApp, objFSO, ObjTextFile
set objFSO = CreateObject("Scripting.FileSystemObject")
'Set Counters: Mc = Message Counter
Mc = 0
On Error Resume Next
set olkApp = GetObject("Outlook.Application")
On Error GoTo 0
If TypeName(olkApp) <> "Application" Then
Set olkApp = CreateObject("Outlook.Application")
End If
'set logfile location and name
Set objTextFile = Objfso.CreateTextFile("\\ComputerName\folder
\logFile.txt", True)
'Script Begin Stamp
StrDTStampBegin = "Date: " & Date & " " & "Time: " & Time
Call LogOutput (objTextFile,
"********************************************")
Call LogOutput (objTextFile, "SCRIPT BEGIN: " & StrDTStampBegin)
Call LogOutput (objTextFile,
"............................................")
Call LogOutput (objTextFile, "...Renaming *.MSG files to DLR Group
Standards.")
Call LogOutput (objTextFile, "...Text Log Format:")
Call LogOutput (objTextFile,
"............................................")
Call LogOutput (objTextFile, "...Path OriginalFilename.msg")
Call LogOutput (objTextFile, "... NewFilename.MSG")
Call LogOutput (objTextFile,
"............................................")
Call LogOutput (objTextFile, " ")
Call LogOutput (objTextFile, " ")
Call LogOutput (objTextFile, " ")
'set root folder to begin processing, can use UNC Path here
Call ProcessFolder("\\ComputerName\folder\subfolder\")
'Script END Stamp
StrDTStampEnd = "Date: " & Date & " " & "Time: " & Time
Call LogOutput (objTextFile,
"............................................")
Call LogOutput (objTextFile, "SCRIPT END: " & StrDTStampEnd)
Call LogOutput (objTextFile, "Total messages processed: " &
Mc)
Call LogOutput (objTextFile,
"********************************************")
objTextFile.Close
'unload objects and terminate the script
set objFSO = Nothing
set olkApp = Nothing
WScript.Quit()
Sub ProcessFolder(path)
Dim objFolder, objFile
'insert new folder flag in log file
Call LogOutput (objTextFile,
"............................................")
Call LogOutput (objTextFile, "***** Processing: " & path)
'begin processing .msg files and skip file if already processed.
For Each objFile In objFSO.GetFolder(path).Files
Call ProcessFile(objFile)
Next
'process all subfolders recursively
For Each objFolder In objFSO.GetFolder(path).SubFolders
Call ProcessFolder(objFolder.Path)
Next
End Sub
Sub ProcessFile(objFile)
If objFile.Type = "Outlook Item" And Not
lcase(left(objFile.Name, 4)) = "eml_" Then
Call LogOutput (objTextFile,
"............................................")
Call LogOutput (objTextFile, objFile.path)
on error resume next
Set olkMessage =
olkApp.CreateItemFromTemplate(objFile.path)
'Cleanup Time stamp.
objTime = olkMessage.ReceivedTime
objTime = Replace(objtime, "/", "-")
objTime = Replace(objtime, ":", "-")
objTime = Replace(objtime, " ", "_")
on error goto 0
'Make sure file is an outlookmailItem, read receipts,
delivery receipts, and meeting requests are not processed
if not objTime = "" Then
'Cleanup Sender Name.
objSender = olkMessage.SenderName
objSender = Replace(objSender, ",", "")
objSender = Replace(objSender, " ", "")
'Cleanup Receiver Name.
'If no human readable receiver name then set
"objReceiver" to "Recv-NO-NAME"
on error resume next
If len(olkMessage.ReceivedByName) > 0 Then
objReceiver = olkMessage.ReceivedByName
Else
objReceiver = olkMessage.ReceivedOnBehalfOfName
End If
If len(olkMessage.ReceivedOnBehalfOfName) < 1 Then
objReceiver = "Recv-NO-NAME"
End If
objReceiver = Replace(objReceiver, ",", "")
objReceiver = Replace(objReceiver, " ", "")
'Cleanup subject text.
'If no Subject on Email set "objSubject" to "NO-
SUBJECT"
on error resume next
If len(olkMessage.Subject) < 1 Then
objSubject = "NO-SUBJECT"
Else
objSubject = left(olkMessage.Subject, 25)
End If
'remove restricted characters from subject string
objSubject = Replace(objSubject, ":", "-")
objSubject = Replace(objSubject, "\", "-")
objSubject = Replace(objSubject, "/", "-")
objSubject = Replace(objSubject, "?", "-")
objSubject = Replace(objSubject, Chr(34), "-")
objSubject = Replace(objSubject, "|", "-")
objSubject = Replace(objSubject, "*", "-")
objSubject = Replace(objSubject, "<", "-")
objSubject = Replace(objSubject, ">", "-")
objSubject = Replace(objSubject, ",", "_")
objSubject = Replace(objSubject, ".", "_")
objSubject = Replace(objSubject, "&", "-")
objSubject = Replace(objSubject, "(", "_")
objSubject = Replace(objSubject, ")", "_")
objSubject = Replace(objSubject, "^", "_")
objSubject = Replace(objSubject, "#", "_")
objSubject = Replace(objSubject, "@", "_")
objSubject = Replace(objSubject, "!", "_")
objSubject = Replace(objSubject, "~", "_")
'Create New File Name for each message file.
objNewMsgName = ("EML_" & objSender & "_" &
objReceiver & "_" & objSubject & "_" & objTime) & ".msg"
objName = objNewMsgName
Mc = Mc + 1
'Check for Duplicate file names Cn = Copy number
Cn = 1
Do While objfso.FileExists(objfile.parentfolder &
"\" & objName)
objName = objNewMsgName & "_COPY-" & Cn
Cn = Cn + 1
Loop
objFile.Name = objName
Call ModFileDT(objFile.ParentFolder, objFile.Name,
olkMessage.ReceivedTime)
Call LogOutput (objTextFile, vbtab & objfile.name)
End If
End If
End Sub
'Subrutine to apply new file name and properties to .MSG file.
Sub ModFileDT(strDir, strFileName, DateTime)
Dim objShell, objFolder, objFile
set objShell = CreateObject("Shell.Application")
set objFolder = objShell.NameSpace(CStr(strDir))
set objFile = objFolder.ParseName(CStr(strFileName))
objFile.ModifyDate = CStr(DateTime)
set objShell = Nothing
set objFolder = Nothing
set objFile = Nothing
End Sub
Sub LogOutput(ObjTextFile, Text)
Set File = ObjTextFile
wscript.echo(Text)
File.WriteLine(Text)
End Sub