public Builder parse(final InputStream is) throws IOException { MimeConfig currentConfig = config != null ? config : MimeConfig.DEFAULT; boolean strict = currentConfig.isStrictParsing(); DecodeMonitor currentMonitor = monitor != null ? monitor : strict ? DecodeMonitor.STRICT : DecodeMonitor.SILENT; BodyDescriptorBuilder currentBodyDescBuilder = bodyDescBuilder != null ? bodyDescBuilder : new DefaultBodyDescriptorBuilder(null, fieldParser != null ? fieldParser : strict ? DefaultFieldParser.getParser() : LenientFieldParser.getParser(), currentMonitor); BodyFactory currentBodyFactory = bodyFactory != null ? bodyFactory : new BasicBodyFactory(!strict); MimeStreamParser parser = new MimeStreamParser(currentConfig, currentMonitor, currentBodyDescBuilder); Message message = new MessageImpl(); parser.setContentHandler(new ParserStreamContentHandler(message, currentBodyFactory)); parser.setContentDecoding(!rawContent); if (flatMode) { parser.setFlat(); } try { parser.parse(is); } catch (MimeException e) { throw new MimeIOException(e); } clearFields(); final List<Field> fields = message.getHeader().getFields(); for (Field field: fields) { addField(field); } setBody(message.getBody()); return this; }
public Builder copy(Message other) { if (other == null) { return this; } clearFields(); final Header otherHeader = other.getHeader(); if (otherHeader != null) { final List<Field> otherFields = otherHeader.getFields(); for (Field field: otherFields) { addField(field); } } Body body = null; Body otherBody = other.getBody(); if (otherBody instanceof Message) { body = Builder.of((Message) otherBody).build(); } else if (otherBody instanceof Multipart) { body = MultipartBuilder.createCopy((Multipart) otherBody).build(); } else if (otherBody instanceof SingleBody) { body = ((SingleBody) otherBody).copy(); } setBody(body); return this; }
public MessageBuilder clearFields() { builder.clearFields(); return this; }