1

I have a HMEFMessage and iterating all attachments using

for (Attachment tnefAttachment : hmef.getAttachments()) {

Attachment size can be obtained using tnefAttachment.getMAPIAttribute(MAPIProperty.ATTACH_SIZE) . This method returns MAPIAttribute instance and it has only getData(), which returns byte[].

How can I convert byte[] from MAPIAttribute to Long (size)?

According to this - https://poi.apache.org/apidocs/org/apache/poi/hmef/attribute/package-summary.html - there is a MAPIStringAttribute.getAsString(attr), which does not work with ATTACH_SIZE.

EDIT - ATTACH_SIZE is Long according to http://grepcode.com/file/repo1.maven.org/maven2/org.openl.rules/org.openl.lib.poi.dev/5.9.4.1/org/apache/poi/hsmf/datatypes/MAPIProperty.java .

Amit Verma
  • 40,709
  • 21
  • 93
  • 115
Xdg
  • 1,735
  • 2
  • 27
  • 42

1 Answers1

2

MAPIProperty.ATTACH_SIZE only indicates the attribute you are requesting with getMAPIAttribute() so its type does not matter.

I suggest using the size of the content to solve your problem:

tnefAttachment.getContent().length

will give you the size of the attachment in bytes.

If you want to convert a byte array to long, see this question.

Community
  • 1
  • 1
andy
  • 2,002
  • 1
  • 12
  • 21
  • Yeah, but calling getContent() downloads a file from server, doesn't it? I wanted to get a size without fetching a file actually. – Xdg Nov 12 '14 at 16:50
  • HSMF works on files anyways. If you do not want to use that approach, convert the bytes to a single long as in the linked question. – andy Nov 12 '14 at 18:27