Getting the dates (month/day/year) for each email in a given folder

Hello, I’m wondering if anyone out there has any experience/advice for scripting Entourage.

I’m trying to work on a script that returns a list of the dates (month/day/year) for each email in a given folder. Then i need to count the number of emails rec ieved on each date. Finally I need that info saved as a text file.

I’ve done a little scripting in the past, but Entourage is not working with on this one.

Thanks for any energy to spend on this one.
jc

Hi,

I think this will do it.
You may need to enter your values for the date ranges and Entourage folder names where indicated
In my case with thousands of mails, this may takes several minutes to go.
At the end, you will find 3 text files on your desktop: MsgDates, Summary (Msgs per day) and MsgLog (dates, IDs and subjects of messages)

Good luck

Eelco Houwink


tell application "Microsoft Entourage"
	set theF to some folder of in box folder whose name is "YourName" --> enter your folder name here..!
	set rr to messages of theF
	set TimeRecs to ""
	repeat with r in rr
		set TimeRecs to TimeRecs & time received of r & return
	end repeat
end tell
WriteToFile(TimeRecs, "MsgDates.txt")

set IDs to {}
set msgs to ""
set ItemsPerDay to ""
set tr to ((current date) - (time of the (current date))) as date
tell application "Microsoft Entourage"
	repeat with i from 0 to 2 -- Enter the number of days you want to go back here..!
		set tr2 to (tr) - i * 24 * 3600
		set tr3 to (tr) - (i + 1) * 24 * 3600
		set rr to (messages of in box folder whose time sent < tr2 and time sent > tr3) --> or: substitute "in box folder" with theF as defined earlier
		set ItemsPerDay to ItemsPerDay & date string of tr2 & ": " & (number of items of rr) & " mails" & return
		repeat with r in rr
			set IDs to IDs & ID of r
			set msgs to msgs & time sent of r & ", id: " & ID of r & " subj: " & subject of r & return
		end repeat
	end repeat
end tell

WriteToFile(ItemsPerDay, "Summary.txt")
WriteToFile(msgs, "MsgLog.txt")
return {ItemsPerDay, msgs}

on WriteToFile(txt, fName)
	tell application "Finder"
		if exists file fName then move file fName to trash
		set LogFile to make new file with properties {kind:"text", name:fName} with replacing
		set LogFile to LogFile as string
		set myFile to (open for access alias LogFile with write permission)
		set eof myFile to 0
		write txt to alias LogFile
		close access myFile
	end tell
end WriteToFile

Forgot to mention:

You may need to change “time sent” to “time received”.
(in my case time sent was better for testing purposes)

i’m sorry it has taken me so long to get back to you…
i left town and then returned to a mountain of paperwork. i’m sure you know the story.
Anyway, thank you for all of your work. I will test it now and let you know how it goes.
thanks again.
jc

Eelco, This is perfect! Thank you so much for the code.
With only minimal shifts i was able to get it to do exactly what i need.

Thanks again,
jc