질문 : 첨부 파일이있는 전자 메일 메시지가 있다고 가정합니다 (JPEG 첨부라고 가정). 어떻게하면 (Tika facade 클래스를 사용하지 않고) 이메일 메시지를 구문 분석하고 고유 한 부분을 반환합니까? a) 이메일 텍스트 내용과 b) 이메일 첨부 파일?Tika - 복합 문서에서 고유 항목 추출
구성 : 티카 1.2 자바 1.7
상세 사항 : 나는 제대로 기본 전자 메일 메시지 형식으로 전자 메일 메시지를 구문 분석 할 수 있었다. 그러나 구문 분석 후, 나는 이메일의 텍스트 내용과 b) 이메일에 첨부 된 내용을 알아야한다. 본인의 데이터베이스에 이러한 항목을 본질적으로 하위 첨부 파일이있는 전자 메일로 저장합니다.
알아낼 수없는 것은 내가 뚜렷한 부분을 "되돌릴"수 있고 부모 이메일에 첨부 파일이 있으며 메일에 참조 된 첨부 파일을 별도로 저장할 수 있다는 것입니다. 이것은 ZipFile 내용 추출과 근본적으로 유사하다고 생각합니다.
코드 예 :
private Message processDocument(String fullfilepath) {
try {
File filename = new File(fullfilepath) ;
return this.processDocument(filename) ;
} catch (NullPointerException npe) {
Message error = new Message(false) ;
error.appendErrorMessage("The file name was null.") ;
return error ;
}
}
private Message processDocument(File filename) {
InputStream stream = null;
try {
stream = new FileInputStream(filename) ;
} catch (FileNotFoundException fnfe) {
// TODO Auto-generated catch block
fnfe.printStackTrace();
System.out.println("FileNotFoundException") ;
return diag ;
}
int writelimit = -1 ;
ContentHandler texthandler = new BodyContentHandler(writelimit);
this.safehandlerbodytext = new SafeContentHandler(texthandler);
this.meta = new Metadata() ;
ParseContext context = new ParseContext() ;
AutoDetectParser autodetectparser = new AutoDetectParser() ;
try {
autodetectparser.parse(
stream,
texthandler,
meta,
context) ;
this.documenttype = meta.get("Content-Type") ;
diag.setSuccessful(true);
} catch (IOException ioe) {
// if the document stream could not be read
System.out.println("TikaTextExtractorHelper IOException " + ioe.getMessage()) ;
//FIXME -- add real handling
} catch (SAXException se) {
// if the SAX events could not be processed
System.out.println("TikaTextExtractorHelper SAXException " + se.getMessage()) ;
//FIXME -- add real handling
} catch (TikaException te) {
// if the document could not be parsed
System.out.println("TikaTextExtractorHelper TikaException " + te.getMessage()) ;
System.out.println("Exception Filename = " + filename.getName()) ;
//FIXME -- add real handling
}
}
당신이 자식 문서를 잡고 그들을 저장하는 문맥에 파서를 추가 봤어 :
그럼, 당신이 아마하고 싶은 무언가처럼? – Gagravarr
감사합니다. 아니, 나는 이것을 시도하지 않았다. 나는 컨텍스트가 실제로하는 일에 너무 익숙하지 않다. 귀하의 노트를 이해한다면, 다른/다른 파서를 컨텍스트 자체에 추가 할 수 있습니까? 이것이 자녀 결과를 어떻게 반환합니까? 나는 이것을 더 깊이 조사하려고 노력할 것이다. – SaB