MimeHelper { public static BodyPartIterator createBodyPartIterator(AdaptrisMessage msg) throws IOException, MessagingException { BodyPartIterator result = null; try (InputStream in = msg.getInputStream()) { result = new BodyPartIterator(in); } catch (Exception e) { String mimeBoundary = getBoundary(msg); result = createBodyPartIterator(mimeFaker(msg, mimeBoundary)); } if (result == null) { throw new IOException("Could not parse " + msg.getUniqueId() + " into a standard MIME Multipart"); } return result; }  static ByteArrayIterator createByteArrayIterator(AdaptrisMessage msg); static BodyPartIterator createBodyPartIterator(AdaptrisMessage msg);  }
@Test public void testBodyPartIterator_CreateFromFake() throws Exception { BodyPartIterator m = MimeHelper.createBodyPartIterator(AdaptrisMessageFactory.getDefaultInstance().newMessage(MIME_PAYLOAD)); assertNotNull(m); assertEquals(2, m.size()); }
@Test public void testBodyPartIterator_CreateFromReal() throws Exception { BodyPartIterator m = MimeHelper .createBodyPartIterator(AdaptrisMessageFactory.getDefaultInstance().newMessage(MIME_HEADER + "\r\n\r\n" + MIME_PAYLOAD)); assertNotNull(m); assertEquals(2, m.size()); }
@Test public void testBodyPartIterator_CreateFromInvalid() throws Exception { try { BodyPartIterator m = MimeHelper.createBodyPartIterator(AdaptrisMessageFactory.getDefaultInstance().newMessage("AAAAAAAA")); fail("Failed"); } catch (Exception expected) { } }