Mail.app AppleScript:将所有邮件复制(复制)到另一个帐户

时间:2015-02-12 06:45:10

标签: applescript osx-yosemite

我正在尝试为Yosemite Mail.app创建一个AppleScript,它可以制作邮件的副本(而不是档案)。

假设我有3个帐户:

  • Master(IMAP)
  • 目标1(IMAP)
  • 目标2(交换)

我想选择主收件箱中的所有邮件 - 并将这些邮件复制(也称为重复)到另外两个帐户(目标1和目标2)的收件箱中。最后,将有三个收件箱,所有收件箱都包含同一组消息 - 再次复制(不是档案)。

我尝试过这样的事情:

set mailboxMaster to "Master"
set mailboxTargets to {"Target 1", "Target 2"}

repeat with curMailboxTarget in mailboxTargets
tell application "Mail"
    duplicate every message in mailbox "Master" to mailbox curMailboxTarget
end tell
end repeat

但我得到“Mail收到错误:无法设置邮箱”

想法?

1 个答案:

答案 0 :(得分:1)

这样的事情会奏效,尼尔。 wink wink

它会将邮件从主帐户/邮箱复制到目标列表中的每个帐户/邮箱对。

property masterAccount : "MySourceAccountName"
property mailboxMaster : "INBOX"

property targetAccounts : {"IMAPAccountName", "ExchangeName"}
property mailboxTargets : {"INBOX", "Inbox"}

-- set the source mailbox and account
tell application "Mail"
    set sourceBox to mailbox mailboxMaster of account masterAccount
    set theCount to count of messages of sourceBox
    set theCount to 3 -- to run a test with a limited number

end tell
if theCount < 0 then error "No messages in the source mailbox."

-- set progress indicator
set progress total steps to theCount

-- iterate for each account name in targetAccounts
repeat with a from 1 to (count targetAccounts)
    set acctName to item a of targetAccounts
    set boxName to item a of mailboxTargets

    -- set destination mailbox for this target account
    tell application "Mail" to set destinationBox to mailbox boxName of account acctName

    -- process each message
    repeat with n from 1 to theCount
        -- iterate the progress indicator
        set progress description to "Copying Message " & n & " of " & theCount

        -- duplicate the message
        tell application "Mail" to duplicate (message n of sourceBox) to destinationBox

        -- terminate the progress indicator
        set progress completed steps to n
    end repeat
end repeat