Re: Searching a Mail message
Re: Searching a Mail message
- Subject: Re: Searching a Mail message
- From: "Stockly, Ed" <email@hidden>
- Date: Tue, 05 Jun 2007 17:31:34 -0700
- Thread-topic: Searching a Mail message
Title: Re: Searching a Mail message
>>> Now as another hw, I'll ask people to remove the \", ), (, etc. from each email.
Picking up on a long dead thread, here's a version that grabs correctly formatted emails from a chunk of text. (In this case it's a BBEdit document but that could easily be changed to mail, which I don't use)
A few caveats, there may be a few more legitimate domain names, and they could be added to that property.
Also, I'm just guessing as to which characters are not allowed in a valid email address, so those variables may need to be adjusted as well.
HTH,
ES
-------------
property validDomains : {"com", "org", "net", "biz", "info", "name", "aero", "biz", "info", "jobs", "museum", "name"}
property invalidText : {tab, return, "\"", "\\", "<", ">", "(", ")", "{", "}"}
property illegalCharacters : {"/", "?", ".."}
tell application "BBEdit"
set myText to text of window 1
end tell
repeat with thisChar in invalidText
set myText to ReplaceText(thisChar, space, myText)
end repeat
set AppleScript's text item delimiters to "@"
set myText to every text item of myText
set x to 0
set atSize to count of myText
set validAddresses to {}
set invalidCharInAddress to false
repeat
repeat 1 times
set AppleScript's text item delimiters to " "
set x to x + 1
set y to x + 1
if y > atSize then exit repeat
set preText to the last text item of item x of myText
set postText to the first text item of item y of myText
if return is in preText then
set AppleScript's text item delimiters to return
set preText to the last text item of preText
end if
if return is in postText then
set AppleScript's text item delimiters to return
set postText to the last text item of postText
end if
if preText = " " or postText = " " then exit repeat
if preText = "" or postText = "" then exit repeat
set AppleScript's text item delimiters to "."
set domainName to the last text item of postText
if domainName is not in validDomains then
if the (count of domainName) is not 2 then exit repeat
end if
set AppleScript's text item delimiters to "@"
set thisAddress to {preText, postText} as string
if (thisAddress as string) is in validAddresses then exit repeat
repeat with thisChar in illegalCharacters
if thisChar is in thisAddress then
set invalidCharInAddress to true
exit repeat
end if
end repeat
if not invalidCharInAddress then
try
display dialog thisAddress
set the end of validAddresses to thisAddress as string
end try
end if
end repeat
if y > atSize then exit repeat
end repeat
set AppleScript's text item delimiters to return
set myText to validAddresses as string
tell application "BBEdit"
make new window
activate
set text of window 1 to myText
end tell
on ReplaceText(findString, replaceString, textToFix)
set fixCount to 1
local fixCount
repeat until fixCount = 0
set AppleScript's text item delimiters to {findString}
set textToFix to every text item of textToFix
set fixCount to the ((count of textToFix) - 1)
set AppleScript's text item delimiters to {replaceString}
set textToFix to textToFix as Unicode text
end repeat
return textToFix
end ReplaceText
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden