chibenwa commented on a change in pull request #515:
URL: https://github.com/apache/james-project/pull/515#discussion_r661177934
##########
File path:
mailbox/api/src/test/java/org/apache/james/mailbox/MailboxManagerTest.java
##########
@@ -144,6 +144,7 @@ void setUp() throws Exception {
this.subscriptionManager = provideSubscriptionManager();
this.message = Message.Builder.of()
+ .setMessageId("MimeMessageId")
Review comment:
We should IMO accept messages without MimeMessageId
##########
File path:
mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -87,11 +91,14 @@ public WithAttachment(MailboxSessionMapperFactory
mapperFactory, MessageId.Facto
}
@Override
- public Mono<Pair<MessageMetaData,
Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox
mailbox, Date internalDate, int size, int bodyStartOctet, Content content,
Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage,
MailboxSession session) throws MailboxException {
+ public Mono<Pair<MessageMetaData,
Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox
mailbox, Date internalDate, int size, int bodyStartOctet, Content content,
Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage,
MailboxSession session, HeaderImpl headers) throws MailboxException {
MessageMapper messageMapper =
mapperFactory.getMessageMapper(session);
MessageId messageId = messageIdFactory.generate();
- // TODO get mime message header fields
- ThreadId threadId =
threadIdGuessingAlgorithm.guessThreadId(session.getUser(), messageId, null,
null, null, null);
+ MimeMessageId mimeMessageId =
MimeMessageHeadersUtil.parseMimeMessageId(headers);
Review comment:
Optional IMO
##########
File path:
mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/MimeMessageHeadersUtil.java
##########
@@ -0,0 +1,58 @@
+/******************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ******************************************************************/
+
+package org.apache.james.mailbox.store.mail.utils;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.apache.james.mailbox.store.mail.model.MimeMessageId;
+import org.apache.james.mailbox.store.mail.model.Subject;
+import org.apache.james.mime4j.message.HeaderImpl;
+import org.apache.james.mime4j.stream.Field;
+
+public class MimeMessageHeadersUtil {
+ public static MimeMessageId parseMimeMessageId(HeaderImpl headers) {
+ return new MimeMessageId(headers.getField("Message-ID").getBody());
+ }
+
+ public static Optional<MimeMessageId> parseInReplyTo(HeaderImpl headers) {
+ Field inReplyToField = headers.getField("In-Reply-To");
+ if (inReplyToField != null) {
+ return Optional.of(new MimeMessageId(inReplyToField.getBody()));
+ }
+ return Optional.empty();
+ }
+
+ public static Optional<List<MimeMessageId>> parseReferences(HeaderImpl
headers) {
+ List<Field> mimeMessageIdFields = headers.getFields("References");
+ if (!mimeMessageIdFields.isEmpty()) {
+ List<MimeMessageId> mimeMessageIdList =
mimeMessageIdFields.stream()
+ .map(mimeMessageIdField -> new
MimeMessageId(mimeMessageIdField.getBody()))
+ .collect(Collectors.toList());
Review comment:
Guavate.toImmutableList()
##########
File path:
mailbox/store/src/main/java/org/apache/james/mailbox/store/MessageStorer.java
##########
@@ -147,11 +154,15 @@ public WithoutAttachment(MailboxSessionMapperFactory
mapperFactory, MessageId.Fa
}
@Override
- public Mono<Pair<MessageMetaData,
Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox
mailbox, Date internalDate, int size, int bodyStartOctet, Content content,
Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage,
MailboxSession session) throws MailboxException {
+ public Mono<Pair<MessageMetaData,
Optional<List<MessageAttachmentMetadata>>>> appendMessageToStore(Mailbox
mailbox, Date internalDate, int size, int bodyStartOctet, Content content,
Flags flags, PropertyBuilder propertyBuilder, Optional<Message> maybeMessage,
MailboxSession session, HeaderImpl headers) throws MailboxException {
MessageMapper messageMapper =
mapperFactory.getMessageMapper(session);
MessageId messageId = messageIdFactory.generate();
- // TODO get mime message header fields
- ThreadId threadId =
threadIdGuessingAlgorithm.guessThreadId(session.getUser(), messageId, null,
null, null, null);
+ MimeMessageId mimeMessageId =
MimeMessageHeadersUtil.parseMimeMessageId(headers);
+ Optional<MimeMessageId> inReplyTo =
MimeMessageHeadersUtil.parseInReplyTo(headers);
+ Optional<List<MimeMessageId>> references =
MimeMessageHeadersUtil.parseReferences(headers);
+ Subject subject = MimeMessageHeadersUtil.parseSubject(headers);
Review comment:
Idem, what if for any reason a message do not have a subject?
##########
File path:
mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/MimeMessageHeadersUtil.java
##########
@@ -0,0 +1,58 @@
+/******************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ******************************************************************/
+
+package org.apache.james.mailbox.store.mail.utils;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.apache.james.mailbox.store.mail.model.MimeMessageId;
+import org.apache.james.mailbox.store.mail.model.Subject;
+import org.apache.james.mime4j.message.HeaderImpl;
+import org.apache.james.mime4j.stream.Field;
+
+public class MimeMessageHeadersUtil {
+ public static MimeMessageId parseMimeMessageId(HeaderImpl headers) {
+ return new MimeMessageId(headers.getField("Message-ID").getBody());
+ }
+
+ public static Optional<MimeMessageId> parseInReplyTo(HeaderImpl headers) {
+ Field inReplyToField = headers.getField("In-Reply-To");
+ if (inReplyToField != null) {
Review comment:
Use Optional.ofNullable(...).map(...)
##########
File path:
mailbox/store/src/main/java/org/apache/james/mailbox/store/mail/utils/MimeMessageHeadersUtil.java
##########
@@ -0,0 +1,58 @@
+/******************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one *
+ * or more contributor license agreements. See the NOTICE file *
+ * distributed with this work for additional information *
+ * regarding copyright ownership. The ASF licenses this file *
+ * to you under the Apache License, Version 2.0 (the *
+ * "License"); you may not use this file except in compliance *
+ * with the License. You may obtain a copy of the License at *
+ * *
+ * http://www.apache.org/licenses/LICENSE-2.0 *
+ * *
+ * Unless required by applicable law or agreed to in writing, *
+ * software distributed under the License is distributed on an *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY *
+ * KIND, either express or implied. See the License for the *
+ * specific language governing permissions and limitations *
+ * under the License. *
+ ******************************************************************/
+
+package org.apache.james.mailbox.store.mail.utils;
+
+import java.util.List;
+import java.util.Optional;
+import java.util.stream.Collectors;
+
+import org.apache.james.mailbox.store.mail.model.MimeMessageId;
+import org.apache.james.mailbox.store.mail.model.Subject;
+import org.apache.james.mime4j.message.HeaderImpl;
+import org.apache.james.mime4j.stream.Field;
+
+public class MimeMessageHeadersUtil {
+ public static MimeMessageId parseMimeMessageId(HeaderImpl headers) {
+ return new MimeMessageId(headers.getField("Message-ID").getBody());
+ }
+
+ public static Optional<MimeMessageId> parseInReplyTo(HeaderImpl headers) {
+ Field inReplyToField = headers.getField("In-Reply-To");
+ if (inReplyToField != null) {
+ return Optional.of(new MimeMessageId(inReplyToField.getBody()));
+ }
+ return Optional.empty();
+ }
+
+ public static Optional<List<MimeMessageId>> parseReferences(HeaderImpl
headers) {
+ List<Field> mimeMessageIdFields = headers.getFields("References");
+ if (!mimeMessageIdFields.isEmpty()) {
+ List<MimeMessageId> mimeMessageIdList =
mimeMessageIdFields.stream()
+ .map(mimeMessageIdField -> new
MimeMessageId(mimeMessageIdField.getBody()))
+ .collect(Collectors.toList());
+ return Optional.of(mimeMessageIdList);
+ }
+ return Optional.empty();
+ }
+
+ public static Subject parseSubject(HeaderImpl headers) {
+ return new Subject(headers.getField("Subject").getBody());
Review comment:
`UnstructuredFieldImpl::getValue`
(We need to handle possible encoded characters IMO cf
HeaderCollectionTest::getHeadersShouldDecodeValues)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]