Title: Re: Complicated script
On or near 9/20/01 9:58 PM, David Leitch at [EMAIL PROTECTED] observed:
> However I am still getting errors from internal JPMorgan lotus notes
> addresses of the form:
>
> Peter C
> Talbot To: Brian D
> Johnson/JPMCHASE@CHASE
>
> This a message from Peter Talbot. The script is returning the error message
> :Could not parse sender's address.
>
> The reason the script is doing this is because the addressor is sending from
> our local Sydney Office and the Notes form generating the sender doesn't
> include an @ in the sender address under such circumstances.
Try this version of the script. By the way, if you send scripts in Entourage, create the message as text, insert the script, and then change the message to HTML (click on the colored ab>ab button at the upper left of the message pane, next to the font name). This will preserve the proper line endings in the script when it is sent.
I modified the script so that if no “@” is found in the address, it will attempt to make a “JPMorgan.com” address out of it, display a message showing what the address is, and ask you want to accept it as is, edit it, or cancel. The format, given your example, should be:
“Peter C Talbot <[EMAIL PROTECTED]>”
The first part is used as the display name, the part between angle brackets as the email address. I did not test my code; I’ll leave that to you. Let me know if it does not work right.
The query will default to “Accept” and will take that path after 15 seconds if no one replies to the message. If you select edit, it will display the address text in a box and allow you to modify it as you wish. This is a quick fix to your problem, and not the final solution, which would check more carefully for valid input. All I am testing for here is the presence or absence of the at-sign; there could be many circumstances where something else results in an improper address, and requires manual intervention. The way I’ve done it, you can intervene if necessary.
If you want to change the time delay on the message from 15 seconds to something else, just edit the “giving up after 15” to the number of seconds you want.
tell application "Microsoft Entourage"
set theMsg to item 1 of (get current messages)
if address of sender of theMsg is "[EMAIL PROTECTED]" then
set theContent to content of theMsg
-- Remove leading blanks
-- Collapse space runs to single space
set paras to paragraphs of theContent
set newstuff to ""
repeat with aLine in paras
repeat while aLine begins with " "
if aLine is not " " then
set aLine to text 2 thru -1 of aLine
else
set aLine to ""
end if
end repeat
repeat while aLine contains " "
set aLine to my myReplace(" ", " ", aLine)
end repeat
if length of aLine > 0 then set newstuff to newstuff & aLine & return
end repeat
if ((words 1 thru 3 of newstuff) as text) contains "attachment" then
set newstuff to my myAfter(")", newstuff) -- Discard the attachment info
end if
set trialAddress to word 1 of newstuff
if trialAddress contains "@" then
set finalAddress to trialAddress -- We are done
return finalAddress
else
set trialAddress to my myBefore("To:", newstuff)
set trialAddress to my myReplace(return, "", trialAddress)
if trialAddress does not contain "@" then
set part2 to my myBetween("<", ">", newstuff)
set part2 to "<" & my myBefore(" ", part2) & my myAfter(return, part2) & ">"
set trialAddress to trialAddress & " " & part2
end if
set finalAddress to trialAddress
end if
set nameLine to finalAddress
if nameLine does not contain "@" then
set nameLine to nameLine & " <" & (my myReplace(" ", ".", nameLine) & "@JPMorgan.com") & ">"
display dialog "Unclear address, trying: " & nameLine buttons {"Cancel", "Edit", "Accept"} default button "Accept" giving up after 15
set btn to button returned of result
if btn = "Cancel" then
return
else if btn = "Edit" then
set nameLine to text returned of (display dialog "Edit as desired" default answer nameLine)
else
if nameLine does not contain " " then
set dName to ""
set eAddress to nameLine
else
set dName to my myBefore("<", nameLine)
set eAddress to my myBetween("<", ">", nameLine)
end if
set AppleScript's text item delimiters to {""}
set display name of sender of theMsg to dName
set address of sender of theMsg to eAddress
--exit repeat
end if
end if
end if
end tell
on myReplace(oldS, newS, theText)
set od to AppleScript's text item delimiters
set AppleScript's text item delimiters to oldS
set temp to text items of theText
set AppleScript's text item delimiters to newS
set theText to temp as text
return theText
end myReplace
to myBetween(firstPart, secondPart, someString)
set lastpart to myAfter(firstPart, someString) -- What follows firstPart
set midpart to myBefore(secondPart, lastpart)
return midpart
end myBetween
to myBefore(subStr, mainStr)
set od to AppleScript's text item delimiters
set AppleScript's text item delimiters to subStr
set temp to text items of mainStr
set theBefore to item 1 of temp
set theRest to (the rest of temp) as text
set AppleScript's text item delimiters to od
return theBefore
end myBefore
to myAfter(subStr, mainStr)
set od to AppleScript's text item delimiters
set AppleScript's text item delimiters to subStr
set temp to text items of mainStr
set theRest to item 1 of temp
set theAfter to (the rest of temp) as text
set AppleScript's text item delimiters to od
return theAfter
end myAfter
--
Add me to Palm/Visor: http://signature.coola.com/?[EMAIL PROTECTED]
Allen Watson <[EMAIL PROTECTED]> XNS name: =Allen Watson
A Mac family since 1984 <http://home.earthlink.net/~allenwatson/>
Applescripts for Outlook Express and Entourage: <http://homepage.mac.com/allenwatson/>
- Complicated script David Leitch
- Re: Complicated script Allen Watson
- Re: Complicated script David Leitch
- Re: Complicated script Allen Watson
- Re: Complicated script David Leitch
- Re: Complicated script David Leitch
- Re: Complicated script Allen Watson
- Re: Complicated script David Leitch
