Removing quotation marks from email addresses in entourage

Greetings, I hope that you can help. I"ve recently moved to a mac, very pleased over all. I moved my contacts into entourage and many of my email addresses now have quotation marks around them. When I send emails I get syntax errors. I found a script that removed the quotation marks from 1st name and last name, but it wouldn’t remove the quotation marks from the email addresses themselves. I would like to be able to do that and then most of my email addresses would work rather than me having to change them manually.

here is the script from tech archive.net that worked to remove the quotation marks from 1st and last name…

– begin script
on run
tell application “Microsoft Entourage”
set contactList to the contacts
repeat with nextContact in contactList
my RemoveQuotesFromContact(nextContact)
end repeat
end tell
end run

on RemoveQuotesFromContact(someContact)
tell application “Microsoft Entourage”
tell someContact
– remove double quotes
set first name to my SearchReplace(first name, “"”, “”)
set last name to my SearchReplace(last name, “"”, “”)
set title to my SearchReplace(title, “"”, “”)
set nickname to my SearchReplace(nickname, “"”, “”)
set e-mail address to my SearchReplace(e-mail address, “"”,“”)
– remove single quotes
set first name to my SearchReplace(first name, “'”, “”)
set last name to my SearchReplace(last name, “'”, “”)
set title to my SearchReplace(title, “'”, “”)
set nickname to my SearchReplace(nickname, “'”, “”)
end tell
end tell
end RemoveQuotesFromContact

on SearchReplace(sourceStr, searchString, replaceString)
– replace with in
set searchStr to (searchString as text)
set replaceStr to (replaceString as text)
set sourceStr to (sourceStr as text)
set saveDelims to AppleScript’s text item delimiters
set AppleScript’s text item delimiters to (searchString)
set theList to (every text item of sourceStr)
set AppleScript’s text item delimiters to (replaceString)
set theString to theList as string
set AppleScript’s text item delimiters to saveDelims
return theString
end SearchReplace
– end script

Any help you could provide would be great.

thanks

Brian

The thing is, contacts contains email addresses, and there might be more than one. Here is a modified version that might work (untested, don’t want to damage my entourage db):

on run
	tell application "Microsoft Entourage"
		set contactList to the contacts
		repeat with nextContact in contactList
			my RemoveQuotesFromContact(nextContact)
		end repeat
	end tell
end run

on RemoveQuotesFromContact(someContact)
	tell application "Microsoft Entourage"
		set allEmailAddresses to every email address of someContact
		tell someContact
			-- remove double quotes
			set first name to my SearchReplace(first name, "\"", "")
			set last name to my SearchReplace(last name, "\"", "")
			set title to my SearchReplace(title, "\"", "")
			set nickname to my SearchReplace(nickname, "\"", "")
			repeat with thisContactEmail in allEmailAddresses
				set thisContactEmail to (my SearchReplace(thisContactEmail, "\"", ""))
			end repeat
			-- remove single quotes
			set first name to my SearchReplace(first name, "'", "")
			set last name to my SearchReplace(last name, "'", "")
			set title to my SearchReplace(title, "'", "")
			set nickname to my SearchReplace(nickname, "'", "")
		end tell
	end tell
end RemoveQuotesFromContact

on SearchReplace(sourceStr, searchString, replaceString)
	-- replace <searchString> with <replaceString> in <sourceStr>
	set searchStr to (searchString as text)
	set replaceStr to (replaceString as text)
	set sourceStr to (sourceStr as text)
	set saveDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to (searchString)
	set theList to (every text item of sourceStr)
	set AppleScript's text item delimiters to (replaceString)
	set theString to theList as string
	set AppleScript's text item delimiters to saveDelims
	return theString
end SearchReplace

Let me know how it goes…

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Thank you very much Leon. I tried it, but it didn’t seem to work. I don’t really know anything about scripting so I’m not sure what needs to be done to make it work. All of the quotation marks are very frustrating.

Thanks a lot

Brian

Was there an error message? Could you post it to see what happened exactly? Maybe of the variables need to be coerced to string or text. And I just noticed that email addresses contain a “contents” field… try this one and let me know if it helps:

on run
	tell application "Microsoft Entourage"
		set contactList to the contacts
		repeat with nextContact in contactList
			my RemoveQuotesFromContact(nextContact)
		end repeat
	end tell
end run

on RemoveQuotesFromContact(someContact)
	tell application "Microsoft Entourage"
		set allEmailAddresses to every email address of someContact
		tell someContact
			-- remove double quotes
			set first name to my SearchReplace(first name, "\"", "")
			set last name to my SearchReplace(last name, "\"", "")
			set title to my SearchReplace(title, "\"", "")
			set nickname to my SearchReplace(nickname, "\"", "")
			repeat with thisContactEmail in allEmailAddresses
				set contents of thisContactEmail to (my SearchReplace((contents of thisContactEmail) as string, "\"", ""))
			end repeat
			-- remove single quotes
			set first name to my SearchReplace(first name, "'", "")
			set last name to my SearchReplace(last name, "'", "")
			set title to my SearchReplace(title, "'", "")
			set nickname to my SearchReplace(nickname, "'", "")
		end tell
	end tell
end RemoveQuotesFromContact

on SearchReplace(sourceStr, searchString, replaceString)
	-- replace <searchString> with <replaceString> in <sourceStr>
	set searchStr to (searchString as text)
	set replaceStr to (replaceString as text)
	set sourceStr to (sourceStr as text)
	set saveDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to (searchString)
	set theList to (every text item of sourceStr)
	set AppleScript's text item delimiters to (replaceString)
	set theString to theList as string
	set AppleScript's text item delimiters to saveDelims
	return theString
end SearchReplace

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

There wasn’t an error message with the 1st one or the second one. Still no luck. i sure appreciate you trying.

Brian

Really? So the script executes fine, but there is no result, correct?

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Yes, that is correct. It takes about 3 minutes to execute. (both times actually)

Hmm. I’ll need to do some tests on my entourage, non-destructive ones at least!

Don’t worry, i’m sure this time and effort will be worth to someone at some point, so I don’t mind taking the time to test it. I’m sure the solution is easy… but without testing, it’s hard to tell what it is.

I’ll keep you posted.

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Ok, what about this one?

on run
	tell application "Microsoft Entourage"
		set contactList to the contacts
		repeat with nextContact in contactList
			my RemoveQuotesFromContact(nextContact)
		end repeat
	end tell
end run

on RemoveQuotesFromContact(someContact)
	tell application "Microsoft Entourage"
		set allEmailAddresses to every email address of someContact
		tell someContact
			-- remove double quotes
			set first name to my SearchReplace(first name, "\"", "")
			set last name to my SearchReplace(last name, "\"", "")
			set title to my SearchReplace(title, "\"", "")
			set nickname to my SearchReplace(nickname, "\"", "")
			repeat with thisContactEmail in allEmailAddresses
				--display dialog (first name & " " & last name & return & (contents of thisContactEmail)) as string
				--display dialog (my SearchReplace((contents of thisContactEmail) as string, "\"", ""))
				set newContactEmail to (my SearchReplace((contents of thisContactEmail) as string, "\"", "")) as string
				set contents of thisContactEmail to newContactEmail
			end repeat
			-- remove single quotes
			set first name to my SearchReplace(first name, "'", "")
			set last name to my SearchReplace(last name, "'", "")
			set title to my SearchReplace(title, "'", "")
			set nickname to my SearchReplace(nickname, "'", "")
		end tell
	end tell
end RemoveQuotesFromContact

on SearchReplace(sourceStr, searchString, replaceString)
	-- replace <searchString> with <replaceString> in <sourceStr>
	set searchStr to (searchString as text)
	set replaceStr to (replaceString as text)
	set sourceStr to (sourceStr as text)
	set saveDelims to AppleScript's text item delimiters
	set AppleScript's text item delimiters to (searchString)
	set theList to (every text item of sourceStr)
	set AppleScript's text item delimiters to (replaceString)
	set theString to theList as string
	set AppleScript's text item delimiters to saveDelims
	return theString
end SearchReplace

Don’t mind the display dialog, they were there for testing purposes. I tried it in “simulation mode” and tried to remove the @ from the email address, everything worked fine. So I did a bit of a workaround to make sure Entourage is not being too picky.

Let me know how this one does.

Oh! And also, remind me… only emails were not being processed correctly, right?

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Wow, the oddest thing happens on my Entourage. When I run the script, it doesnt remove the quotes, but after a while, it erases the email address. So I would reccommend you do not use this latest script. I’ll keep on looking!

Very odd…

Nope, tried a lot of things. No result. It just keeps deleting the email address completely, even if I confirmed that the quotes were indeed removed… very very strange. Strange as in “this should not be happening, but it still does!”.

I’ll have to pass this to someone else who may have an idea at what’s wrong. The last script posted here is a good start point. Also, I don’t want to cause irreperable damage to your contacts database.

Sorry!

Regards,
Fred

Browser: Safari 531.9
Operating System: Mac OS X (10.6)

Thanks so much Fred, I appreciate you working on it.

Brian

I ended up exporting my email addresses as csv files, cleaning them up and importing them again. it worked well.

thanks for your efforts.

Brian