@Test public void generateMDNMessageShouldFailOnMissingDisposition() throws Exception { String senderAddress = "sender@local"; Message originMessage = Message.Builder.of() .setMessageId("45554@local.com") .setFrom(senderAddress) .setBody("body", StandardCharsets.UTF_8) .addField(new RawField(JmapMDN.RETURN_PATH, "<" + senderAddress + ">")) .build(); assertThatThrownBy(() -> MDN.generateMDNMessage(originMessage, MAILBOX_SESSION)) .isInstanceOf(InvalidOriginMessageForMDNException.class); }
.addField(new RawField("Great-Header", "message 3 subject")) .setBody("my message", StandardCharsets.UTF_8) .build();
@Test public void generateMDNMessageShouldUseDispositionHeaders() throws Exception { String senderAddress = "sender@local"; Message originMessage = Message.Builder.of() .setMessageId("45554@local.com") .setFrom(senderAddress) .setBody("body", StandardCharsets.UTF_8) .addField(new RawField(JmapMDN.RETURN_PATH, "<" + senderAddress + ">")) .addField(new RawField(JmapMDN.DISPOSITION_NOTIFICATION_TO, "<" + senderAddress + ">")) .build(); assertThat( MDN.generateMDNMessage(originMessage, MAILBOX_SESSION) .getTo()) .extracting(address -> (Mailbox) address) .extracting(Mailbox::getAddress) .containsExactly(senderAddress); }
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 addField(Field field) { builder.addField(field); return this; }
private void addHeader(Message.Builder messageBuilder, String fieldName, String value) { FieldParser<UnstructuredField> parser = UnstructuredFieldImpl.PARSER; RawField rawField = new RawField(fieldName, value); messageBuilder.addField(parser.parse(rawField, DecodeMonitor.SILENT)); }