aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/server/api
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/server/api')
-rw-r--r--src/main/java/com/juick/server/api/Service.java29
1 files changed, 25 insertions, 4 deletions
diff --git a/src/main/java/com/juick/server/api/Service.java b/src/main/java/com/juick/server/api/Service.java
index 144b5bec..2a86c5e7 100644
--- a/src/main/java/com/juick/server/api/Service.java
+++ b/src/main/java/com/juick/server/api/Service.java
@@ -1,11 +1,14 @@
package com.juick.server.api;
+import com.juick.Message;
import com.juick.User;
+import com.juick.model.CommandResult;
import com.juick.server.CommandsManager;
import com.juick.server.EmailManager;
import com.juick.server.ServerManager;
import com.juick.server.util.HttpForbiddenException;
import com.juick.service.EmailService;
+import com.juick.service.MessagesService;
import com.juick.service.UserService;
import com.juick.service.security.annotation.Visitor;
import org.apache.commons.codec.digest.DigestUtils;
@@ -46,6 +49,8 @@ public class Service {
@Inject
private EmailService emailService;
@Inject
+ private MessagesService messagesService;
+ @Inject
private CommandsManager commandsManager;
@Inject
private EmailManager emailManager;
@@ -116,16 +121,32 @@ public class Service {
});
String[] inReplyToHeaders = msg.getHeader("In-Reply-To");
if (inReplyToHeaders != null && inReplyToHeaders.length > 0) {
- Scanner inReplyToScanner = new Scanner(inReplyToHeaders[0].trim()).useDelimiter(EmailManager.MSGID_PATTERN);
- int mid = Integer.parseInt(inReplyToScanner.next());
- int rid = Integer.parseInt(inReplyToScanner.next());
+ int mid, rid;
+ var originalMessage = messagesService.findMessageByProperty("messageId", inReplyToHeaders[0]);
+ if (originalMessage.isPresent()) {
+ mid = originalMessage.get().getLeft();
+ rid = originalMessage.get().getRight();
+ } else {
+ Scanner inReplyToScanner = new Scanner(inReplyToHeaders[0].trim()).useDelimiter(EmailManager.MSGID_PATTERN);
+ mid = Integer.parseInt(inReplyToScanner.next());
+ rid = Integer.parseInt(inReplyToScanner.next());
+ }
logger.info("Message is reply to #{}/{}", mid, rid);
body[0] = rid > 0 ? String.format("#%d/%d %s", mid, rid, body[0])
: String.format("#%d %s", mid, body[0]);
}
URI attachmentUri = StringUtils.isNotEmpty(attachmentFName[0]) ? URI.create(String.format("juick://%s", attachmentFName[0]))
: URI.create(StringUtils.EMPTY);
- commandsManager.processCommand(visitor, body[0], attachmentUri);
+ CommandResult result = commandsManager.processCommand(visitor, body[0], attachmentUri);
+ if (result.getNewMessage().isPresent()) {
+ String[] messageIds = msg.getHeader("Message-Id");
+ if (messageIds.length == 1) {
+ Message message = result.getNewMessage().get();
+ messagesService.setMessageProperty(message.getMid(), message.getRid(), "messageId", messageIds[0]);
+ } else {
+ logger.warn("Wrong number of Message-Id headers");
+ }
+ }
} else {
if (!Arrays.asList(ignoredEmails).contains(from)) {
String verificationCode = RandomStringUtils.randomAlphanumeric(8).toUpperCase();