Get Dropped Mail from Apple Mail in Cocoa
I googled and read docs. Searched SO, found answers suggesting using Applescript, but I can't use Applescript because of the sandbox.
I am working on a Cocoa application (written in Objective-C and sandboxed software). I am using drag-and-drop from Apple Mail app. The app needs to receive or copy the eml email message like the Finder does.
I tried to look NSPromisedFilesPboardType
but could hardly figure out how I should work with it. I've tried code like this in a method - (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;
}
When I try to iterate over all types in the filing cabinet, this is what I see:
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)
Can anyone help me?
I just went through this process and it was actually pretty easy.
Look for "com.apple.pasteboard.promised-file-content-type = com.apple.mail.email" in carton types and if you just try them call namesOfPromisedFilesDroppedAtDestination (from NSDraggingInfo) with the target url to delete and the file will be created when the drag is complete.