获取对Outlook邮件副本的引用

时间:2013-09-13 14:51:28

标签: outlook applescript

此代码会将Microsoft Outlook message复制到drafts文件夹:

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

3 个答案:

答案 0 :(得分: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

答案 1 :(得分: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字典查找具有给定类别的邮件会更容易,但却必须采用聚光灯搜索。我确信有更好的方法可以做到这一点。

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

答案 2 :(得分: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
相关问题