aboutsummaryrefslogtreecommitdiff
path: root/juick-api/src/main/java/com/juick/api/controllers
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-01-05 11:44:40 +0300
committerGravatar Vitaly Takmazov2018-01-05 11:44:40 +0300
commit4f2f63dbda970c06e63f444e11e29da483961843 (patch)
treef14238dc6debe5f8fa9a4907df536b5fa70dce2e /juick-api/src/main/java/com/juick/api/controllers
parentd5a737bd5b1155cdbb80ab3d2927113c0d385bd6 (diff)
email: parse In-Reply-To
Diffstat (limited to 'juick-api/src/main/java/com/juick/api/controllers')
-rw-r--r--juick-api/src/main/java/com/juick/api/controllers/Post.java11
1 files changed, 11 insertions, 0 deletions
diff --git a/juick-api/src/main/java/com/juick/api/controllers/Post.java b/juick-api/src/main/java/com/juick/api/controllers/Post.java
index 33d83d2c..032b549b 100644
--- a/juick-api/src/main/java/com/juick/api/controllers/Post.java
+++ b/juick-api/src/main/java/com/juick/api/controllers/Post.java
@@ -52,6 +52,7 @@ import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Paths;
import java.util.Properties;
+import java.util.Scanner;
import java.util.UUID;
/**
@@ -210,6 +211,7 @@ public class Post {
String from = msg.getFrom().length > 1 ? ((InternetAddress) msg.getSender()).getAddress()
: ((InternetAddress) msg.getFrom()[0]).getAddress();
logger.info("got msg from {}", from);
+
User visitor = userService.getUserByEmail(from);
if (!visitor.isAnonymous()) {
MimeMessageParser parser = new MimeMessageParser(msg);
@@ -248,6 +250,15 @@ public class Post {
logger.info("attachment error: {}", e);
}
});
+ String[] inReplyToHeaders = msg.getHeader("In-Reply-To");
+ if (inReplyToHeaders != null && inReplyToHeaders.length > 0) {
+ Scanner inReplyToScanner = new Scanner(inReplyToHeaders[0].trim()).useDelimiter("\\.|@|<");
+ int mid = Integer.parseInt(inReplyToScanner.next());
+ int rid = Integer.parseInt(inReplyToScanner.next());
+ logger.info("Message is reply to #%d/%d", mid, rid);
+ body[0] = rid > 0 ? String.format("#%d/%d %s", mid, rid, body[0])
+ : String.format("#%d %s", mid, body[0]);
+ }
rocks.xmpp.core.stanza.model.Message xmsg = new rocks.xmpp.core.stanza.model.Message();
xmsg.setType(rocks.xmpp.core.stanza.model.Message.Type.CHAT);
xmsg.setFrom(Jid.of(String.valueOf(visitor.getUid()), "uid.juick.com", "mail"));