Satır içi ve Normal Ekler Arasındaki Farkı Belirleme

Contents
[ ]

Bu makale, satır içi ekleri normal eklerden ayırmayı … kullanarak açıklar MapiMessage. Karar verirken, gövde tipi MapiMessage aşağıdaki gibi dikkate alınır:

  • Düz metin gövdesi: Düz metin gövdesine sahip e-posta mesajlarında eklerin kontrol edilmesine gerek yoktur, çünkü bu tür mesajlardaki tüm ekler her zaman normal eklerdir.
  • HTML gövdesi: HTML gövdesine sahip mesajlarda, ek yalnızca PR_ATTACH_FLAGS (0x37140003) özelliğini içermekle kalmamalı, aynı zamanda satır içi ekler için değeri 0x00000004 olmalıdır. Bu koşul sağlandığında, ekin niteliğini belirlemek için PR_ATTACH_CONTENT_LOCATION ve PR_ATTACH_CONTENT_ID etiketlerine de bakılır. Ancak, PR_ATTACH_FLAGS MAPI etiketi yoksa, ekin türünü belirlemek için PR_ATTACH_DISPOSITION (0x3716001F veya 0x3716001E) özelliği kontrol edilir.
  • RTF gövdesi: Gövde RTF ise, tüm OLE ekleri satır içi eklerdir. Tüm OLE ekleri için PR_ATTACH_METHOD değeri 0x00000006’ya eşittir.

Aşağıdaki kod örneği, satır içi ve normal ekler arasında programatik olarak farklılaştırmayı göstermektedir. isInlineAttachment fonksiyonu bir eki ve MapiMessage’ı girdi parametreleri olarak alır ve ek satır içi ise true döndürür.

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

Bu kod snippet’i, ekleri değerlendirmek için isInlineAttachment() fonksiyonunu kullanır.

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