AppleScript的邮件,从邮件中提取冻结的时候 [英] Applescript freezes when extracting email from mail

查看:216
本文介绍了AppleScript的邮件,从邮件中提取冻结的时候的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我运行一个AppleScript从我的老板的收件箱中的所有邮件提取所有的电子邮件地址,并冻结了他的电脑上和我的正常工作。

我的计算机运行雪豹与邮件4.6,他的运行狮子邮件5.3,如果有什么差别。

此外我的收件箱只有400左右的邮件,因为我不经常使用邮件和只得到了这些消息,以测试脚本,他拥有超过60万人。

该脚本通过我的电子邮件在20秒左右跑过去对他花了2分钟做40然后僵住了。

我在想,如果有什么不对的code,可能导致它在他的更高的版本或由于电子邮件present增加冻结。

在另一方面我知道,写他们都一一可能是适得其反,因为我适应了这个从正在整理中不会忽略,并将其写入文件之前删除重复,但剧本我认为,由于大量的邮件,它会加快这一进程,并使用更少的内存只写他们。加上计数器有助于了解那里的脚本是。

这里是code:

 告诉应用程序发现者来设置西门子输配电集团为路径的文件的文件夹弦
    设置theFile以PTD&安培; extracted3.txt
    设置theFileID以打开具有写权限访问theFile计数器设置为0告诉应用程序邮件
    设置selectionMessage来选择 - 只选择文件夹中的第一条消息
    thisMessage设置为selectionMessage第1项
    设置theseMessages为(每封邮件中(thisMessage邮箱))
    与eachMessage重复theseMessages
        尝试
            设置专柜反击+ 1
            (从eachMessage的发件人地址提取物)中设置theFrom为
            设置theFromName(从eachMessage的发件人名字提取物)
            设置theFromTemp为theFrom&安培; 与& theFromName&安培; 与&计数器
            写theFromTemp&安培;回到theFileID为«类UTF8»
            如果eachMessage的(到收件人地址)不是{}然后
                与我重复1至数与eachMessage收件人
                    设置theTo为eachMessage的(到收件人的i地址)字符串
                    设置theToName为(名称到收件人一)eachMessage作为字符串
                    设置theToTemp为theTo&安培; 与& theToName&安培; 与&计数器
                    写theToTemp&安培;回到theFileID为«类UTF8»
                重复结束
            万一
            如果eachMessage的(CC收件人地址)不是{}然后
                与我再说一遍,从1数eachMessage的抄送收件人
                    设置theCC为eachMessage的(CC收件人我的地址)字符串
                    设置theCCName为eachMessage作为字符串(CC收件人我的名字)
                    设置theCCTemp为theCC&安培; 与& theCCName&安培; 与&计数器
                    写theCCTemp&安培;回到theFileID为«类UTF8»
                重复结束
            万一
        年底试
    重复结束
告诉结束紧邻theFileID


解决方案

修改:进一步的思考之后,我删除我发布的第一个脚本。我的想法是,你所看到的问题是,因为你越来越60,000+一次电子邮件在此行中...

 设置theseMessages到(每封邮件中(thisMessage邮箱))

这样的想法是在一个时间只得到了一堆。我使用变量writeEveryXMessages指定您应该同时获得500的消息,并在每个循环中,我们得到下一个500直到完成。

请注意:我修改了code是一个小更高效,修正了一些可能的错误,例如写命令不再code的邮件告诉块。此外,它现在那些写500条消息在同一时间到文件。这个脚本在山狮和邮件V6.2。它应该为你工作了。

我希望这个解决您的问题!祝你好运。

 设置为theFile(路径,文件夹文本)及extracted3.txt
集writeEveryXMessages 500
计数器设置为1尝试
    设置theFileID来打开访问文件theFile具有写权限    告诉应用程序邮件
        设置selectedMessage为第1项(获取选择)
        设置theMailbox为selectedMessage邮箱
        设置messageCount算在theMailbox消息
    告诉结束    重复
        设置endCount反击+ writeEveryXMessages
        如果endCount大于messageCount然后设置为endCount messageCount
        设置theString为        告诉应用程序邮件
            集theseMessages邮件反击直通theMailbox的endCount
        告诉结束        与eachMessage重复theseMessages
            设置theFromTemp为
            设置theToTemp为
            设置theCCTemp为            尝试
                告诉应用程序邮件
                    告诉eachMessage
                        设置theSender发件人
                        设置toRecipients向收件人
                        设置ccRecipients为抄送收件人
                    告诉结束                    集theFrom从theSender提取地址
                    集theFromName从theSender提取名
                    设置theFromTemp为来源:&放大器; theFrom&安培; 与& theFromName&安培; 与&吧台和放大器;返回                    如果toRecipients不是{}然后
                        与toRecipient重复toRecipients
                            尝试
                                设置theTo为toRecipient地址
                                设置theToName为toRecipient的名字
                                设置theToTemp为theToTemp&安培; 为:&放大器; theTo&安培; 与& theToName&安培; 与&吧台和放大器;返回
                            年底试
                        重复结束
                    万一                    如果ccRecipients不是{}然后
                        在ccRecipients ccRecipient重复
                            尝试
                                设置theCC为ccRecipient地址
                                设置theCCName为ccRecipient的名字
                                设置theCCTemp为theCCTemp&安培; CC:&放大器; theCC&安培; 与& theCCName&安培; 与&吧台和放大器;返回
                            年底试
                        重复结束
                    万一
                告诉结束                设置theString为theString&安培; theFromTemp&安培; theToTemp&安培; theCCTemp&安培;返回
            年底试            设置专柜反击+ 1
        重复结束        写theString到theFileID为«类UTF8»
        如果计数器大于或等于messageCount然后
            设置theString为
            退出重复
        万一
    重复结束    紧邻theFileID
