Title: Re: What sets the "Sent" time of each email
On or near 1/18/02 12:03 PM, Allen Watson at [EMAIL PROTECTED] observed:

> Ah! again. Something I once knew but forgot, and when I tried "x as date"
> and it did not work, I just used the brute force method. Much better.

Here is my revised "Fix Sent Time" script, incorporating Barry's excellent suggestions.

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
    (* For some reason, received headers sometimes break into two lines, so
    I have to paste them together. Continuation lines start with a space. *)
    set hdrs to my searchReplace(hdrs, (return & " "), " ")
    set hdrs to every paragraph of hdrs
    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
        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
    tell me to set dateStamp to date x
    display dialog "Set sent time to " & date string of dateStamp & " " & time string of dateStamp ¬
        buttons {"No", "Set it"} default button 2
    if button returned of result is "No" then
        return
    else
        set time sent of theMsg to dateStamp
    end if
end tell

-- routine to do a search and replace on text
on searchReplace(mainString, searchString, replaceString) -- Parameters: search, replace, the String
    set olddelis to AppleScript's text item delimiters
    
    set AppleScript's text item delimiters to (searchString)
    set theList to (every text item of mainString)
    
    set AppleScript's text item delimiters to (replaceString)
    set theString to theList as string
    
    set AppleScript's text item delimiters to olddelis
    return theString
end searchReplace


--
Microsoft MVP for Entourage/OE/Word
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>

Reply via email to