1

此代码会将 Microsoft Outlook 复制messagedrafts文件夹:

tell application "Microsoft Outlook"

  ...

  -- find the template give an ID
  set theTemplate to message id theID

  -- duplicate the message  
  duplicate theTemplate to drafts

  ...

end tell

我需要对副本的引用以进行额外处理。

不幸的是,这不起作用:

...

-- this will create a duplicate
set theDuplicate to (duplicate theTemplate to drafts)

-- produces an error that reads "The variable theDuplicate is not defined."
display dialog (subject of theDuplicate) & " [" & (id of theDuplicate) & "]"

如何获得对刚刚复制的消息的引用?它的 ID 将是一个令人满意的选择。

4

3 回答 3

1

我想重复方法在这方面非常有限。我也尝试了更通用的复制方法 - 复制了消息,但再次没有返回 ID。

这是另一种没有重复循环的可能方法:

  • 创建一个新的临时类别
  • 使用新类别标记原始消息
  • 重复 - 重复的消息也将标有类别
  • 搜索标有临时类别的消息 - 你应该只得到两个 - 原始和重复
  • 删除临时类别

这是代码(相当未完成):

tell application "Microsoft Outlook"
    try
        set tempCategory to category "Temporary Category"
    on error number -1728
        set tempCategory to (make new category with properties {name:"Temporary Category"})
    end try

    set messageList to selected objects
    set origMsg to item 1 of messageList
    display dialog "Original Message ID: " & id of origMsg

    set msgCat to category of origMsg
    set end of msgCat to tempCategory
    set category of origMsg to msgCat

    duplicate origMsg to drafts
    delay 1 -- sigh, it seems to take a bit of time before the category markings are reflected in the spotlight DB

    --set msgList to messages whose category contains tempCategory
    set currentIdentityFolder to quoted form of POSIX path of (current identity folder as string)
    set tempCatMsgs to words of (do shell script "mdfind -onlyin " & currentIdentityFolder & " 'com_microsoft_outlook_categories == " & id of tempCategory & "' | xargs -I % mdls -name com_microsoft_outlook_recordID '%' | cut -d'=' -f2 | sort -u | paste -s -")

    if item 1 of tempCatMsgs is (id of origMsg) as text then
        set dupMsgId to item 2 of tempCatMsgs
    else
        set dupMsgId to item 1 of tempCatMsgs
    end if

    delete tempCategory

    display dialog "Original Message ID: " & id of origMsg & return & "Duplicate Message ID: " & dupMsgId
end tell

我认为使用 OL 词典查找具有给定类别的消息会更容易,但不得不求助于聚光灯搜索。我确信有更好的方法来做到这一点。

向消息添加类别也比我更难 - 我再次确信这可以更有效地完成。

于 2013-09-13T23:03:22.797 回答
1

必须有更好的方法,但是...

--For Testing
set theID to 39110

tell application "Microsoft Outlook"    
    set oldIds to my getDraftIds()

    -- find the template give an ID
    set theTemplate to message id theID

    --duplicate the message  
    duplicate theTemplate to drafts

    set newIds to my getDraftIds()
    set duplicatedMessage to message id (my findNewID(oldIds, newIds))
end tell


on getDraftIds()
    set messageIDs to {}
    tell application "Microsoft Outlook"
        set draftFolders to (every folder whose name = "Drafts")
        repeat with dFolder in draftFolders
            set messageIDs to messageIDs & id of dFolder's messages
        end repeat
    end tell
end getDraftIds

on findNewID(oldList, newList)
    repeat with mID in newList
        if mID is not in oldList then return mID
    end repeat
end findNewID
于 2013-09-13T17:12:37.703 回答
0
-- create a temporary folder to hold duplicates
on createFolder(theName)

  tell application "Microsoft Outlook"
    set theFolder to make new mail folder with properties {name:theName}
  end tell

end createFolder

-- find folder by name
on findFolder(theName)

  tell application "Microsoft Outlook"
    set theFolder to make new mail folder with properties {name:theName}
  end tell

end findFolder

-- duplicate the message and get a reference
on duplicateIt(theID)

  set theDestination to findFolder("foo bar")

  tell application "Microsoft Outlook"

    --find the template
    set theTemplate to message id theID

    -- duplicate it to the temporary location
    (duplicate theTemplate to theDestination)

    -- get the first item in the folder
    set theDuplicate to item 1 of theDestination

    -- do something with it
    ...

  end tell

end duplicateIt
于 2013-09-17T19:17:34.173 回答