I found the following script to extract email addresses in the Apple discussion boards. Thanks to Tony T1. The script is great in that it extracts email addresses for all senders, recipients and cc recipients. It also removes all duplicates and sorts into a text file. This is exactly what I need with one exception. I need the names along with the email addresses.
Could someone please help me by adjusting this script so that the name and email address is listed on the same line in the text file.
Example:
John Smith jsmith@address.com
Mary Smith msmith@address.com
Any help will be greatly appreciated. I have a few thousand emails to go through and this script would be so helpful!
I also hope I used the proper format for sending this post.
Diane
tell application "Mail"
set selectionMessage to selection -- just select the first message in the folder
set thisMessage to item 1 of selectionMessage
set theseMessages to (every message in (mailbox of thisMessage))
set listOfEmails to {}
repeat with eachMessage in theseMessages
try
set theFrom to (extract address from sender of eachMessage)
if listOfEmails does not contain theFrom then
copy theFrom to the end of listOfEmails
end if
if (address of to recipient) of eachMessage is not {} then
repeat with i from 1 to count of to recipient of eachMessage
set theTo to (address of to recipient i) of eachMessage as string
if listOfEmails does not contain theTo then
copy theTo to the end of listOfEmails
end if
end repeat
end if
if (address of cc recipient) of eachMessage is not {} then
repeat with i from 1 to count of cc recipient of eachMessage
set theCC to (address of cc recipient i) of eachMessage as string
if listOfEmails does not contain theCC then
copy theCC to the end of listOfEmails
end if
end repeat
end if
end try
end repeat
end tell
tell application "Finder" to set ptd to path to documents folder as string
set theFile to ptd & "extracted.txt"
set theFileID to open for access theFile with write permission
set SortedListOfEmails to simple_sort(listOfEmails)
repeat with i from 1 to count of SortedListOfEmails
write item i of SortedListOfEmails & return to theFileID as «class utf8»
end repeat
close access theFileID
on simple_sort(my_list)
set the index_list to {}
set the sorted_list to {}
repeat (the number of items in my_list) times
set the low_item to ""
repeat with i from 1 to (number of items in my_list)
if i is not in the index_list then
set this_item to item i of my_list as text
if the low_item is "" then
set the low_item to this_item
set the low_item_index to i
else if this_item comes before the low_item then
set the low_item to this_item
set the low_item_index to i
end if
end if
end repeat
set the end of sorted_list to the low_item
set the end of the index_list to the low_item_index
end repeat
return the sorted_list
end simple_sort