Beispiel #1
0
 private void expect(Class<?> c) {
   if (!c.isInstance(stack.peek())) {
     throw new IllegalStateException(
         "Internal stack error: "
             + "Expected '"
             + c.getName()
             + "' found '"
             + stack.peek().getClass().getName()
             + "'");
   }
 }
Beispiel #2
0
    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);
      }
    }
Beispiel #3
0
    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);
      }
    }
Beispiel #4
0
 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);
     }
   }
 }
Beispiel #5
0
 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());
 }
Beispiel #6
0
 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);
   }
 }
Beispiel #7
0
 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);
   }
 }
Beispiel #8
0
 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);
   }
 }
Beispiel #9
0
 public void endBodyPart() {
   expect(BodyPart.class);
   stack.pop();
 }
Beispiel #10
0
 public void endMultipart() {
   stack.pop();
 }
Beispiel #11
0
 public void endMessage() {
   expect(MimeMessage.class);
   stack.pop();
 }