2016-06-14 3 views
2

& 드래그로 전자 메일 URL ("message : //"체계)을 받으면서 붙여 넣기 할 수있는 바탕 화면 응용 프로그램이 있습니다. Subject는 관련 메시지에서 가져옵니다. 지금까지 내가 가진 유일한 단서는 QuickLook 라이브러리가이 정보를 검색 할 수있는 정보 개체를 제공 할 수 있다는 것입니다.이메일 제목을 OSX Swift의 message : // URL에서 가져 오는 방법

현재로서는 QuickLook API이 유동적 인 것처럼 보이고 대부분의 예에서는 iOS에서 사용하는 방법을 보여 주므로 URL을 사용하여 '미리보기'개체를 설정하고 거기에서 정보를 가져 오는 방법을 찾을 수 없습니다. .

내 프로젝트를 QuickLook 플러그인으로 설정하거나 전체 미리보기 창 /보기 스캐 폴딩을 설정하는 것을 피하고 싶습니다. 지금은 QuickLook이로드되기 전에로드해야 할 항목을 알려주고 싶지만 Apple이 여기에서 구현하고자하는 패러다임을 이해할 수는 없습니다.

XCode 7.3.1. 

답변

1

내가 (이 경우 URL) 정보의 한 유형을 포함하는 계층 적 목록으로 draggingInfo.draggingPasteboard().types의 내용을 잘못 해석 밝혀졌습니다. 드래그 이벤트 유형 kUTTypeMessage as String에 가입 stringForType("public.url-name")

편집과 대지에서 전자 메일 제목을 검색했다 : 전자 메일을 드래그 할 때 현재 Mail.app가 때때로이 메일의 스택을 만들 않습니다 실. 위의 방법이 스택의 주제를 얻기 위해 여전히 작동하지만 드래그 정보에는 URL이 없으며 사용 가능한 Message-ID 목록도 없기 때문에 사용자의 mbox 디렉토리를 긁어 내려야했습니다.

 // See if we can resolve e-mail message meta data 
     if let mboxPath = pboard.stringForType("com.apple.mail.PasteboardTypeMessageTransfer") { 
      if let automatorPlist = pboard.propertyListForType("com.apple.mail.PasteboardTypeAutomator") { 
       // Get the latest e-mail in the thread 
       if let maxID = (automatorPlist.allObjects.flatMap({ $0["id"]! }) as AnyObject).valueForKeyPath("@max.self") as? Int { 
        // Read its meta data in the background 
        let emailItem = draggingEmailItem 
        dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)) { 
         // Find the e-mail file 
         if let path = Util.findEmlById(searchPath: mboxPath, id: maxID) { 
          // Read its contents 
          emailItem.properties = Util.metaDataFromEml(path) 
          dispatch_async(dispatch_get_main_queue(), { 
           // Update UI 
          }); 
         } 
        } 
       } 
      } 
     } 

백분율의 funcs :

/* Searches the given path for <id>.eml[x] and returns its URL if found 
*/ 
static func findEmlById(searchPath searchPath: String, id: Int)-> NSURL? { 
    let enumerator = NSFileManager.defaultManager().enumeratorAtPath(searchPath) 
    while let element = enumerator?.nextObject() as? NSString { 
     switch (element.lastPathComponent, element.pathExtension) { 
      case (let lpc, "emlx") where lpc.hasPrefix("\(id)"): 
       return NSURL(fileURLWithPath: searchPath).URLByAppendingPathComponent(element as String)! 
      case (let lpc, "eml") where lpc.hasPrefix("\(id)"): 
       return NSURL(fileURLWithPath: searchPath).URLByAppendingPathComponent(element as String)! 
      default:() 
     } 
    } 
    return nil 
} 

/* Reads an eml[x] file and parses it, looking for e-mail meta data 
*/ 
static func metaDataFromEml(path: NSURL)-> Dictionary<String, AnyObject> { 

    // TODO Support more fields 

    var properties: Dictionary<String, AnyObject> = [:] 
    do { 
     let emlxContent = try String(contentsOfURL: path, encoding: NSUTF8StringEncoding) 
     // Parse message ID from "...\nMessage-ID: <...>" 
     let messageIdStrMatches = emlxContent.regexMatches("[\\n\\r].*Message-ID:\\s*<([^\n\r]*)>") 
     if !messageIdStrMatches.isEmpty { 
      properties["messageId"] = messageIdStrMatches[0] as String 
     } 
    } 
    catch { 
     print("ERROR: Failed to open emlx file") 
    } 
    return properties 
} 

참고 : /Library/

: 앱 당신이 하나의 문자열 배열에 com.apple.security.temporary-exception.files.home-relative-path.read-only 자격 세트가 필요합니다 샌드 박스 경우