@Test public void testBadHeaderNames() { String[] bad = new String[] { "Foo\\Bar: value\r\n", "Foo@Bar: value\r\n", "Foo,Bar: value\r\n", "Foo}Bar: value\r\n", "Foo{Bar: value\r\n", "Foo=Bar: value\r\n", "Foo>Bar: value\r\n", "Foo<Bar: value\r\n", "Foo)Bar: value\r\n", "Foo(Bar: value\r\n", "Foo?Bar: value\r\n", "Foo\"Bar: value\r\n", "Foo/Bar: value\r\n", "Foo]Bar: value\r\n", "Foo[Bar: value\r\n", "\u0192\u00f8\u00f8\u00df\u00e5\u00ae: value\r\n" }; for (String s : bad) { ByteBuffer buffer = BufferUtils.toBuffer( "--AaB03x\r\n" + s + "\r\n--AaB03x--\r\n"); MultiPartParser.Handler handler = new TestHandler(); MultiPartParser parser = new MultiPartParser(handler, "AaB03x"); try { parser.parse(buffer, true); } catch (BadMessageException e) { assertTrue(e.getMessage().contains("Illegal character")); } } }
public boolean parse(ByteBuffer buffer, boolean last) { boolean handle = false; while (!handle && BufferUtils.hasContent(buffer)) { switch (state) { case PREAMBLE: parsePreamble(buffer); continue; case DELIMITER: case DELIMITER_PADDING: case DELIMITER_CLOSE: parseDelimiter(buffer); continue; case BODY_PART: handle = parseMimePartHeaders(buffer); break; case FIRST_OCTETS: case OCTETS: handle = parseOctetContent(buffer); break; case EPILOGUE: BufferUtils.clear(buffer); break; case END: handle = true; break; default: throw new IllegalStateException(); } } if (last && BufferUtils.isEmpty(buffer)) { if (state == State.EPILOGUE) { state = State.END; if (LOG.isDebugEnabled()) LOG.debug("messageComplete {}", this); return handler.messageComplete(); } else { if (LOG.isDebugEnabled()) LOG.debug("earlyEOF {}", this); handler.earlyEOF(); return true; } } return handle; }
MultiPartParser { public boolean parse(ByteBuffer buffer, boolean last) { boolean handle = false; while (!handle && BufferUtils.hasContent(buffer)) { switch (state) { case PREAMBLE: parsePreamble(buffer); continue; case DELIMITER: case DELIMITER_PADDING: case DELIMITER_CLOSE: parseDelimiter(buffer); continue; case BODY_PART: handle = parseMimePartHeaders(buffer); break; case FIRST_OCTETS: case OCTETS: handle = parseOctetContent(buffer); break; case EPILOGUE: BufferUtils.clear(buffer); break; case END: handle = true; break; default: throw new IllegalStateException(); } } if (last && BufferUtils.isEmpty(buffer)) { if (state == State.EPILOGUE) { state = State.END; if (LOG.isDebugEnabled()) LOG.debug("messageComplete {}", this); return handler.messageComplete(); } else { if (LOG.isDebugEnabled()) LOG.debug("earlyEOF {}", this); handler.earlyEOF(); return true; } } return handle; } }
MultiPartParser { public boolean parse(ByteBuffer buffer, boolean last) { boolean handle = false; while (!handle && BufferUtils.hasContent(buffer)) { switch (state) { case PREAMBLE: parsePreamble(buffer); continue; case DELIMITER: case DELIMITER_PADDING: case DELIMITER_CLOSE: parseDelimiter(buffer); continue; case BODY_PART: handle = parseMimePartHeaders(buffer); break; case FIRST_OCTETS: case OCTETS: handle = parseOctetContent(buffer); break; case EPILOGUE: BufferUtils.clear(buffer); break; case END: handle = true; break; default: throw new IllegalStateException(); } } if (last && BufferUtils.isEmpty(buffer)) { if (state == State.EPILOGUE) { state = State.END; if (LOG.isDebugEnabled()) LOG.debug("messageComplete {}", this); return handler.messageComplete(); } else { if (LOG.isDebugEnabled()) LOG.debug("earlyEOF {}", this); handler.earlyEOF(); return true; } } return handle; } MultiPartParser(Handler handler, String boundary); }
MultiPartParser { public boolean parse(ByteBuffer buffer, boolean last) { boolean handle = false; while (!handle && BufferUtils.hasContent(buffer)) { switch (state) { case PREAMBLE: parsePreamble(buffer); continue; case DELIMITER: case DELIMITER_PADDING: case DELIMITER_CLOSE: parseDelimiter(buffer); continue; case BODY_PART: handle = parseMimePartHeaders(buffer); break; case FIRST_OCTETS: case OCTETS: handle = parseOctetContent(buffer); break; case EPILOGUE: BufferUtils.clear(buffer); break; case END: handle = true; break; default: throw new IllegalStateException(); } } if (last && BufferUtils.isEmpty(buffer)) { if (state == State.EPILOGUE) { state = State.END; if (LOG.isDebugEnabled()) LOG.debug("messageComplete {}", this); return handler.messageComplete(); } else { if (LOG.isDebugEnabled()) LOG.debug("earlyEOF {}", this); handler.earlyEOF(); return true; } } return handle; } MultiPartParser(Handler handler, String boundary); void reset(); Handler getHandler(); State getState(); boolean isState(State state); boolean parse(ByteBuffer buffer, boolean last); @Override String toString(); }
MultiPartParser { public boolean parse(ByteBuffer buffer, boolean last) { boolean handle = false; while (!handle && BufferUtils.hasContent(buffer)) { switch (state) { case PREAMBLE: parsePreamble(buffer); continue; case DELIMITER: case DELIMITER_PADDING: case DELIMITER_CLOSE: parseDelimiter(buffer); continue; case BODY_PART: handle = parseMimePartHeaders(buffer); break; case FIRST_OCTETS: case OCTETS: handle = parseOctetContent(buffer); break; case EPILOGUE: BufferUtils.clear(buffer); break; case END: handle = true; break; default: throw new IllegalStateException(); } } if (last && BufferUtils.isEmpty(buffer)) { if (state == State.EPILOGUE) { state = State.END; if (LOG.isDebugEnabled()) LOG.debug("messageComplete {}", this); return handler.messageComplete(); } else { if (LOG.isDebugEnabled()) LOG.debug("earlyEOF {}", this); handler.earlyEOF(); return true; } } return handle; } MultiPartParser(Handler handler, String boundary); void reset(); Handler getHandler(); State getState(); boolean isState(State state); boolean parse(ByteBuffer buffer, boolean last); @Override String toString(); static final LazyLogger LOG; }