objective c - Drop e-mail from mail.app into NSWindow object -


i have cocoa app accept e-mails mail.app dragged main window of app. have in applicationdidfinishlaunching:

[_window registerfordraggedtypes:     [nsarray arraywithobjects:        nsfilenamespboardtype,       (nsstring *)kpasteboardtypefileurlpromise, nil]]; //kuttypedata [_window setdelegate:(id) self]; 

this works fine, can receive document, in performdragoperation: using

nsarray * files =  [sender namesofpromisedfilesdroppedatdestination:url]; 

however, lets me drag emails one-by-one. if mark several emails, seems ok until drop, nothing happens. performdragoperation not called.

i have tried add kuttypedata registerfordraggedtypes..., , performdragoperation... called, cannot use namesofpromisedfilesdroppedatdestination:url returns nil pointer.

when had kuttypedata included in register... included in performdragoperation see types in drag:

pboard = [sender draggingpasteboard]; nslog(@"perform drag entered, %@", [pboard types]); 

with following result:

2013-07-25 15:09:50.771 bo2ical[1672:303] perform drag entered, ( "dyn.ah62d4rv4gu8y4zvanr41a3pwfz30n25wqz4ca5pfsr30c35feb4he2pssrxgn6vasbu1g7dfqm10c6xeeb4hw6df", "mv super-secret message transfer pasteboard type", "dyn.ah62d4rv4gu8zg7puqz3c465fqr3gn7bakf41k55rqf4g86vasbu1g7dfqm10c6xeeb4hw6df", "super-secret automator pasteboard type" ) 

while list single e-mails are:

2013-07-25 15:14:30.096 bo2ical[1672:303] perform drag entered, ( "dyn.ah62d4rv4gu8y4zvanr41a3pwfz30n25wqz4ca5pfsr30c35feb4he2pssrxgn6vasbu1g7dfqm10c6xeeb4hw6df", "mv super-secret message transfer pasteboard type", "dyn.ah62d4rv4gu8zg7puqz3c465fqr3gn7bakf41k55rqf4g86vasbu1g7dfqm10c6xeeb4hw6df", "super-secret automator pasteboard type", "dyn.ah62d4rv4gu8yc6durvwwa3xmrvw1gkdusm1044pxqyuha2pxsvw0e55bsmwca7d3sbwu", "apple files promise pasteboard type", "public.url", "corepasteboardflavortype 0x75726c20", "dyn.ah62d4rv4gu8yc6durvwwaznwmuuha2pxsvw0e55bsmwca7d3sbwu", "apple url pasteboard type", "public.url-name", "corepasteboardflavortype 0x75726c6e", "com.apple.pasteboard.promised-file-content-type", "com.apple.pasteboard.promised-file-url", "dyn.ah62d4rv4gu8y6y4usm1044pxqzb085xyqz1hk64uqm10c6xenv61a3k", nspromisecontentspboardtype )

does have advice how correctly in order accept multiple e-mails?

i have found solution this. found data provided in mode "kuttypedata" gave me enough data grab files directly mail.app mailbox.

in mbox folder, there folder long sequence of numbers , dashes, there no trace of name anywhere in mailbox hierarchy, since contains folder , info.plist file, used function grab name: update: implemented regexp check since folder contains sub-mailboxes can have longer name...

-(nsstring*)findcodedfolderinmailbox:(nsstring*)mailboxpath {       nsstring *uuid_regexp = @"[a-f0-9]{8}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{4}-[a-f0-9]{12}";      nspredicate *uuid_test = [nspredicate predicatewithformat:@"self matches %@", uuid_regexp];       nsfilemanager *filemanager = [nsfilemanager defaultmanager];      nsarray *filelist = [filemanager contentsofdirectoryatpath:mailboxpath error:nil];      (nsstring * file in filelist) {          if ([uuid_test evaluatewithobject: file]){              return file;          }      }      return nil; } 

then section find there no "nspromisecontentspboardtype", instead "super-secret automator pasteboard type", wrote following section (there nslog entries intend remove, here is:

} else if ( [[pboard types] containsobject:@"super-secret automator pasteboard type"] ) {       nsfilemanager *filemanager = [nsfilemanager defaultmanager];      // create url destination folder , ensure exists.       nsurl *applicationfilesdirectory = [self applicationfilesdirectory];      nsurl *url = [applicationfilesdirectory urlbyappendingpathcomponent:@"documents"];      bool isdir;      if (!([filemanager fileexistsatpath:[url path] isdirectory:&isdir] && isdir)) {          nserror * error = nil;          [ filemanager createdirectoryaturl:url withintermediatedirectories: yes attributes:nil error:&error];          if (error) {              [[nsapplication sharedapplication] presenterror:error];          }      }      bool ok = false;    // locate mailbox path....     nsstring *mailboxpath = [pboard stringfortype:@"mv super-secret message transfer pasteboard type"];     nslog(@"mailboxpath: %@", mailboxpath);      nsstring * codedfolder = [self findcodedfolderinmailbox:mailboxpath];     if (codedfolder) {         nsstring * codedpath = [nsstring stringwithformat:@"file://%@/%@/data", mailboxpath, codedfolder];         nsurl * mb1 = [nsurl urlwithstring:codedpath];         nslog(@"directory:%@", mb1);         nsarray *msgarray = [pboard propertylistfortype:@"super-secret automator pasteboard type"];         if (msgarray) {             (nsdictionary *msg in msgarray) {                  // locate message....                 nsnumber * msgid = [msg valueforkey:@"id"];                 nslog(@"melding(%@):%@", msgid, msg);                 nsstring * filename = [nsstring stringwithformat:@"%@.emlx", msgid];                  // second , first letter of id                 nsstring * idsec = [[msgid stringvalue]substringwithrange:(nsrange){1, 1}];                 nsstring * idfirst = [[msgid stringvalue]substringwithrange:(nsrange){0, 1}];                 nsstring * subpath = [nsstring stringwithformat:@"%@/%@/messages/%@",idsec, idfirst,  filename];                  nsurl * thisfilepath = [mb1 urlbyappendingpathcomponent:subpath];                   if ([filemanager fileexistsatpath:[thisfilepath path]]) {                      nsurl *destpath = [url urlbyappendingpathcomponent:filename];                      nserror * error = nil;                     [filemanager copyitematurl:thisfilepath tourl:destpath error:&error];                     if (error) {                         [[nsapplication sharedapplication]presenterror:error];                     } else {                         [self parseemlmessageforpath:[destpath path] filename:filename];                      }                   }              }           }      } 

and here go.... :-)


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -