Title: Re: Way to check for duplicate emails addresses in a message? [BEST, FIXED version 2 :-)]
On 1/28/01 9:02 PM, I wrote:
On 1/28/01 8:39 PM, "R. Scott Ohlgren" <[EMAIL PROTECTED]> wrote:
That’s it! Whatever you did to this modified script makes it work brilliantly.
Aha. I hadn't sent the fixed version to the list yet.
One more fix. Since it may be a day or two until I can write the ReadMe and post the finished script at AppleScript Central, I'm sending another fix below. The version below will not error if you have a group member who is not a contact in the Address Book, and will include him/her (with an @ sign) as a recipient in the message. The previous version would error.
**Incidentally, in trying to come up with a version for OE, I discovered another unheralded AppleScript fix in Entourage. Although you can put one single contact with a contact icon into a new message window, it won't work for lists of contacts: the names get enclosed in < > signs as if they were email addresses, so you end up with a ;lot of big green question marks and unusable addresses. For the OE version I have to use the @ icons, not contact icons. Thanks for the fix in Entourage, Dan.
Anyway, here's the (surely) final fixed version:
---------------------REMOVE DUPLICATE RECIPIENTS-----------------
global ods
tell application "Microsoft Entourage"
set theDraft to window 1
if class of theDraft � draft window then
beep
display dialog "You must have your new message window [not the Address Book, a Custom View, or anything else] in the front when you run the script." buttons {"OK"} default button "OK" with icon 0
return
end if
set {theTo, theCC, theBCC} to theDraft's {to recipients, CC recipients, BCC recipients}
set {ods, AppleScript's text item delimiters} to {AppleScript's text item delimiters, {", "}}
set {toList, ccList, bccList} to {text items of theTo, text items of theCC, text items of theBCC}
set AppleScript's text item delimiters to ods
set toList to my ResetRecipients(toList, {}, {})
set ccList to my ResetRecipients(ccList, toList, {})
set bccList to my ResetRecipients(bccList, ccList, toList)
set AppleScript's text item delimiters to {", "}
set {window 1's to recipients, window 1's CC recipients, window 1's BCC recipients} to {"" & toList, "" & ccList, "" & bccList}
set AppleScript's text item delimiters to ods
end tell
on ResetRecipients(theList, previousList, anteriorList)
tell application "Microsoft Entourage"
set newList to {}
if theList � {""} then
repeat with i from 1 to (count theList)
set aRecip to item i of theList
if aRecip does not contain "@" then -- must be group
set newList to my ProcessGroup(aRecip, theList, previousList, anteriorList, newList)
else -- it's a contact
set AppleScript's text item delimiters to {" <"}
try
set dName to text item 1 of aRecip
set eAddress to text 1 thru -2 of text item 2 of aRecip -- remove final ">"
set AppleScript's text item delimiters to ods
if (eAddress = default email address of contact dName) then
if ({dName} is not in newList) and ({dName} is not in previousList) and ({dName} is not in anteriorList) then set end of newList to dName -- will be contact icon
else --more than one contact with that name or not using default email address
if ({aRecip} is not in newList) and ({aRecip} is not in previousList) and ({aRecip} is not in anteriorList) then set end of newList to aRecip -- use @ format
end if
on error -- address only
set AppleScript's text item delimiters to ods
if ({aRecip} is not in newList) and ({aRecip} is not in previousList) and ({aRecip} is not in anteriorList) then set end of newList to aRecip -- address only, @ format
end try
end if
end repeat
else
set newList to {""}
end if
end tell
return newList
end ResetRecipients
to ProcessGroup(aRecip, theList, previousList, anteriorList, newList)
tell application "Microsoft Entourage"
try
set theGroup to group aRecip
on error -- if actually an artificial group member without email address
return newList --without adding this email-less contact to it
end try
set theEntries to content of every group entry of theGroup
repeat with j from 1 to (count theEntries)
set anEntry to item j of theEntries
repeat 1 times -- for doing next repeat after nested groups
try
set {dName, eAddress} to {display name, address} of anEntry
if eAddress = "" then
set newList to my ProcessGroup(dName, theList, previousList, anteriorList, newList) -- recursive
exit repeat -- the 1 times repeat, go on to next group entry
end if
if dName � "" then
if dName starts with "\"" then set dName to text 2 thru -2 of dName -- equivalent to display name without quotes
try
if eAddress = default email address of contact dName then -- will error if not a contact
if ({dName} is not in newList) and ({dName} is not in previousList) and ({dName} is not in anteriorList) then set end of newList to dName -- will have contact icon
else --more than one contact with that name or not using default email address
error number -128 --catch below
end if
on error -- or not a contact
set nameAddress to dName & " <" & eAddress & ">"
if ({nameAddress} is not in newList) and ({nameAddress} is not in previousList) and ({nameAddress} is not in anteriorList) then set end of newList to nameAddress -- use @ format
end try
else -- no display name, address only
if ({eAddress} is not in newList) and ({eAddress} is not in previousList) and ({eAddress} is not in anteriorList) then set end of newList to eAddress -- will have @ format
end if
on error
exit repeat -- the 1 times repeat, move on to next group entry
end try
end repeat -- the 1 times repeat
end repeat
end tell
return newList
end ProcessGroup
----------------END SCRIPT --------------------
--
Paul Berkowitz
- Re: Way to check for duplicate emai... Paul Berkowitz
- Re: Way to check for duplicate... Allen Watson
- Re: Way to check for dupli... Paul Berkowitz
- Re: Way to check for dupli... Allen Watson
- Re: Way to check for dupli... Christian M. M. Brady
- Re: Way to check for dupli... Paul Berkowitz
- Re: Way to check for duplicate emails addresses in a... R. Scott Ohlgren
- Re: Way to check for duplicate emails addresses in a... R. Scott Ohlgren
- Re: Way to check for duplicate emails addresses in a... R. Scott Ohlgren
- Re: Way to check for duplicate emails addresses... Paul Berkowitz
- Re: Way to check for duplicate emails addresses... Paul Berkowitz
- Re: Way to check for duplicate emails addre... Allen Watson
- Re: Way to check for duplicate emails a... Paul Berkowitz
