I am attempting to correct a timezone problem in entourage email messages. I am trying to modify the date of the message to display UTC - 7, where the headers of the email show UTC.
The script encludes the following statement
set time sent of theMess to date theDate
and I have (perhaps mistakenly) been beating my head looking through the Applescript Language Guide ((c) 1999!!!) on the Apple Developer website and trying the various examples for doing arithmetic on dates with no success. I am ssuming the guide is badly out of date.
Can anyone suggest a possible solution to correcting the time offset in theDate, or date?
You can use the ‘time to gmt’ standard addition command to get the difference between gmt and local time. This is negative or zero seconds, so subtracting will add the seconds to the current date. Something like this:
set cur_date to (current date)
set gmt_secs to (time to GMT) – negative or 0
set utc_date to (cur_date - gmt_secs) – adding seconds
This sort of helps - I am able to make changes now to the time sentd. However I am not able to apply logic to the right part of the header - I am only able to make changes to the existing time received.
However, the received time that shows up in Entourage is
Sun, 3 Apr 2005 11:12:07 which is the time that my system crashed, and Entourage proceeded to reload all of my inbox, and used the current time to set the received time in Entourage. It did this to every one of the emails in my system, and I need to correct them.
So Barry Wainwright has a well-known script that fixes Entourage time stamps. His script is right here at applescript.net, and, slightly modified to handle time received instead of sent is:
+++++++++++++++++++++++++++++++++++++++++++++++++
– Correct the date v1.0 25th June 2002
– a script for Microsoft Entourage by Barry Wainwright
– Resets the date of messages to the date of the last received header
– useful for messages with badly formatted (or just plain wrong) dates
tell application “Microsoft Entourage”
set theMessages to current messages
if theMessages is {} then
display dialog “No messages selected!” buttons {“Stop”} default button 1 with icon stop
return -99
end if
repeat with theMess in theMessages
set theHeaders to the headers of theMess
set AppleScript's text item delimiters to {return & space}
set theHeaders to text items of theHeaders
set AppleScript's text item delimiters to {space}
set theHeaders to theHeaders as string
set AppleScript's text item delimiters to {return & tab}
set theHeaders to text items of theHeaders
set AppleScript's text item delimiters to {space}
set theHeaders to theHeaders as string
set theHeaders to the paragraphs of theHeaders
set receivedHeader to ""
repeat with aHeader in theHeaders
if aHeader starts with "Received:" then copy contents of aHeader to receivedHeader
if contents of receivedHeader is not "" then exit repeat
end repeat
set AppleScript's text item delimiters to {";","("}
set theDate to (last text item of receivedHeader)
set time sent of theMess to date theDate
end repeat
end tell
+++++++++++++++++++++++++++++++++++++++++++++++++
It works great, except it is unaware of the timezone in the header vs. the timezone on my machine. So it takes the time in the header, and converts it exactly without taking the offset into account. Running the sample header through the script returns a received time of
Fri, 1 Apr 2005 21:55:23
wheras the actual time received was this time - 0700, or
I tried your suggestion. However it seems to fail, no matter which of teh options I use:
set AppleScript’s text item delimiters to {“;”, “(”}
set theDate to (last text item of receivedHeader)
set theDate to ((date theDate) - (time to GMT)) as string
– set theDate to ((date theDate) - 7 * hours) as string
set time received of theMess to myDate
returns:
time to GMT
-25200
get date " Thu, 07 Apr 2005 21:55:23 +0000"
“Microsoft Entourage got an error: Can’t get date " Thu, 07 Apr 2005 21:55:23 +0000”."
Any suggestions? Can the +0000 be causing the problem?
is impropper. I don’t see how you could coerce the date before and now it doesn’t work. One thing I noticed is that the text item delimiters are unnecessary as is anyway because it has always been that you can’t use more than 1 text item delimiter. On the other hand you say that the script works other than the date being in utc (or gmt). All I did was take the string date and add (actually subtract) the difference between the gmt. Where it’s going wrong is not with the adjustment in the date but with the original script.
Are you sure that the original script does anything?
Things can be deceiving sometimes. The text parsing in the script looks fishy.
I could not get Entourage to show the header, but I can get it in a script if truth be told that the original script doesn’t work.
Check it out. I’m not too good at parsing but can probably create something that works.
This might be it. Sometimes, using keywords from scripting additions in tell app blocks don’t work because the same words are used in the app. So you need to coerce it out of the tell block. This was my original thought, but you said that it worked (the coercion to date). Again I’m thinking that it didn’t work.
I’ll look it tomorrow. Trying to have fun tonight.
tell application "Microsoft Entourage"
set theMessages to current messages
if theMessages is {} then
display dialog "No messages selected!" buttons {"Stop"} default button 1 with icon stop
return -99
end if
set astid to AppleScript's text item delimiters
repeat with theMess in theMessages
set AppleScript's text item delimiters to "Received:"
set topReceivedLine to text item 2 of theHeaders
set AppleScript's text item delimiters to ";"
set theDate to text from first word to last word of (last text item of topReceivedLine)
set AppleScript's text item delimiters to space
set baseDate to (date (text 1 thru text item 5 of theDate))
set timeDiff to (time to GMT) - (text item 6 of theDate) / 100 * hours
set time received of theMess to baseDate + timeDiff
end repeat
set AppleScript's text item delimiters to astid
end tell