Question

I'm working on a Cocoa application into which I'd like to allow Mail messages to be dropped.

If I include public.plain-text in my Info.plist Document Types, I can drop a Mail message on the icon in the Dock and get a file path like this from the application:openFiles: delegate method:

"/Users/smokris/Library/Caches/TemporaryItems/Re_ multiplexer question 3.eml"

...and I can read the raw message data from this file. So far so good.

However, I also want the user to be able to drop Mail messages on the application window. So I do this:

[window registerForDraggedTypes:[NSArray arrayWithObjects:(NSString *)kPasteboardTypeFileURLPromise,nil]];

...and in performDragOperation:, I get a URL like this from the pasteboard:

message:%3CAANLkTikeTeWYU39JpTovxF2PC0Mm=xkrU7fHNh6gGh6V@mail.gmail.com%3E

If I try doing an NSURLRequest on this URL, it gives me the error "unsupported URL".

How can I get the raw message data from this message: URL?

Was it helpful?

Solution

I tried it out with Apple's PasteboardPeeper sample code (from http://developer.apple.com/library/mac/#samplecode/PasteboardPeeker/Introduction/Intro.html), and dragging a message into the main did show that the path of the message is available:

PasteboardRef: 1395632  ItemCount: 1
   Index: 1  item ID: 789514
      "dyn.ah62d4rv4gu8y4zvanr41xxxxx30n25wqz4ca5pfsr30c35feb4he2pssrxgn6vasbu1g7dfqm1"
      "MV Super-secret message transfer pasteboard type"
      '' ______ 82  /Users/guest/Library/Mail/IMAP-me@gmail.com@imap.gmail.com/INBOX.imapmb

      "dyn.ah62d4rv4gu8zg7puqz3c465fqr3gn7bakf41k55rqf4g86vasbu1g7dfqm10c6xeeb4hw6df"
      "Super-secret Automator pasteboard type"
      '' ______ 454  <?xml version= 1.0  encoding= UTF-8 ?> < DOCTYPE plist PUBLIC  -//Apple//DTD PLI

      "dyn.ah62d4rv4gu8yc6durvwwa3xmrvw1gkdusm1044pxqyuha2pxsvw0e55bsmwca7d3sbwu"
      "Apple files promise pasteboard type"
      '' ______ 212  <?xml version= 1.0  encoding= UTF-8 ?> < DOCTYPE plist PUBLIC  -//Apple//DTD PLI

      "public.url"
      ""
      'url ' ______ 74  message: 3C6EEF5CFD6A04D6395BC617836C91FC3A050542759970026E@cornell.edu 3E

      "public.url-name"
      ""
      'urln' ______ 56  A friend thought you would be interested in this station

      "com.apple.pasteboard.promised-file-content-type"
      ""
      '' ______ 23  dyn.ah6xxxqmxhk2x43prru

      "com.apple.pasteboard.promised-file-url"
      ""
      '' ______ 0  

      "dyn.ah62d4rv4gu8y6y4usm10xxxxqzb085xyqz1hk64uqm10c6xenv61a3k"
      "NSPromiseContentsPboardType"
      '' ______ 0  

      "dyn.ah62d4rv4gk81a4dgsq"
      ""
      'phfs' PT____ 14  ????????  Pssf

I don't know what "MV Super-secret message transfer pasteboard type" is, but you might not want to rely on it as a key name; rather, maybe you could just walk through all the keys and see if any of them look like a file path.

P.S. This might also be of interest: http://www.wuffwuffware.com/developer.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top