Title: Re: received message timing
OK, thanks for fixing that up Allen. The semi-colon thing – I checked hundreds of messages when I wrote the script and they all had the same format. Not sure if this is a standard or not, but it seemed to be all-pervading so I went with it. Looks like this one is an exception.

The GMT thing is different. Since I’m living IN GMT,I never fell over this! I’m not sure that your ‘ends in ‘00’ will catch every possibility – I’ll have to think about that...

--
Barry Wainwright
Microsoft MVP (see http://mvp.support.microsoft.com for details)
Seen the All-New Entourage Help Pages? - Check them out:
        <http://www.entourage.mvps.org/>



From: Allen Watson <[EMAIL PROTECTED]>
Reply-To: "Entourage:mac Talk" <[EMAIL PROTECTED]>
Date: Fri, 23 Jul 2004 12:00:58 -0700
To: "Entourage:mac Talk" <[EMAIL PROTECTED]>
Subject: Re: received message timing

On 7/23/04 9:48 AM, I wrote:

> It might be helpful to see the actual headers of the message that is
> getting the wrong time set. Can you do a View Source on it, copy that, and
> send it to us?  

I ran the script on a sampling of messages, and found that I was getting the same errors about invalid date. Here's the Received header in question:

Received: from 207.217.125.19 ([221.154.102.17])
    by killdeer (EarthLink SMTP Server) with SMTP id 1bO3cG1lD3NZFlr0
    Fri, 23 Jul 2004 09:47:15 -0700 (PDT)

Notice that the date begins with an abbreviated day of the week. The dates in headers of messages where the script works do not have that weekday part; that is probably the cause of the error. I'll experiment...nope! AppleScript's "date" eats that up, weekday and timezone at the end and all. Must be something else. Ah! It is lacking the semicolon delimiter! Bad! I wonder if, when the semicolon is absent, one can rely on the date being on a separate line? Nope. Hmmm....(Hours later)

I also ran into the extra hours of offset problem. I discovered that my Earthlink server, located God know where, is using GMT. So, something that arrived at 9:45 AM is showing up as arriving at 4:45 PM! (Seven hours offset to Pacific time zone.) I think the script somehow needs to get the local user's offset from GMT, compare it to the one in the Received header time stamp, and adjust if the two are different. The same problem could arise with national outfits that have local connections but whose servers are in a different time zone. I recall, when I used AOL for a brief period, that my mail was being sent and stored on servers on the east coast while I was living in Arizona, two time zones away.

I've munged Barry's script and made it considerably more complex to handle these two problems. It seems to work for me now. Give it a try.

-- Script from a message sent by Barry Wainwright
-- on Wednesday, July 21, 2004 3:15:13 PM

-- Correct the date v1.0 25th June 2002
-- (Modified 22/7/2004 to set Time Received to First Received Header date)
-- (Modified 23/7/2004 by Allen Watson to handle
--   malformed headers missing semicolon, and
--   to adjust if the server's time zone differs from the user's local time zone
-- a script for Microsoft Entourage by Barry Wainwright
-- Resets the date of messages to the date of the first 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
               exit repeat
           end if
       end repeat
       if receivedHeader contains ";" then
           set AppleScript's text item delimiters to {";"}
        else
           set AppleScript's text item delimiters to {","}
        end if
       set thedate to (last text item of receivedHeader)
        set GMToff to my hoursToGMTString()
        if last word of thedate does not end with "00" then -- GMT offset in last word
           repeat with i from (count thedate) to 1 by -1
                if character i of thedate = " " then
                   set thedate to text 1 thru (i - 1) of thedate
                   exit repeat
               end if
           end repeat
       end if
       set theirGMToff to text -5 thru -1 of thedate
       if theirGMToffGMToff then
           tell me to set theirDate to date thedate
           set theirHoursOff to (theirGMToff as number) / 100
            set myHoursOff to (GMToff as number) / 100
            set newDate to theirDate - (theirHoursOff * hours) + (myHoursOff * hours) -- Adjust to local time
           set time received of theMess to newDate
       else
           set time received of theMess to date thedate
       end if
   end repeat
end
tell

on hoursToGMTString()
    -- Return a numeric string of the hours offset from current time zone to GMT
   -- e.g. "-0700" for Pacific Daylight Time
   set secOffset to time to GMT
   if (secOffset) ≠ 0 then
       set temp to ((secOffset) div 60 div 60 * 100)
        if temp ≥ 0 then
           return "+" & (text -4 thru -1 of ("0" & temp as text))
        else
           return "-" & (text -4 thru -1 of ("0" & text 2 thru -1 of (temp as text)))
        end if
   else
       return "-0000"
    end if
end
hoursToGMTString




Reply via email to