private void expect(Class<?> c) { if (!c.isInstance(stack.peek())) { throw new IllegalStateException( "Internal stack error: " + "Expected '" + c.getName() + "' found '" + stack.peek().getClass().getName() + "'"); } }
public void preamble(InputStream is) throws IOException { expect(MimeMultipart.class); StringBuffer sb = new StringBuffer(); int b; while ((b = is.read()) != -1) { sb.append((char) b); } ((MimeMultipart) stack.peek()).setPreamble(sb.toString()); }
public void body(BodyDescriptor bd, InputStream in) throws IOException { expect(Part.class); Body body = MimeUtility.decodeBody(in, bd.getTransferEncoding()); try { ((Part) stack.peek()).setBody(body); } catch (MessagingException me) { throw new Error(me); } }
public void field(String fieldData) { expect(Part.class); try { String[] tokens = fieldData.split(":", 2); ((Part) stack.peek()).addHeader(tokens[0], tokens[1].trim()); } catch (MessagingException me) { throw new Error(me); } }
public void startBodyPart() { expect(MimeMultipart.class); try { MimeBodyPart bodyPart = new MimeBodyPart(); ((MimeMultipart) stack.peek()).addBodyPart(bodyPart); stack.push(bodyPart); } catch (MessagingException me) { throw new Error(me); } }
public void field(RawField field) { expect(Part.class); try { Field parsedField = DefaultFieldParser.parse(field.getRaw(), null); ((Part) stack.peek()).addHeader(parsedField.getName(), parsedField.getBody().trim()); } catch (MessagingException me) { throw new Error(me); } catch (MimeException me) { throw new Error(me); } }
public void startMultipart(BodyDescriptor bd) { expect(Part.class); Part e = (Part) stack.peek(); try { MimeMultipart multiPart = new MimeMultipart(e.getContentType()); e.setBody(multiPart); stack.push(multiPart); } catch (MessagingException me) { throw new Error(me); } }
public void startMessage() { if (stack.isEmpty()) { stack.push(MimeMessage.this); } else { expect(Part.class); try { MimeMessage m = new MimeMessage(); ((Part) stack.peek()).setBody(m); stack.push(m); } catch (MessagingException me) { throw new Error(me); } } }