At 11:20 am -0800 16/1/02, Allen Watson Wrote:
>On or near 1/15/02 3:22 PM, Barry Wainwright at [EMAIL PROTECTED] observed:
>
>>  I wrote a little script that put these dates as near right as could
>>  be expected:
>>
>>  tell application "Eudora"
>>   set AppleScript's text item delimiters to {";"}
>>   try
>>     set field "Date" of message 0 to last text item of item 1 of (get
>>  field "received" of message 0)
>>   end try
>>  end tell
>>
>>  As you can see, it was written for Eudora, but it should be easy
>>  enough to modify it for Entourage.
>>
>I think what you are doing there, if I can guess correctly, is 
>setting the "time sent" to the "time received" of the message. 
>Right? That could be way off if a person isn't picking up mail 
>frequently--say dialing in every day or two.

Not quite, I'm setting it to the date/time of the first 'Received' 
header - which is set as it passes through the transport system. this 
will, for most people, be when it was received by their ISP and would 
normally be only a few minutes after the message was sent.

I just realised as I typed this, I'd be better setting it to the 
date/time of the LAST Received header, which would be the one set 
when the first MTA accepted the message - more likely to be closer to 
the time of writing/sending than the first received header, which 
could be the recipients own mail server if they are running one and 
could be a long way off the time.

>
>I wrote a script for Entourage to do this a bit more carefully (also 
>resetting the text item delimiters properly, which any script should 
>do, Barry--tsk, tsk!).

this is a philosophical discussion :)

I am used to writing in Smile, which declares that it will leave the 
TIDs in an indeterminate state, so I get used to NOT relying on them 
to contain any specific value, but setting them before use and 
forgetting about them afterwards. this is what I do for my own use. 
Usually, I clean this up on any scripts I publish, but this was more 
of a tip on the way to do it than a finished script (besides, I was 
in a hurry <g>)

>My script scans the message headers for the first or oldest 
>Received: header, which represents the time the user's ISP received 
>the message from him or her--which is usually much closer to the 
>time sent.

Snap :)

>However, that time is expressed in a format that AppleScript does 
>not understand, and with a GMT offset so it is the sender's local 
>time. Accordingly, my script reformats it in an AppleScript date 
>format, adjusts it back to GMT and then to the receiver's local time.

This was not necessary for Eudora, since it can understand the header 
format just fine. I see that Entourage requires a class date.

>A bit more complex...but still fast.
>
>--Script "Fix Time Sent"
>tell application "Microsoft Entourage"
>     activate
>     set theMsg to item 1 of (get current messages)
>     --Locate the first received header
>     set oldDelims to AppleScript's text item delimiters
>     set hdrs to the headers of theMsg
>     set hdrs to every paragraph of hdrs
>     (* For some reason, received headers sometimes break into two lines, so
>     I have to check the following line to see if it starts with a 
>word followed by
>     a colon; if not, it is a continuation of the previous header and 
>needs to be appended
>     to it. *)

A continuation line is one that starts with a whitespace character 
according to the rfc. So, all you need to do is replace all 
cr/whitespace pairs with just the whitespace before carrying out your 
search. Then all the headers will be in one paragraph each.

>     repeat with i from 1 to (count hdrs)
>         set aHdr to item i of hdrs
>         if aHdr starts with "Received:" then
>             set receivedHdr to aHdr
>             try
>                 set testWord to word 1 of item (i + 1) of hdrs
>                 if testWord does not end with ":" then set 
>receivedHdr to receivedHdr & item (i + 1) of hdrs
>             end try
>         end if
>         -- The one we want is the last received header, so keep looping
>     end repeat
>     --Now isolate the date/time stamp
>     set AppleScript's text item delimiters to {";"}
>     try
>         set x to last text item of receivedHdr
>     on error theErr number theNum
>         display dialog "Err#:" & theNum & " " & theErr
>     end try
>     set AppleScript's text item delimiters to oldDelims
>     set GMToffset to last word of x

Oops. many received header date stamps are formatted like this : " 
Wed, 16 Jan 2002 19:22:21 +0000 (GMT)" or this  "Wed, 16 Jan 2002 
11:23:18 -0800 (PST)" - in this case, your 'last word' will get "GMT" 
or "PST" (without the parentheses as well!)

>     set sign to character -5 of x
>     set dateStamp to text 1 thru (-((length of GMToffset) + 2)) of x

now this next bit...

>     --Now reformat the damned date stamp to something Applescript 
>can understand
>     set oldDelims to AppleScript's text item delimiters
>     set AppleScript's text item delimiters to {" "}
>     set dateParts to text items of dateStamp
>     set AppleScript's text item delimiters to oldDelims
>     set dd to item 3 of dateParts
>     set mm to item 4 of dateParts
>     set yy to item 5 of dateParts
>     set hhmmss to item 6 of dateParts
>     set mm to (offset of mm in 
>"JanFebMarAprMayJunJulAugSepOctNovDec") div 3 + 1
>     set dateStamp to "" & mm & "/" & dd & "/" & yy & ":" & hhmmss

can be done by saying "Date x" - it will format all it can understand 
and ignore the GMT offset at the end. For some reason, 'x as date' 
doesn't work???

set x to "Wed, 16 Jan 2002 11:23:18 -0800 (PST)"
date x
   --  date "Wednesday, January 16, 2002 11:23:18 am"

>     -- Adjust user's time to GMT, then local time
>     set GMToffset to ((sign & text 1 thru 2 of GMToffset) as number) 
>* 3600 -- Number of seconds offset    
>     tell me to set dateStamp to (date dateStamp)
>     set dateStamp to dateStamp - GMToffset + (time to GMT) -- 
>Subtract sender's time, add receiver's
>     set time sent of theMsg to dateStamp
>end tell
>

-- 
=Barry Wainwright=
<http://www.barryw.net>

-- 
To unsubscribe:                     
<mailto:[EMAIL PROTECTED]>
archives:       
<http://www.mail-archive.com/entourage-talk%40lists.letterrip.com/>
old-archive:       
<http://www.mail-archive.com/entourage-talk%40lists.boingo.com/>

Reply via email to