private byte[] getValue(Chunk chunk) { byte[] data = null; if (chunk instanceof ByteChunk) { data = ((ByteChunk) chunk).getValue(); } else if (chunk instanceof StringChunk) { data = ((StringChunk) chunk).getRawValue(); } return data; }
r.displayName = (chunks.recipientDisplayNameChunk != null) ? chunks.recipientDisplayNameChunk.toString() : null; r.name = (chunks.recipientNameChunk != null) ? chunks.recipientNameChunk.toString() : null; r.emailAddress = chunks.getRecipientEmailAddress(); List<PropertyValue> vals = chunks.getProperties().get(MAPIProperty.RECIPIENT_TYPE); Object val = vals.get(0).getValue(); if (val instanceof Integer) { recipientType = RECIPIENT_TYPE.getTypeFromVal((int)val); vals = chunks.getProperties().get(MAPIProperty.ADDRTYPE); if (vals != null && vals.size() > 0) { String val = vals.get(0).toString(); if (val != null) { val = val.toLowerCase(Locale.US);
Chunk rtfChunk = null; Chunk textChunk = null; for (Chunk chunk : msg.getMainChunks().getChunks()) { if (chunk.getChunkId() == MAPIProperty.BODY_HTML.id) { htmlChunk = chunk; if (chunk.getChunkId() == MAPIProperty.RTF_COMPRESSED.id) { rtfChunk = chunk; if (chunk.getChunkId() == MAPIProperty.BODY.id) { textChunk = chunk; if (attachment.getAttachLongFileName() != null) { filename = attachment.getAttachLongFileName().getValue(); } else if (attachment.getAttachFileName() != null) { filename = attachment.getAttachFileName().getValue(); if (attachment.getAttachData() != null) { handleEmbeddedResource( TikaInputStream.get(attachment.getAttachData().getValue()), filename, null, null, xhtml, true ); if (attachment.getAttachmentDirectory() != null) { handleEmbeddedOfficeDoc( attachment.getAttachmentDirectory().getDirectory(), xhtml );
byte[] data = null; if (htmlChunk instanceof ByteChunk) { data = ((ByteChunk) htmlChunk).getValue(); } else if (htmlChunk instanceof StringChunk) { data = ((StringChunk) htmlChunk).getRawValue(); if (chunk.getValue() != null && chunk.getValue().length > 0) { MAPIRtfAttribute rtf = new MAPIRtfAttribute( MAPIProperty.RTF_COMPRESSED, Types.BINARY.getId(), chunk.getValue() ); Parser rtfParser = xhtml.element("p", ((StringChunk) textChunk).getValue());
Map<MAPIProperty, List<PropertyValue>> props = mainChunks.getProperties(); if (props != null) { List<PropertyValue> val = props.get(prop); if (val != null && val.size() > 0) { int codepage = ((PropertyValue.LongPropertyValue) val.get(0)).getValue(); String encoding = null; try { StringChunk text = mainChunks.getTextBodyChunk(); if (text != null) { CharsetDetector detector = new CharsetDetector(); detector.setText(text.getRawValue()); CharsetMatch match = detector.detect(); if (match != null && match.getConfidence() > 35 &&
StringChunk sentByServerType = chunks.getSentByServerType(); if (sentByServerType != null) { metadata.set(Office.MAPI_SENT_BY_SERVER_TYPE, sentByServerType.getValue()); Map<MAPIProperty, List<Chunk>> mainChunks = msg.getMainChunks().getAll();
/** * Returns the embedded object, if the attachment is an object based * embedding (image, document etc), or null if it's an embedded message */ public byte[] getEmbeddedAttachmentObject() { if (attachData != null) { return attachData.getValue(); } return null; }
/** * Sets the Encoding that will be used to decode any "7 bit" (non unicode) * data. This doesn't appear to be stored anywhere specific in the file, so * you may need to guess by looking at headers etc */ public void set7BitEncoding(String encoding) { this.encoding7Bit = encoding; // Re-read the String if we're a 7 bit one if (getType() == Types.ASCII_STRING) { parseString(); } }
@Override public String toString() { Object v = getValue(); if (v == null) { return "(No value available)"; } if (v instanceof byte[]) { return ByteChunk.toDebugFriendlyString((byte[]) v); } else { // Just use the normal toString on the value return v.toString(); } }
/** * Parses as non-unicode, supposedly 7 bit CP1252 data * and returns the string that that yields. */ protected static String parseAs7BitData(byte[] data) { return parseAs7BitData(data, DEFAULT_ENCODING); } /**
/** * Return the 4 character hex encoded version, as used in file endings */ public String asFileEnding() { return Types.asFileEnding(id); } }
@Override public void writeValue(OutputStream stream) throws IOException { // write properties without variable length properties writeProperties(stream); } }
/** * Returns the data in a debug-friendly string format */ @Override public String toString() { return toDebugFriendlyString(value); }
/** * Returns the embedded MAPI message, if the attachment is an embedded * message, or null otherwise */ public MAPIMessage getEmbeddedMessage() throws IOException { if (attachmentDirectory != null) { return attachmentDirectory.getAsEmbededMessage(); } return null; }
@Override public String toString() { return id + " / 0x" + asFileEnding() + " - " + name + " @ " + length; }
private byte[] getValue(Chunk chunk) { byte[] data = null; if (chunk instanceof ByteChunk) { data = ((ByteChunk) chunk).getValue(); } else if (chunk instanceof StringChunk) { data = ((StringChunk) chunk).getRawValue(); } return data; }
/** * Returns the data, formatted as a string assuming it * was a non-unicode string. * If your data isn't in fact stored as basically * ASCII, don't expect this to return much of any * sense.... * @return the data formatted as a string */ public String getAs7bitString() { return StringChunk.parseAs7BitData(value); } }
/** * Returns the data, formatted as a string assuming it was a non-unicode * string. If your data isn't in fact stored as basically ASCII, don't * expect this to return much of any sense.... * * @return the data formatted as a string */ public String getAs7bitString() { return StringChunk.parseAs7BitData(value); } }
/** * Parses as non-unicode, supposedly 7 bit CP1252 data and returns the * string that that yields. */ protected static String parseAs7BitData(byte[] data) { return parseAs7BitData(data, DEFAULT_ENCODING); }