@Override public void startMultipart(BodyDescriptor bd) throws MimeException { Part part = (Part) stack.peek(); String mimeType = bd.getMimeType(); String boundary = bd.getBoundary(); MimeMultipart multipart = new MimeMultipart(mimeType, boundary); part.setBody(multipart); stack.push(multipart); }
@Override public void body(BodyDescriptor bd, InputStream in) throws IOException, MimeException { expect(Part.class); Body body = bodyFactory.createBody(bd.getTransferEncoding(), bd.getMimeType(), in); ((Part)stack.peek()).setBody(body); }
submd.set(Metadata.CONTENT_TYPE, body.getMimeType()); submd.set(Metadata.CONTENT_ENCODING, body.getCharset()); submd.set(Message.MULTIPART_SUBTYPE, parts.peek().getSubType()); submd.set(Message.MULTIPART_BOUNDARY, parts.peek().getBoundary());
@Override public void startMultipart(BodyDescriptor descr) throws MimeException { parts.push(descr); if (! extractAllAlternatives) { if (alternativePartBuffer.size() == 0 && MULTIPART_ALTERNATIVE.equalsIgnoreCase(descr.getMimeType())) { Part part = new Part(descr); alternativePartBuffer.push(part); } else if (alternativePartBuffer.size() > 0) { //add the part to the stack Part parent = alternativePartBuffer.peek(); Part part = new Part(descr); alternativePartBuffer.push(part); if (parent != null) { parent.children.add(part); } } } }
public void body(BodyDescriptor bd, final InputStream is) throws MimeException, IOException { expect(Entity.class); final Body body; if (bd.getMimeType().startsWith("text/")) { body = bodyFactory.textBody(is, bd.getCharset()); } else { body = bodyFactory.binaryBody(is); } Entity entity = ((Entity) stack.peek()); entity.setBody(body); }
@Override public void body(BodyDescriptor bd, InputStream inputStream) throws MimeException, IOException { Part part = (Part) stack.peek(); String transferEncoding = bd.getTransferEncoding(); Body body = createBody(inputStream, transferEncoding, fileFactory); part.setBody(body); }
log.debug("subType: {}", bd.getSubType()); log.debug("body-length is {} bytes", bd.getContentLength());
/** * Gets a reader configured for the current body or body part. * The reader will return a transfer and charset decoded * stream of characters based on the MIME fields with the standard * defaults. * This is a conveniance method and relies on {@link #getInputStream()}. * Consult the javadoc for that method for known limitations. * * @return <code>Reader</code>, not null * @see #getInputStream * @throws IllegalStateException {@link #getState()} returns an * invalid value * @throws UnsupportedEncodingException if there is no JVM support * for decoding the charset */ public Reader getReader() throws UnsupportedEncodingException { final BodyDescriptor bodyDescriptor = getBodyDescriptor(); final String mimeCharset = bodyDescriptor.getCharset(); final Charset charset; if (mimeCharset == null || "".equals(mimeCharset)) { charset = Charsets.US_ASCII; } else { charset = CharsetUtil.lookup(mimeCharset); if (charset == null) { throw new UnsupportedEncodingException(mimeCharset); } } final InputStream instream = getDecodedInputStream(); return new InputStreamReader(instream, charset); }
private void createMimePartStream() throws MimeException, IOException { String boundary = body.getBoundary(); if (boundary == null) { throw new MimeException("Multipart body does not have a valid boundary"); } try { currentMimePartStream = new MimeBoundaryInputStream(inbuffer, boundary, config.isStrictParsing()); } catch (IllegalArgumentException e) { // thrown when boundary is too long throw new MimeException(e.getMessage(), e); } dataStream = new LineReaderInputStreamAdaptor( currentMimePartStream, config.getMaxLineLen()); }
public void startMultipart(final BodyDescriptor bd) throws MimeException { expect(Entity.class); final Entity e = (Entity) stack.peek(); final String subType = bd.getSubType(); final Multipart multiPart = new MultipartImpl(subType); e.setBody(multiPart); stack.push(multiPart); }
submd.set(Metadata.CONTENT_TYPE, body.getMimeType()); submd.set(Metadata.CONTENT_ENCODING, body.getCharset()); submd.set(Message.MULTIPART_SUBTYPE, parts.peek().getSubType()); submd.set(Message.MULTIPART_BOUNDARY, parts.peek().getBoundary());
private void handleBestParts(Part part) throws MimeException, IOException { if (part == null) { return; } if (part instanceof BodyContents) { handleInlineBodyPart((BodyContents)part); return; } if (MULTIPART_ALTERNATIVE.equalsIgnoreCase(part.bodyDescriptor.getMimeType())) { int bestPartScore = -1; Part bestPart = null; for (Part alternative : part.children) { int score = score(alternative); if (score > bestPartScore) { bestPart = alternative; bestPartScore = score; } } handleBestParts(bestPart); } else { for (Part child : part.children) { handleBestParts(child); } } }
public void body(BodyDescriptor body, InputStream is) throws MimeException, IOException { // use a different metadata object // in order to specify the mime type of the // sub part without damaging the main metadata Metadata submd = new Metadata(); submd.set(Metadata.CONTENT_TYPE, body.getMimeType()); submd.set(Metadata.CONTENT_ENCODING, body.getCharset()); try { if (extractor.shouldParseEmbedded(submd)) { // Wrap the InputStream before passing on, as the James provided // one misses many features we might want eg mark/reset TikaInputStream tis = TikaInputStream.get(is); extractor.parseEmbedded(tis, handler, submd, false); } } catch (SAXException e) { throw new MimeException(e); } }
private InputStream decodedStream(InputStream instream) { String transferEncoding = body.getTransferEncoding(); if (MimeUtil.isBase64Encoding(transferEncoding)) { instream = new Base64InputStream(instream, monitor); } else if (MimeUtil.isQuotedPrintableEncoded(transferEncoding)) { instream = new QuotedPrintableInputStream(instream, monitor); } return instream; }
@Override public void body(BodyDescriptor bodyDescriptor, InputStream inputStream) throws MimeException, IOException { if (bodyDescriptor.getMimeType().equalsIgnoreCase("message/disposition-notification")) { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; while ((line = reader.readLine()) != null) { if (line.startsWith("Disposition:")) { if (line.contains("MDN-sent-automatically") || line.contains("automatic-action")) { resultCollector.setResult(true); } } } } } } };
@Override public void startMultipart(BodyDescriptor bd) throws MimeException { expect(Part.class); Part e = (Part)stack.peek(); String mimeType = bd.getMimeType(); String boundary = bd.getBoundary(); MimeMultipart multiPart = new MimeMultipart(mimeType, boundary); e.setBody(multiPart); stack.addFirst(multiPart); }
@Override public void startMultipart(BodyDescriptor descr) throws MimeException { parts.push(descr); if (! extractAllAlternatives) { if (alternativePartBuffer.size() == 0 && MULTIPART_ALTERNATIVE.equalsIgnoreCase(descr.getMimeType())) { Part part = new Part(descr); alternativePartBuffer.push(part); } else if (alternativePartBuffer.size() > 0) { //add the part to the stack Part parent = alternativePartBuffer.peek(); Part part = new Part(descr); alternativePartBuffer.push(part); if (parent != null) { parent.children.add(part); } } } }
@Override public String toString() { return getClass().getName() + " [" + stateToString(state) + "][" + body.getMimeType() + "][" + body.getBoundary() + "]"; }
private void handleBestParts(Part part) throws MimeException, IOException { if (part == null) { return; } if (part instanceof BodyContents) { handleInlineBodyPart((BodyContents)part); return; } if (MULTIPART_ALTERNATIVE.equalsIgnoreCase(part.bodyDescriptor.getMimeType())) { int bestPartScore = -1; Part bestPart = null; for (Part alternative : part.children) { int score = score(alternative); if (score > bestPartScore) { bestPart = alternative; bestPartScore = score; } } handleBestParts(bestPart); } else { for (Part child : part.children) { handleBestParts(child); } } }
case T_EPILOGUE: case T_BODY: if (contentTypes.isEmpty() || contentTypes.contains(parser.getBodyDescriptor().getMimeType())) { if (checkBody(buffer, parser)) { return true;