[github-103] take latest changes
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1828142 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
6ca71f0bb9
commit
3f19729834
@ -383,12 +383,7 @@ public abstract class PropertiesChunk extends Chunk {
|
|||||||
byte[] bytes = value.getRawValue();
|
byte[] bytes = value.getRawValue();
|
||||||
int length = bytes != null ? bytes.length : 0;
|
int length = bytes != null ? bytes.length : 0;
|
||||||
if (bytes != null) {
|
if (bytes != null) {
|
||||||
// Little endian.
|
out.write(bytes);
|
||||||
byte[] reversed = new byte[bytes.length];
|
|
||||||
for (int i = 0; i < bytes.length; ++i) {
|
|
||||||
reversed[bytes.length - i - 1] = bytes[i];
|
|
||||||
}
|
|
||||||
out.write(reversed);
|
|
||||||
}
|
}
|
||||||
out.write(new byte[8 - length]);
|
out.write(new byte[8 - length]);
|
||||||
}
|
}
|
||||||
|
@ -23,7 +23,6 @@ import static org.junit.Assert.assertNotNull;
|
|||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.nio.ByteBuffer;
|
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.TimeZone;
|
import java.util.TimeZone;
|
||||||
@ -79,19 +78,21 @@ public class TestExtractEmbeddedMSG {
|
|||||||
public void testEmbeddedMSGProperties() throws IOException, ChunkNotFoundException {
|
public void testEmbeddedMSGProperties() throws IOException, ChunkNotFoundException {
|
||||||
AttachmentChunks[] attachments = pdfMsgAttachments.getAttachmentFiles();
|
AttachmentChunks[] attachments = pdfMsgAttachments.getAttachmentFiles();
|
||||||
assertEquals(2, attachments.length);
|
assertEquals(2, attachments.length);
|
||||||
MAPIMessage attachedMsg = attachments[0].getEmbeddedMessage();
|
if (attachments.length == 2) {
|
||||||
assertNotNull(attachedMsg);
|
MAPIMessage attachedMsg = attachments[0].getEmbeddedMessage();
|
||||||
// test properties of embedded message
|
assertNotNull(attachedMsg);
|
||||||
testFixedAndVariableLengthPropertiesOfAttachedMSG(attachedMsg);
|
// test properties of embedded message
|
||||||
// rebuild top level message from embedded message
|
testFixedAndVariableLengthPropertiesOfAttachedMSG(attachedMsg);
|
||||||
try (POIFSFileSystem extractedAttachedMsg = rebuildFromAttached(attachedMsg)) {
|
// rebuild top level message from embedded message
|
||||||
try (ByteArrayOutputStream extractedAttachedMsgOut = new ByteArrayOutputStream()) {
|
try (POIFSFileSystem extractedAttachedMsg = rebuildFromAttached(attachedMsg)) {
|
||||||
extractedAttachedMsg.writeFilesystem(extractedAttachedMsgOut);
|
try (ByteArrayOutputStream extractedAttachedMsgOut = new ByteArrayOutputStream()) {
|
||||||
byte[] extratedAttachedMsgRaw = extractedAttachedMsgOut.toByteArray();
|
extractedAttachedMsg.writeFilesystem(extractedAttachedMsgOut);
|
||||||
MAPIMessage extractedMsgTopLevel = new MAPIMessage(
|
byte[] extratedAttachedMsgRaw = extractedAttachedMsgOut.toByteArray();
|
||||||
new ByteArrayInputStream(extratedAttachedMsgRaw));
|
MAPIMessage extractedMsgTopLevel = new MAPIMessage(
|
||||||
// test properties of rebuilt embedded message
|
new ByteArrayInputStream(extratedAttachedMsgRaw));
|
||||||
testFixedAndVariableLengthPropertiesOfAttachedMSG(extractedMsgTopLevel);
|
// test properties of rebuilt embedded message
|
||||||
|
testFixedAndVariableLengthPropertiesOfAttachedMSG(extractedMsgTopLevel);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -115,17 +116,17 @@ public class TestExtractEmbeddedMSG {
|
|||||||
POIFSFileSystem newDoc = new POIFSFileSystem();
|
POIFSFileSystem newDoc = new POIFSFileSystem();
|
||||||
MessagePropertiesChunk topLevelChunk = new MessagePropertiesChunk(null);
|
MessagePropertiesChunk topLevelChunk = new MessagePropertiesChunk(null);
|
||||||
// Copy attachments and recipients.
|
// Copy attachments and recipients.
|
||||||
int recipientsCount = 0;
|
int recipientscount = 0;
|
||||||
int attachmentsCount = 0;
|
int attachmentscount = 0;
|
||||||
for (Entry entry : attachedMsg.getDirectory()) {
|
for (Entry entry : attachedMsg.getDirectory()) {
|
||||||
if (entry.getName().startsWith(RecipientChunks.PREFIX)) {
|
if (entry.getName().startsWith(RecipientChunks.PREFIX)) {
|
||||||
recipientsCount++;
|
recipientscount++;
|
||||||
DirectoryEntry newDir = newDoc.createDirectory(entry.getName());
|
DirectoryEntry newDir = newDoc.createDirectory(entry.getName());
|
||||||
for (Entry e : ((DirectoryEntry) entry)) {
|
for (Entry e : ((DirectoryEntry) entry)) {
|
||||||
EntryUtils.copyNodeRecursively(e, newDir);
|
EntryUtils.copyNodeRecursively(e, newDir);
|
||||||
}
|
}
|
||||||
} else if (entry.getName().startsWith(AttachmentChunks.PREFIX)) {
|
} else if (entry.getName().startsWith(AttachmentChunks.PREFIX)) {
|
||||||
attachmentsCount++;
|
attachmentscount++;
|
||||||
DirectoryEntry newDir = newDoc.createDirectory(entry.getName());
|
DirectoryEntry newDir = newDoc.createDirectory(entry.getName());
|
||||||
for (Entry e : ((DirectoryEntry) entry)) {
|
for (Entry e : ((DirectoryEntry) entry)) {
|
||||||
EntryUtils.copyNodeRecursively(e, newDir);
|
EntryUtils.copyNodeRecursively(e, newDir);
|
||||||
@ -137,13 +138,6 @@ public class TestExtractEmbeddedMSG {
|
|||||||
for (Map.Entry<MAPIProperty, PropertyValue> p : mpc.getRawProperties().entrySet()) {
|
for (Map.Entry<MAPIProperty, PropertyValue> p : mpc.getRawProperties().entrySet()) {
|
||||||
PropertyValue val = p.getValue();
|
PropertyValue val = p.getValue();
|
||||||
if (!(val instanceof ChunkBasedPropertyValue)) {
|
if (!(val instanceof ChunkBasedPropertyValue)) {
|
||||||
// Reverse data.
|
|
||||||
byte[] bytes = val.getRawValue();
|
|
||||||
for (int idx = 0; idx < bytes.length / 2; idx++) {
|
|
||||||
byte xchg = bytes[bytes.length - 1 - idx];
|
|
||||||
bytes[bytes.length - 1 - idx] = bytes[idx];
|
|
||||||
bytes[idx] = xchg;
|
|
||||||
}
|
|
||||||
MAPIType type = val.getActualType();
|
MAPIType type = val.getActualType();
|
||||||
if (type != null && type != Types.UNKNOWN) {
|
if (type != null && type != Types.UNKNOWN) {
|
||||||
topLevelChunk.setProperty(val);
|
topLevelChunk.setProperty(val);
|
||||||
@ -160,17 +154,20 @@ public class TestExtractEmbeddedMSG {
|
|||||||
nameid.createDocument(PropertiesChunk.DEFAULT_NAME_PREFIX + "00040102", new ByteArrayInputStream(new byte[0]));
|
nameid.createDocument(PropertiesChunk.DEFAULT_NAME_PREFIX + "00040102", new ByteArrayInputStream(new byte[0]));
|
||||||
// Base properties.
|
// Base properties.
|
||||||
// Attachment/Recipient counter.
|
// Attachment/Recipient counter.
|
||||||
topLevelChunk.setAttachmentCount(attachmentsCount);
|
topLevelChunk.setAttachmentCount(attachmentscount);
|
||||||
topLevelChunk.setRecipientCount(recipientsCount);
|
topLevelChunk.setRecipientCount(recipientscount);
|
||||||
topLevelChunk.setNextAttachmentId(attachmentsCount);
|
topLevelChunk.setNextAttachmentId(attachmentscount);
|
||||||
topLevelChunk.setNextRecipientId(recipientsCount);
|
topLevelChunk.setNextRecipientId(recipientscount);
|
||||||
// Unicode string format.
|
// Unicode string format.
|
||||||
topLevelChunk.setProperty(new PropertyValue(MAPIProperty.STORE_SUPPORT_MASK,
|
byte[] storeSupportMaskData = new byte[4];
|
||||||
|
PropertyValue.LongPropertyValue storeSupportPropertyValue = new PropertyValue.LongPropertyValue(MAPIProperty.STORE_SUPPORT_MASK,
|
||||||
MessagePropertiesChunk.PROPERTIES_FLAG_READABLE | MessagePropertiesChunk.PROPERTIES_FLAG_WRITEABLE,
|
MessagePropertiesChunk.PROPERTIES_FLAG_READABLE | MessagePropertiesChunk.PROPERTIES_FLAG_WRITEABLE,
|
||||||
ByteBuffer.allocate(4).putInt(0x00040000).array()));
|
storeSupportMaskData);
|
||||||
|
storeSupportPropertyValue.setValue(0x00040000);
|
||||||
|
topLevelChunk.setProperty(storeSupportPropertyValue);
|
||||||
topLevelChunk.setProperty(new PropertyValue(MAPIProperty.HASATTACH,
|
topLevelChunk.setProperty(new PropertyValue(MAPIProperty.HASATTACH,
|
||||||
MessagePropertiesChunk.PROPERTIES_FLAG_READABLE | MessagePropertiesChunk.PROPERTIES_FLAG_WRITEABLE,
|
MessagePropertiesChunk.PROPERTIES_FLAG_READABLE | MessagePropertiesChunk.PROPERTIES_FLAG_WRITEABLE,
|
||||||
attachmentsCount == 0 ? new byte[] { 0 } : new byte[] { 1 }));
|
attachmentscount == 0 ? new byte[] { 0 } : new byte[] { 1 }));
|
||||||
// Copy properties from MSG file system.
|
// Copy properties from MSG file system.
|
||||||
for (Chunk chunk : attachedMsg.getMainChunks().getChunks()) {
|
for (Chunk chunk : attachedMsg.getMainChunks().getChunks()) {
|
||||||
if (!(chunk instanceof MessagePropertiesChunk)) {
|
if (!(chunk instanceof MessagePropertiesChunk)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user