Inline 첨부 파일과 일반 첨부 파일 구분

Contents
[ ]

이 문서는 inline 첨부 파일과 일반 첨부 파일을 구분하는 방법을 설명합니다 MapiMessage. 결정 시, 본문의 타입은 MapiMessage 다음과 같이 고려됩니다:

  • Plain text 본문: 일반 텍스트 본문 타입의 이메일 메시지는 별도로 확인할 필요가 없습니다. 이러한 메시지의 모든 첨부 파일은 항상 일반 첨부 파일이기 때문입니다.
  • HTML 본문: HTML 본문이 있는 메시지의 경우, 첨부 파일은 PR_ATTACH_FLAGS (0x37140003) 속성을 포함해야 할 뿐만 아니라, inline 첨부 파일인 경우 해당 값이 0x00000004이어야 합니다. 이 조건이 충족되면 PR_ATTACH_CONTENT_LOCATION 및 PR_ATTACH_CONTENT_ID 태그를 추가로 확인하여 첨부 파일의 성격을 판단합니다. 그러나 PR_ATTACH_FLAGS MAPI 태그가 없는 경우, 첨부 파일은 PR_ATTACH_DISPOSITION (0x3716001F 또는 0x3716001E) 속성을 확인하여 첨부 파일 유형을 결정합니다.
  • RTF 본문: 본문이 RTF인 경우 모든 OLE 첨부 파일은 inline 첨부 파일입니다. 모든 OLE 첨부 파일의 PR_ATTACH_METHOD 값은 0x00000006과 같습니다.

다음 코드 샘플은 inline 첨부 파일과 일반 첨부 파일을 프로그램matically 구분하는 방법을 보여줍니다. isInlineAttachment 함수는 첨부 파일과 MapiMessage를 입력 매개변수로 받아들이며, 첨부 파일이 inline인 경우 true를 반환합니다.

public static boolean isInlineAttachment(MapiAttachment att, MapiMessage msg) {
    if (msg.getBodyType() == BodyContentType.PlainText)
        // ignore indications for plain text messages
        return false;
    else if (msg.getBodyType() == BodyContentType.Html) {
        // check the PidTagAttachFlags property
        Long attachFlagsValue = att.getPropertyLong(MapiPropertyTag.PR_ATTACH_FLAGS);
        if (attachFlagsValue != null && (attachFlagsValue > 3 || attachFlagsValue < 1)) {
            // check PidTagAttachContentId property
            String contentId = att.getProperties().containsKey(MapiPropertyTag.PR_ATTACH_CONTENT_ID)
                    ? att.getPropertyString(MapiPropertyTag.PR_ATTACH_CONTENT_ID)
                    : att.getPropertyString(MapiPropertyTag.PR_ATTACH_CONTENT_ID_W);
            if (contentId != null && !contentId.isEmpty() && msg.getBodyHtml().contains("cid:" + contentId)) {
                return true;
            }
            // check PidTagAttachContentLocation property
            String contentLocation = att.getProperties().containsKey(MapiPropertyTag.PR_ATTACH_CONTENT_LOCATION)
                    ? att.getPropertyString(MapiPropertyTag.PR_ATTACH_CONTENT_LOCATION)
                    : att.getPropertyString(MapiPropertyTag.PR_ATTACH_CONTENT_LOCATION_W);
            if (contentLocation != null && !contentLocation.isEmpty() && msg.getBodyHtml().contains(contentLocation)) {
                return true;
            }
        }
        return "inline".equals(att.getPropertyString(0x3716001F)) || "inline".equals(att.getPropertyString(0x3716001E));
    } else if (msg.getBodyType() == BodyContentType.Rtf) {
        // If the body is RTF, then all OLE attachments are inline attachments.
        // OLE attachments have 0x00000006 for the value of the PidTagAttachMethod property
        Long attachMethod = att.getPropertyLong(MapiPropertyTag.PR_ATTACH_METHOD);
        return attachMethod != null && attachMethod == 0x00000006;
    } else {
        throw new ArgumentOutOfRangeException();
    }
}

이 코드 조각은 isInlineAttachment() 함수를 사용해 첨부 파일을 평가합니다.

Java

String fileName = ("Sample.msg");
MapiMessage message = MapiMessage.fromFile(fileName);
MapiAttachmentCollection attachments = message.getAttachments();
for (int i = 0; i < attachments.size(); i++) {
    MapiAttachment attachment = (MapiAttachment) attachments.get(i);
    if (isInlineAttachment(attachment, message)) {
        System.out.println(attachment.getLongFileName() + " is inline attachment");
    } else {
        System.out.println(attachment.getLongFileName() + " is regular attachment");
    }
}