我正在运行一个applescript,以从我老板收件箱中的所有邮件中提取所有电子邮件地址,它在他的计算机上冻结并且在我的计算机上运行良好。
我的电脑正在运行带有邮件 4.6 的雪豹,而他的正在运行带有邮件 5.3 的 Lion,如果这有什么不同的话。
此外,我的收件箱只有大约 400 封邮件,因为我通常不使用邮件并且只收到这些邮件来测试脚本,而他的邮件超过 60 000 封。
脚本在大约 20 秒内浏览了我的电子邮件,而在他的邮件中花了 2 分钟完成 40 次,然后冻结了。
我想知道代码是否有任何问题可能导致它在他的更高版本中冻结或由于电子邮件的增加。
另一方面,我知道一个一个地写它们可能会适得其反,因为我改编的脚本是在将它们写入文件之前对地址进行排序并删除重复项,但我认为由于它的邮件数量很大将加快进程并使用更少的内存来编写它们。加上计数器有助于了解脚本的位置。
这是代码:
tell application "Finder" to set ptd to path to documents folder as string
set theFile to ptd & "extracted3.txt"
set theFileID to open for access theFile with write permission
set counter to 0
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))
repeat with eachMessage in theseMessages
try
set counter to counter + 1
set theFrom to (extract address from sender of eachMessage)
set theFromName to (extract name from sender of eachMessage)
set theFromTemp to theFrom & "," & theFromName & "," & counter
write theFromTemp & return to theFileID as «class utf8»
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
set theToName to (name of to recipient i) of eachMessage as string
set theToTemp to theTo & "," & theToName & "," & counter
write theToTemp & return to theFileID as «class utf8»
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
set theCCName to (name of cc recipient i) of eachMessage as string
set theCCTemp to theCC & "," & theCCName & "," & counter
write theCCTemp & return to theFileID as «class utf8»
end repeat
end if
end try
end repeat
end tell
close access theFileID