Outlook 获取对Outook消息副本的引用

Outlook 获取对Outook消息副本的引用,outlook,applescript,Outlook,Applescript,此代码将Microsoft Outlook邮件复制到草稿文件夹: 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 我需要一份副本的参考资料,以便进一步

此代码将Microsoft Outlook
邮件
复制到
草稿
文件夹:

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将是一个令人满意的替代方案。

一定有更好的方法,但是

--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

我想复制方法在这方面相当有限。我也尝试了更通用的复制方法-消息被复制,但同样没有返回ID

这里有另一种不重复循环的方法:

  • 创建一个新的临时类别
  • 用新类别标记原始邮件
  • 重复-重复消息也将标记类别
  • 搜索标有临时类别的邮件-您应该只会得到两个-原始邮件和副本邮件
  • 删除临时类别
以下是代码(尚未完成):

我认为使用OL字典查找具有给定类别的邮件会更容易,但不得不求助于聚光灯搜索。我相信有更好的办法


另外,在邮件中添加一个类别比我想象的要难——我再次确信这可以更有效地完成

+1我正在考虑类似的方法。我认为没有一种方法可以执行
非IN
查询。另一种想法是:API支持可选的“[with properties record]”语句。也许我可以添加一个伪属性(不丢失所有原始属性),然后使用伪属性获取消息。想法?我喜欢这个想法,尽管我没有看到一个消息属性可以作为伪值的好占位符。在消息上设置一个临时类别来复制怎么样?看看我的答案。
-- 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
-- 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