/** * <p>Gets a descriptor for the current entity. * This method is valid if {@link #getState()} returns:</p> * <ul> * <li>{@link EntityState#T_BODY}</li> * <li>{@link EntityState#T_START_MULTIPART}</li> * <li>{@link EntityState#T_EPILOGUE}</li> * <li>{@link EntityState#T_PREAMBLE}</li> * </ul> * @return <code>BodyDescriptor</code>, not nulls */ public BodyDescriptor getBodyDescriptor() { return currentStateMachine.getBodyDescriptor(); }
/** * This method returns the raw entity, preamble, or epilogue contents. * <p/> * This method is valid, if {@link #getState()} returns either of * {@link EntityState#T_RAW_ENTITY}, {@link EntityState#T_PREAMBLE}, or * {@link EntityState#T_EPILOGUE}. * * @return Data stream, depending on the current state. * @throws IllegalStateException {@link #getState()} returns an * invalid value. */ public InputStream getInputStream() { return currentStateMachine.getContentStream(); }
/** * This method returns a transfer decoded stream based on the MIME * fields with the standard defaults. * <p/> * This method is valid, if {@link #getState()} returns either of * {@link EntityState#T_RAW_ENTITY}, {@link EntityState#T_PREAMBLE}, or * {@link EntityState#T_EPILOGUE}. * * @return Data stream, depending on the current state. * @throws IllegalStateException {@link #getState()} returns an * invalid value. */ public InputStream getDecodedInputStream() { return currentStateMachine.getDecodedContentStream(); }
/** * This method advances the token stream to the next token. * @throws IllegalStateException The method has been called, although * {@link #getState()} was already {@link EntityState#T_END_OF_STREAM}. */ public EntityState next() throws IOException, MimeException { if (state == EntityState.T_END_OF_STREAM || currentStateMachine == null) { throw new IllegalStateException("No more tokens are available."); } while (currentStateMachine != null) { EntityStateMachine next = currentStateMachine.advance(); if (next != null) { entities.add(next); currentStateMachine = next; } state = currentStateMachine.getState(); if (state != EntityState.T_END_OF_STREAM) { return state; } entities.removeLast(); if (entities.isEmpty()) { currentStateMachine = null; } else { currentStateMachine = entities.getLast(); currentStateMachine.setRecursionMode(recursionMode); } } state = EntityState.T_END_OF_STREAM; return state; }
/** * This method is valid, if {@link #getState()} returns {@link EntityState#T_FIELD}. * @return String with the fields raw contents. * @throws IllegalStateException {@link #getState()} returns another * value than {@link EntityState#T_FIELD}. */ public Field getField() { return currentStateMachine.getField(); }
/** * Sets the current recursion. * The recursion mode specifies the approach taken to parsing parts. * {@link RecursionMode#M_RAW} mode does not parse the part at all. * {@link RecursionMode#M_RECURSE} mode recursively parses each mail * when an <code>message/rfc822</code> part is encountered; * {@link RecursionMode#M_NO_RECURSE} does not. * @param mode {@link RecursionMode#M_RECURSE}, {@link RecursionMode#M_RAW} or * {@link RecursionMode#M_NO_RECURSE} */ public void setRecursionMode(RecursionMode mode) { recursionMode = mode; if (currentStateMachine != null) { currentStateMachine.setRecursionMode(mode); } }
private void doParse(InputStream stream, EntityState start) { if (config.isCountLineNumbers()) { LineNumberInputStream lnstream = new LineNumberInputStream(stream); rootentity = new MimeEntity( lnstream, lnstream, config, start, EntityState.T_END_MESSAGE, monitor, fieldBuilder, bodyDescBuilder); } else { rootentity = new MimeEntity( null, stream, config, start, EntityState.T_END_MESSAGE, monitor, fieldBuilder, bodyDescBuilder); } rootentity.setRecursionMode(recursionMode); currentStateMachine = rootentity; entities.clear(); entities.add(currentStateMachine); state = currentStateMachine.getState(); }