Verschil tussen inline‑ en reguliere bijlagen

Contents
[ ]

Dit artikel legt uit hoe je inline‑bijlagen kunt onderscheiden van reguliere bijlagen met behulp van MapiMessage. Bij het bepalen, het type inhoud van MapiMessage wordt als volgt in aanmerking genomen:

  • Platte‑tekst‑inhoud: E‑mailberichten met een platte‑tekst‑inhoud hoeven niet gecontroleerd te worden, aangezien alle bijlagen in dergelijke berichten altijd reguliere bijlagen zijn.
  • HTML‑inhoud: Voor berichten met een HTML‑inhoud mag de bijlage niet alleen de PR_ATTACH_FLAGS (0x37140003) eigenschap bevatten, maar de waarde moet gelijk zijn aan 0x00000004 voor inline‑bijlagen. Als aan deze voorwaarde is voldaan, hangt het verder af van de tags PR_ATTACH_CONTENT_LOCATION en PR_ATTACH_CONTENT_ID om de aard van de bijlage te bepalen. Bij afwezigheid van de PR_ATTACH_FLAGS MAPI‑tag wordt de bijlage gecontroleerd op de PR_ATTACH_DISPOSITION (0x3716001F of 0x3716001E) eigenschap om het type bijlage te bepalen.
  • RTF‑inhoud: Als de inhoud RTF is, dan zijn alle OLE‑bijlagen inline‑bijlagen. De waarde van PR_ATTACH_METHOD voor alle OLE‑bijlagen is gelijk aan 0x00000006.

Het volgende codevoorbeeld laat zien hoe je programmatisch kunt onderscheiden tussen inline‑ en reguliere bijlagen. De functie isInlineAttachment neemt een bijlage en een MapiMessage als invoerparameters en retourneert true als de bijlage een inline‑bijlage is.

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();
    }
}

Deze codefragment gebruikt de functie isInlineAttachment() om bijlagen te evalueren.

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");
    }
}