use of com.pff.PSTAttachment in project Xponents by OpenSextant.
the class OutlookPSTCrawler method processAttachments.
/**
* REFERENCE: libpst home page, https://code.google.com/p/java-libpst/
* @author com.pff
* @author ubaldino -- cleaned up name checks.
* @param msg PST API message
* @param msgFolder output target
* @return list of attachment filenames
* @throws PSTException err
* @throws IOException err
* @throws ConfigException err
*/
public List<String> processAttachments(PSTMessage msg, File msgFolder) throws PSTException, IOException, ConfigException {
int numberOfAttachments = msg.getNumberOfAttachments();
List<String> attachmentFilenames = new ArrayList<String>();
for (int x = 0; x < numberOfAttachments; x++) {
PSTAttachment attach = msg.getAttachment(x);
// both long and short filenames can be used for attachments
String filename = attach.getLongFilename();
if (StringUtils.isBlank(filename)) {
filename = attach.getFilename();
if (StringUtils.isBlank(filename)) {
filename = String.format("attachment%d", x + 1);
}
}
File attPath = new File(String.format("%s/%s", msgFolder.getAbsolutePath(), filename));
savePSTFile(attach.getFileInputStream(), attPath.getAbsolutePath());
attachmentFilenames.add(filename);
if (listener != null) {
listener.collected(attPath);
}
if (converter != null) {
converter.convert(attPath);
}
}
return attachmentFilenames;
}
use of com.pff.PSTAttachment in project tika by apache.
the class OutlookPSTParser method parseMailAttachments.
private void parseMailAttachments(XHTMLContentHandler xhtml, PSTMessage email, EmbeddedDocumentExtractor embeddedExtractor) throws TikaException {
int numberOfAttachments = email.getNumberOfAttachments();
for (int i = 0; i < numberOfAttachments; i++) {
File tempFile = null;
try {
PSTAttachment attach = email.getAttachment(i);
// Get the filename; both long and short filenames can be used for attachments
String filename = attach.getLongFilename();
if (filename.isEmpty()) {
filename = attach.getFilename();
}
xhtml.element("p", filename);
Metadata attachMeta = new Metadata();
attachMeta.set(Metadata.RESOURCE_NAME_KEY, filename);
attachMeta.set(Metadata.EMBEDDED_RELATIONSHIP_ID, filename);
AttributesImpl attributes = new AttributesImpl();
attributes.addAttribute("", "class", "class", "CDATA", "embedded");
attributes.addAttribute("", "id", "id", "CDATA", filename);
xhtml.startElement("div", attributes);
if (embeddedExtractor.shouldParseEmbedded(attachMeta)) {
TemporaryResources tmp = new TemporaryResources();
try {
TikaInputStream tis = TikaInputStream.get(attach.getFileInputStream(), tmp);
embeddedExtractor.parseEmbedded(tis, xhtml, attachMeta, true);
} finally {
tmp.dispose();
}
}
xhtml.endElement("div");
} catch (Exception e) {
throw new TikaException("Unable to unpack document stream", e);
} finally {
if (tempFile != null)
tempFile.delete();
}
}
}
Aggregations