@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 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 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); }
@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); } } } }
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); } } }
submd.set(Metadata.CONTENT_TYPE, body.getMimeType()); submd.set(Metadata.CONTENT_ENCODING, body.getCharset());
@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 String toString() { return getClass().getName() + " [" + stateToString(state) + "][" + body.getMimeType() + "][" + body.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); }
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); } } }
submd.set(Metadata.CONTENT_TYPE, body.getMimeType()); submd.set(Metadata.CONTENT_ENCODING, body.getCharset());
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); } }
case T_EPILOGUE: case T_BODY: if (contentTypes.isEmpty() || contentTypes.contains(parser.getBodyDescriptor().getMimeType())) { if (checkBody(buffer, parser)) { return true;
case T_END_HEADER: body = bodyDescBuilder.build(); String mimeType = body.getMimeType(); if (recursionMode == RecursionMode.M_FLAT) { state = EntityState.T_BODY;