Title: Re: Way to check for duplicate emails addresses in a message?
On 1/27/01 9:42 PM, I wrote:

>  I'm just about done. I can't quite decide whether it's worth the bother
> to show the recipients as contact icons instead of just @ recipients, but
> I suppose people like it.  
>
> Coming right up in a few moments.


OK. Here it is. You can drag contacts and/or groups (any combination) from custom view(s) and/or the Address Book to any or all of the recipient fields (To, Cc, Bcc) of a new message window. Then run the script to remove duplicates. It will show all contacts as contact icons, except for contacts without display names (i.e. only email addresses): they will be included but will display the email address with an @ icon. If you have dragged a group, it will show all non-duplicate individual group members now, not the group name. If the group members are contacts, it will show them as contact icons (except nameless ones, as above). If you have any group members who are not real contacts in the Address Book, they will be included, if not duplicates, with the @ icon.  Please let me know if you hit any problem. I'll also post this soon at AS Central after I hear back from you 'beta testers' here.



------------------------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 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
                    try
                        set theGroup to group aRecip
                        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
                            set {dName, eAddress} to {display name, address} of anEntry
                            if dName � "" then
                                if dName starts with "\"" then set dName to text 2 thru -2 of dName -- equivalent to display name without quotes
                                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 -- 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
                            
                        end repeat
                    end try
                else -- it's a contact
                    
                    set AppleScript's text item delimiters to {" <"}
                    try
                        set dName to text item 1 of aRecip
                        if dName starts with "\"" then set dName to text 2 thru -2 of dName -- equivalent to display name without quotes
                        set AppleScript's text item delimiters to ods
                        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
                    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 theList
        end if
    end tell
    return newList
    
end ResetRecipient


-------------------END SCRIPT------------------------------------


--
Paul Berkowitz

Reply via email to