在错误theError
    登录theError
    尝试
        关闭访问文件theFile
    年底试
年底试

I'm running an applescript to extract all the email adress from all the messages in my boss's inbox and it freezes on his computer and works fine on mine.

my computer is running Snow leopard with mail 4.6 and his is running Lion with mail 5.3 if that makes any difference.

Also my inbox only has around 400 mails since i don't usually use mail and only got those messages to test the script and his has over 60 000.

The script ran through my email in around 20 seconds and on his took 2 minutes to do 40 then froze.

I was wondering if there was anything wrong with the code that could cause it to freeze in his higher version or due to the increase in email present.

On another note i know that writing them all one by one is probably counter-productive because the script i adapted this from was sorting the adresses and removing duplicates before writing them to the file but i thought that due to the large number of mails that it would speed the process and use less memory to just write them. PLus the counters helps to know where the script is at.

here is the code :

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

解决方案

EDIT: after further thought, I removed the first script I posted. My thought is the problem you are seeing is because you are getting 60,000+ emails at once in this line...

set theseMessages to (every message in (mailbox of thisMessage))

So the idea is to just get a bunch at a time. I use the variable writeEveryXMessages to specify that you should get 500 messages at a time, and on each loop we get the next 500 until finished.

NOTE: I modified your code to be a little more efficient and fixed a few possible bugs, for example the write command is no longer in the Mail tell block of code. Also it now writes those 500 messages to file at one time. This script works on Mountain Lion and Mail v6.2. It should work for you too.

I hope this fixes your problem! Good luck.

set theFile to (path to documents folder as text) & "extracted3.txt"
set writeEveryXMessages to 500
set counter to 1

try
    set theFileID to open for access file theFile with write permission

    tell application "Mail"
        set selectedMessage to item 1 of (get selection)
        set theMailbox to mailbox of selectedMessage
        set messageCount to count of messages in theMailbox
    end tell

    repeat
        set endCount to counter + writeEveryXMessages
        if endCount is greater than messageCount then set endCount to messageCount
        set theString to ""

        tell application "Mail"
            set theseMessages to messages counter thru endCount of theMailbox
        end tell

        repeat with eachMessage in theseMessages
            set theFromTemp to ""
            set theToTemp to ""
            set theCCTemp to ""

            try
                tell application "Mail"
                    tell eachMessage
                        set theSender to sender
                        set toRecipients to to recipients
                        set ccRecipients to cc recipients
                    end tell

                    set theFrom to extract address from theSender
                    set theFromName to extract name from theSender
                    set theFromTemp to "From: " & theFrom & "," & theFromName & "," & counter & return

                    if toRecipients is not {} then
                        repeat with toRecipient in toRecipients
                            try
                                set theTo to address of toRecipient
                                set theToName to name of toRecipient
                                set theToTemp to theToTemp & "  To: " & theTo & "," & theToName & "," & counter & return
                            end try
                        end repeat
                    end if

                    if ccRecipients is not {} then
                        repeat with ccRecipient in ccRecipients
                            try
                                set theCC to address of ccRecipient
                                set theCCName to name of ccRecipient
                                set theCCTemp to theCCTemp & "  CC: " & theCC & "," & theCCName & "," & counter & return
                            end try
                        end repeat
                    end if
                end tell

                set theString to theString & theFromTemp & theToTemp & theCCTemp & return
            end try

            set counter to counter + 1
        end repeat

        write theString to theFileID as «class utf8»
        if counter is greater than or equal to messageCount then
            set theString to ""
            exit repeat
        end if
    end repeat

    close access theFileID
on error theError
    log theError
    try
        close access file theFile
    end try
end try

这篇关于AppleScript的邮件,从邮件中提取冻结的时候的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