2013-06-19 5 views
0

현재 java mail api로 작업하고 있습니다. 첨부 파일 세부 정보를 나열해야 할 경우 일부 전자 메일에서 첨부 파일을 제거하고 다른 사람에게 전달할 수도 있습니다. 그래서 첨부 파일 ID를 찾으려고합니다. 내가 어떻게 해? 어떤 제안이라도 감사 할 것입니다 !!!첨부 파일 ID가있는 이메일

답변

0

이 정보가 도움이됩니까?

private void getAttachments(Part p, File inputFolder, List<String> fileNames) throws Exception{ 
    String disp = p.getDisposition(); 
    if (!p.isMimeType("multipart/*")) { 
     if (disp == null || (disp != null && (disp.equalsIgnoreCase(Part.ATTACHMENT) || disp.equalsIgnoreCase(Part.INLINE)))) {    
      String fileName = p.getFileName(); 
      File opFile = new File(inputFolder, fileName); 
      ((MimeBodyPart) p).saveFile(opFile); 
      fileNames.add(fileName);      
      } 
     } 
    }else{ 
     Multipart mp = (Multipart) p.getContent(); 
     int count = mp.getCount(); 
     for (int i = 0; i < count; i++){     
      getAttachments(mp.getBodyPart(i),inputFolder, fileNames); 
     } 
    } 
} 
0

첨부 ID로 아무것도 없습니다. 무엇 부착 된 내용으로 메시지와 메일 클라이언트 디스플레이, 정말 MIME 여러 부분과 같이 (sample source)를 찾습니다 :

From: John Doe <[email protected]> 
MIME-Version: 1.0 
Content-Type: multipart/mixed; boundary="XXXXboundary text" 

This is a multipart message in MIME format. 

--XXXXboundary text 
Content-Type: text/plain 

this is the body text 

--XXXXboundary text 
Content-Type: text/plain; 
Content-Disposition: attachment; filename="test.txt" 

this is the attachment text 

--XXXXboundary text-- 

중요 사항주의하기 :

  1. 여러 부분의 모든 부분이있다 Content-Type
  2. 선택적으로, Content-Dispositionheader
  3. 단일 부품이 스스로 여러 부분이 될 수있을 수
이 참으로 Content-ID 헤더,하지만 난 그것을 위해 당신이 찾고있는 것을 생각하지 않는 것이

참고 : 예를 들어,이 같은 전자 메일 메시지에 text/html에서 image/*의 텍스트를 포함 할 multipart/related 메시지에 사용됩니다. 당신은 그것이 어떻게 작동하고 그것이 당신의 입력에 사용되는지 이해해야합니다.

최상의 옵션은 Content-DispositionContent-Type 헤더를 검사하는 것입니다. 나머지는 어림짐작이며 실제 요구 사항 없이는 코드를 도울 수 없습니다.

+0

의견을 보내 주셔서 감사합니다. –

관련 문제