Start on TNEF RTF attribute decompression, but not quite finished yet

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1058555 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2011-01-13 13:53:02 +00:00
parent 9d2b9caa33
commit 89df31493c
4 changed files with 70 additions and 2 deletions

View File

@ -31,10 +31,13 @@ import org.apache.poi.util.LittleEndian;
* Within a {@link HMEFMessage}, the content is often
* stored in as RTF, but LZW compressed. This class
* handles decompressing it for you.
*
* Note - this doesn't quite decompress the data correctly,
* more work and unit testing is required...
*/
public final class CompressedRTF extends LZWDecompresser {
public static final byte[] COMPRESSED_SIGNATURE =
new byte[] { (byte)'L', (byte)'Z', (byte)'F', (byte)'U' };
new byte[] { (byte)'L', (byte)'Z', (byte)'F', (byte)'u' };
public static final byte[] UNCOMPRESSED_SIGNATURE =
new byte[] { (byte)'M', (byte)'E', (byte)'L', (byte)'A' };
public static final int COMPRESSED_SIGNATURE_INT =

View File

@ -62,7 +62,17 @@ public class MAPIAttribute {
}
public String toString() {
return property.toString() + " " + HexDump.toHex(data);
String hex;
if(data.length <= 16) {
hex = HexDump.toHex(data);
} else {
byte[] d = new byte[16];
System.arraycopy(data, 0, d, 0, 16);
hex = HexDump.toHex(d);
hex = hex.substring(0, hex.length()-1) + ", ....]";
}
return property.toString() + " " + hex;
}
/**
@ -146,6 +156,8 @@ public class MAPIAttribute {
MAPIAttribute attr;
if(type == Types.UNICODE_STRING || type == Types.ASCII_STRING) {
attr = new MAPIStringAttribute(prop, type, data);
} else if(id == MAPIProperty.RTF_COMPRESSED.id) {
attr = new MAPIRtfAttribute(prop, type, data);
} else {
attr = new MAPIAttribute(prop, type, data);
}

View File

@ -0,0 +1,49 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
package org.apache.poi.hmef;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import org.apache.poi.hsmf.datatypes.MAPIProperty;
import org.apache.poi.util.StringUtil;
/**
* A pure-MAPI attribute holding RTF (compressed or not), which applies
* to a {@link HMEFMessage} or one of its {@link Attachment}s.
*/
public final class MAPIRtfAttribute extends MAPIAttribute {
private final String data;
public MAPIRtfAttribute(MAPIProperty property, int type, byte[] data) throws IOException {
super(property, type, data);
CompressedRTF rtf = new CompressedRTF();
byte[] decomp = rtf.decompress(new ByteArrayInputStream(data));
this.data = StringUtil.getFromCompressedUnicode(decomp, 0, decomp.length);
}
public String getDataString() {
return data;
}
public String toString() {
return getProperty().toString() + " " + data;
}
}

View File

@ -65,6 +65,10 @@ public final class MAPIStringAttribute extends MAPIAttribute {
this.data = tmpData;
}
public String getDataString() {
return data;
}
public String toString() {
return getProperty().toString() + " " + data;
}