aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-09-27 09:29:33 +0300
committerGravatar Vitaly Takmazov2018-09-27 09:29:46 +0300
commit32869acec73653b6b62b35841845e9c732133571 (patch)
tree971b0c3c841d0f1d132376251e7b38859e64b337
parenta6537a1349de14f9fb457d7abb14147c7a0795b2 (diff)
RFC8058: One-Click Functionality for List Email Headers
-rw-r--r--juick-server/src/main/java/com/juick/server/EmailManager.java3
-rw-r--r--juick-server/src/main/java/com/juick/server/www/controllers/Settings.java20
-rw-r--r--juick-server/src/test/java/com/juick/server/tests/ServerTests.java9
3 files changed, 30 insertions, 2 deletions
diff --git a/juick-server/src/main/java/com/juick/server/EmailManager.java b/juick-server/src/main/java/com/juick/server/EmailManager.java
index d6c2bb3f..67c21d1c 100644
--- a/juick-server/src/main/java/com/juick/server/EmailManager.java
+++ b/juick-server/src/main/java/com/juick/server/EmailManager.java
@@ -123,8 +123,9 @@ public class EmailManager implements ApplicationListener<MessageEvent> {
message.setContent(multipart);
User emailUser = userService.getUserByEmail(to);
if (!emailUser.isAnonymous()) {
- message.setHeader("List-Unsubscribe", String.format("https://juick.com/settings?hash=%s",
+ message.setHeader("List-Unsubscribe", String.format("https://juick.com/settings/unsubscribe?hash=%s",
userService.getHashByUID(emailUser.getUid())));
+ message.setHeader("List-Unsubscribe-Post", "List-Unsubscribe=One-Click");
}
message.saveChanges();
transport.connect();
diff --git a/juick-server/src/main/java/com/juick/server/www/controllers/Settings.java b/juick-server/src/main/java/com/juick/server/www/controllers/Settings.java
index 6405b3bd..cc8f43eb 100644
--- a/juick-server/src/main/java/com/juick/server/www/controllers/Settings.java
+++ b/juick-server/src/main/java/com/juick/server/www/controllers/Settings.java
@@ -16,9 +16,12 @@
*/
package com.juick.server.www.controllers;
+import com.juick.User;
import com.juick.model.NotifyOpts;
import com.juick.model.UserInfo;
-import com.juick.server.util.*;
+import com.juick.server.util.HttpBadRequestException;
+import com.juick.server.util.HttpUtils;
+import com.juick.server.util.UserUtils;
import com.juick.service.*;
import org.apache.commons.lang3.RandomStringUtils;
import org.apache.commons.lang3.StringUtils;
@@ -257,4 +260,19 @@ public class Settings {
model.addAttribute("result", result);
return "views/settings_result";
}
+ @PostMapping("/settings/unsubscribe")
+ public String unsubscribeOneClick(@RequestParam(name = "List-Unsubscribe") String unsubscribe,
+ ModelMap model) {
+ User user = UserUtils.getCurrentUser();
+ if (!user.isAnonymous()) {
+ if (unsubscribe.equals("One-Click")) {
+ emailService.setNotificationsEmail(user.getUid(), StringUtils.EMPTY);
+ model.addAttribute("title", "Настройки");
+ model.addAttribute("visitor", user);
+ model.addAttribute("result", "Unsubscribed");
+ return "views/settings_result";
+ }
+ }
+ throw new HttpBadRequestException();
+ }
}
diff --git a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
index 4e4ad9c4..f1e3a58e 100644
--- a/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
+++ b/juick-server/src/test/java/com/juick/server/tests/ServerTests.java
@@ -1697,4 +1697,13 @@ public class ServerTests {
assertThat(msg.getTags().get(1).getName(), is("test2"));
assertThat(msg.getText(), is("test3"));
}
+ @Test
+ public void oneClickUnsubscribe() throws Exception {
+ mockMvc.perform(post("/settings/unsubscribe")
+ .param("hash", "123456")
+ .param("List-Unsubscribe", "One-Click")).andExpect(status().isBadRequest());
+ mockMvc.perform(post("/settings/unsubscribe")
+ .param("hash", userService.getHashByUID(ugnich.getUid()))
+ .param("List-Unsubscribe", "One-Click")).andExpect(status().isOk());
+ }
}