aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/juick/www/api/Service.java25
1 files changed, 17 insertions, 8 deletions
diff --git a/src/main/java/com/juick/www/api/Service.java b/src/main/java/com/juick/www/api/Service.java
index f7c7a4aa..81b24a23 100644
--- a/src/main/java/com/juick/www/api/Service.java
+++ b/src/main/java/com/juick/www/api/Service.java
@@ -36,6 +36,7 @@ import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
+import org.apache.commons.lang3.math.NumberUtils;
import org.apache.commons.mail.util.MimeMessageParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -140,7 +141,8 @@ public class Service {
try {
logger.info("got inputstream: {}", a.getInputStream());
FileOutputStream fos = new FileOutputStream(
- Paths.get(storageService.getTemporaryDirectory(), attachmentFName[0]).toString());
+ Paths.get(storageService.getTemporaryDirectory(), attachmentFName[0])
+ .toString());
IOUtils.copy(a.getInputStream(), fos);
fos.close();
} catch (IOException e) {
@@ -150,19 +152,26 @@ public class Service {
String[] inReplyToHeaders = msg.getHeader("In-Reply-To");
if (inReplyToHeaders != null && inReplyToHeaders.length > 0) {
int mid, rid;
- var originalMessage = messagesService.findMessageByProperty("messageId", inReplyToHeaders[0]);
+ String inReplyTo = inReplyToHeaders[0].trim();
+ var originalMessage = messagesService.findMessageByProperty("messageId", inReplyTo);
if (originalMessage.isPresent()) {
mid = originalMessage.get().getLeft();
rid = originalMessage.get().getRight();
} else {
- Scanner inReplyToScanner = new Scanner(inReplyToHeaders[0].trim())
+ Scanner inReplyToScanner = new Scanner(inReplyTo)
.useDelimiter(EmailManager.MSGID_PATTERN);
- mid = Integer.parseInt(inReplyToScanner.next());
- rid = Integer.parseInt(inReplyToScanner.next());
+ mid = NumberUtils.toInt(inReplyToScanner.next(), 0);
+ rid = NumberUtils.toInt(inReplyToScanner.next(), 0);
+ inReplyToScanner.close();
+ }
+ if (mid > 0) {
+ 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]);
+ } else {
+ logger.warn("Unknown In-Reply-To: {}", inReplyTo);
+ return;
}
- 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]))