从Cocoa中的Apple Mail获取已删除的邮件消息

时间:2013-02-08 03:08:48

标签: objective-c cocoa drag-and-drop

我用Google搜索并阅读了文档。在SO上搜索,找到了建议使用Applescript的答案,但由于沙箱,我不能使用Applescript。

我正在研究Cocoa应用程序(用Objective-C和沙盒编写)。我正在从Apple Mail应用程序实现拖放。应用程序应该像Finder一样接收或复制eml邮件消息。

我试着看NSPromisedFilesPboardType,但几乎无法弄清楚我应该如何使用它。我在- (BOOL)acceptDrop:(id<NSDraggingInfo>)info方法中尝试了这样的代码:

if ([info.draggingPasteboard.types containsObject:@"MV Super-secret message transfer pasteboard type"]) {
    NSURL *tempFolder = [FM createTempFolderInFolder:AppDataDir()];
    NSArray *filenames = [info namesOfPromisedFilesDroppedAtDestination:tempFolder];
    // tempFolder is filepath of generated temp folder in appdata directory so it is accessible for sandboxed app
    // filenames becomes nil
    return YES;
}

当我尝试遍历粘贴板中的所有类型时,我看到的是:

Dropped types are:
Type: dyn.ah62d4rv4gu8y4zvanr41a3pwfz30n25wqz4ca5pfsr30c35feb4he2pssrxgn6vasbu1g7dfqm10c6xeeb4hw6df (null)
Type: MV Super-secret message transfer pasteboard type (null)
Type: dyn.ah62d4rv4gu8zg7puqz3c465fqr3gn7bakf41k55rqf4g86vasbu1g7dfqm10c6xeeb4hw6df (
        {
        account = Gmail;
        id = 6622;
        mailbox = INBOX;
        subject = "got SUV?";
    }
)
Type: Super-secret Automator pasteboard type (
        {
        account = Gmail;
        id = 6622;
        mailbox = INBOX;
        subject = "got SUV?";
    }
)
Type: dyn.ah62d4rv4gu8yc6durvwwa3xmrvw1gkdusm1044pxqyuha2pxsvw0e55bsmwca7d3sbwu (
    eml
)
Type: Apple files promise pasteboard type (
    eml
)
Type: public.url (null)
Type: CorePasteboardFlavorType 0x75726C20 (null)
Type: dyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw0e55bsmwca7d3sbwu (
    "message:%3C1a392cb9-b78c-402d-8d7f-dbd1d4a9ec42@Neptune.do.losaltos.k12.ca.us%3E",
    ""
)
Type: Apple URL pasteboard type (
    "message:%3C1a392cb9-b78c-402d-8d7f-dbd1d4a9ec42@Neptune.do.losaltos.k12.ca.us%3E",
    ""
)
Type: public.url-name (null)
Type: CorePasteboardFlavorType 0x75726C6E (null)
Type: com.apple.pasteboard.promised-file-content-type com.apple.mail.email
Type: com.apple.pasteboard.promised-file-url (null)
Type: dyn.ah62d4rv4gu8y6y4usm1044pxqzb085xyqz1hk64uqm10c6xenv61a3k (null)
Type: NSPromiseContentsPboardType (null)

有人可以帮助我吗?

1 个答案:

答案 0 :(得分:3)

我刚刚完成了这个过程,实际上很容易。

在粘贴板类型中查找“com.apple.pasteboard.promised-file-content-type = com.apple.mail.email”,如果找到,只需使用放置目标网址和文件调用namesOfPromisedFilesDroppedAtDestination(来自NSDraggingInfo)拖动完成后将创建。