@Override public InputStream getContent() throws IOException, IllegalStateException { try { return message.getInputStream(); } catch (MessagingException e) { throw new IOException(e); } }
public String getMessageRawText() { MimeMessage message = getMessage(); try { return getTextFromStream(message.getInputStream()); } catch (Exception e) { Debug.logError(e, module); return null; } }
public final int getMessageHash() { if (hash == -1) { try { MimeMessage m = getMessage(); if (m == null) { // for anonymised DB return 0; } InputStream in = m.getInputStream(); long hash = 7; int c; while ((c = in.read()) != -1) { hash = (hash * 13L + c) % 2147483647L; } this.hash = (int) hash; } catch (Exception e) { getContext().error(e, "Error making message hash"); hash = -1; } } return hash; }
@Override public Object evaluate() throws TMLExpressionException { Binary b = (Binary) getOperand(0); DataSource ds = new BinaryDataSource(b); Navajo result = NavajoFactory.getInstance().createNavajo(); Message mail = NavajoFactory.getInstance().createMessage(result, "Mail"); result.addMessage(mail); Message parts = NavajoFactory.getInstance().createMessage(result, "Parts", Message.MSG_TYPE_ARRAY); mail.addMessage(parts); try { MimeMultipart mmp = getMultipartMessage(ds); if (mmp != null) { for (int i = 0; i < mmp.getCount(); i++) { BodyPart bp = mmp.getBodyPart(i); String type = bp.getContentType(); Binary partBinary = new Binary(bp.getInputStream(), false); if (i == 0) { // Property content = NavajoFactory.getInstance().createProperty(result, "Content", // Property.BINARY_PROPERTY, null, 0,"",Property.DIR_OUT); Property mimeType = NavajoFactory.getInstance() .createProperty( result, "ContentType", Property.STRING_PROPERTY, type, 0, "", Property.DIR_OUT); // mail.addProperty(content); mail.addProperty(mimeType); // content.setAnyValue(partBinary); partBinary.setMimeType(type); } Message element = parts.addElement( NavajoFactory.getInstance() .createMessage(result, "Parts", Message.MSG_TYPE_ARRAY_ELEMENT)); Property content = NavajoFactory.getInstance() .createProperty( result, "Content", Property.BINARY_PROPERTY, null, 0, "", Property.DIR_OUT); element.addProperty(content); Property mimeType = NavajoFactory.getInstance() .createProperty( result, "ContentType", Property.STRING_PROPERTY, type, 0, "", Property.DIR_OUT); element.addProperty(mimeType); content.setAnyValue(partBinary); partBinary.setMimeType(type); content.addSubType("browserMime=" + type); } } else { String type = b.guessContentType(); MimeMessage mm = new MimeMessage(Session.getDefaultInstance(new Properties()), b.getDataAsStream()); // mm.get Binary body = new Binary(mm.getInputStream(), false); // mm.getC Message element = parts.addElement( NavajoFactory.getInstance() .createMessage(result, "Parts", Message.MSG_TYPE_ARRAY_ELEMENT)); Property content = NavajoFactory.getInstance() .createProperty( result, "Content", Property.BINARY_PROPERTY, null, 0, "", Property.DIR_OUT); element.addProperty(content); Property mimeType = NavajoFactory.getInstance() .createProperty( result, "ContentType", Property.STRING_PROPERTY, type, 0, "", Property.DIR_OUT); Property messageMimeType = NavajoFactory.getInstance() .createProperty( result, "ContentType", Property.STRING_PROPERTY, type, 0, "", Property.DIR_OUT); mail.addProperty(messageMimeType); element.addProperty(mimeType); content.setAnyValue(body); b.setMimeType(mm.getContentType()); content.addSubType("browserMime=" + type); } return result; } catch (MessagingException e) { logger.error("Error: ", e); } catch (IOException e) { logger.error("Error: ", e); } return null; }