From e275083243884588ee11130a483123447c951a80 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 19 Mar 2020 17:56:10 +0100 Subject: [PATCH] fix Bug #18875 Social networking Mail Parser empty replies to posts --- .classpath | 5 +- .settings/org.eclipse.jdt.core.prefs | 7 ++- ....eclipse.wst.common.project.facet.core.xml | 2 +- .../gcube/portal/socialmail/PeriodicTask.java | 57 +++++++++++-------- 4 files changed, 41 insertions(+), 30 deletions(-) diff --git a/.classpath b/.classpath index 91f2707..47de373 100644 --- a/.classpath +++ b/.classpath @@ -15,6 +15,7 @@ + @@ -23,9 +24,9 @@ - + - + diff --git a/.settings/org.eclipse.jdt.core.prefs b/.settings/org.eclipse.jdt.core.prefs index 443e085..4e4a3ad 100644 --- a/.settings/org.eclipse.jdt.core.prefs +++ b/.settings/org.eclipse.jdt.core.prefs @@ -1,8 +1,9 @@ eclipse.preferences.version=1 org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled -org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.7 -org.eclipse.jdt.core.compiler.compliance=1.7 +org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 +org.eclipse.jdt.core.compiler.compliance=1.8 org.eclipse.jdt.core.compiler.problem.assertIdentifier=error org.eclipse.jdt.core.compiler.problem.enumIdentifier=error org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning -org.eclipse.jdt.core.compiler.source=1.7 +org.eclipse.jdt.core.compiler.release=disabled +org.eclipse.jdt.core.compiler.source=1.8 diff --git a/.settings/org.eclipse.wst.common.project.facet.core.xml b/.settings/org.eclipse.wst.common.project.facet.core.xml index f7f0893..dcea5a1 100644 --- a/.settings/org.eclipse.wst.common.project.facet.core.xml +++ b/.settings/org.eclipse.wst.common.project.facet.core.xml @@ -3,6 +3,6 @@ - + diff --git a/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java b/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java index 4e3bf6a..d021695 100644 --- a/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java +++ b/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java @@ -26,6 +26,7 @@ import javax.mail.internet.InternetAddress; import javax.mail.internet.MimeMessage.RecipientType; import javax.servlet.http.HttpServletRequest; +import org.apache.commons.lang.StringEscapeUtils; import org.gcube.application.framework.core.session.ASLSession; import org.gcube.application.framework.core.session.SessionManager; import org.gcube.application.framework.core.util.GenderType; @@ -346,24 +347,24 @@ public class PeriodicTask implements Runnable { /** * this method manages the replies coming from post notifications * @param portalName - * @param feedId the identifier in the System managing the feeds + * @param postId the identifier in the System managing the feeds * @param message the javax mail Message instance * @param fakeSession * @throws Exception */ - private void handlePostReply(String portalName, String feedId, Message message, ASLSession fakeSession) throws Exception { - String commentText = extractText(portalName, feedId, message); - _log.info("Extracted id: " + feedId + " text=" + commentText); + private void handlePostReply(String portalName, String postId, Message message, ASLSession fakeSession) throws Exception { + String commentText = extractText(portalName, postId, message); + _log.info("Extracted id: " + postId + " text=" + commentText); String escapedCommentText = org.gcube.portal.socialmail.Utils.escapeHtmlAndTransformUrl(commentText); String subject = message.getSubject(); if (escapedCommentText.trim().compareTo("") == 0) {//it is a favorite/subscription - _log.debug("Found favorite/subscription for feed with subject: " + subject); - favoriteFeed(feedId, fakeSession); + _log.debug("Found life/subscription for post with subject: " + subject); + likePost(postId, fakeSession); } else { Comment comment = new Comment(UUID.randomUUID().toString(), fakeSession.getUsername(), - new Date(), feedId, escapedCommentText, fakeSession.getUserFullName(), fakeSession.getUserAvatarId()); + new Date(), postId, escapedCommentText, fakeSession.getUserFullName(), fakeSession.getUserAvatarId()); _log.debug("The EscapedCommentText =>" + escapedCommentText); boolean commentCommitResult = false; @@ -375,26 +376,26 @@ public class PeriodicTask implements Runnable { e.printStackTrace(); } if (commentCommitResult) { //the notifications should start - notifyUsersInvolved(comment, escapedCommentText, feedId, fakeSession); + notifyUsersInvolved(comment, escapedCommentText, postId, fakeSession); } } } /** - * favorite the feed to subscribe to further comments - * @param feedId + * like the post to subscribe to further comments + * @param postId * @param fakeSession */ - private void favoriteFeed(String feedId, ASLSession fakeSession) { - if (feedId == null || feedId.compareTo("") == 0) { + private void likePost(String postId, ASLSession fakeSession) { + if (postId == null || postId.compareTo("") == 0) { _log.warn("Found email with no feedId from " + fakeSession.getUserEmailAddress() + ". Going to trash it"); return; } Like like = new Like(UUID.randomUUID().toString(), fakeSession.getUsername(), - new Date(), feedId, fakeSession.getUserFullName(), fakeSession.getUserAvatarId()); + new Date(), postId, fakeSession.getUserFullName(), fakeSession.getUserAvatarId()); boolean likeCommitResult = false; try { @@ -406,9 +407,9 @@ public class PeriodicTask implements Runnable { } if (likeCommitResult) { //the notification should be delivered to the post owner try { - Feed feed = socialStore.readFeed(feedId); - String feedOwnerId = feed.getEntityId(); - boolean isAppFeed = feed.isApplicationFeed(); + Feed post = socialStore.readFeed(postId); + String feedOwnerId = post.getEntityId(); + boolean isAppFeed = post.isApplicationFeed(); NotificationsManager nm = new ApplicationNotificationsManager( site, @@ -417,7 +418,7 @@ public class PeriodicTask implements Runnable { APP_ID_NEWSFEED ); if (! fakeSession.getUsername().equals(feedOwnerId) && (!isAppFeed)) { - boolean result = nm.notifyLikedFeed(feedOwnerId, feedId, ""); + boolean result = nm.notifyLikedFeed(feedOwnerId, postId, ""); _log.trace("Like Notification to post owner added? " + result); } } @@ -437,14 +438,14 @@ public class PeriodicTask implements Runnable { * @throws ColumnNameNotFoundException */ private void notifyUsersInvolved(Comment comment, String commentText, String feedId, ASLSession fakeSession) throws PrivacyLevelTypeNotFoundException, FeedTypeNotFoundException, FeedIDNotFoundException, ColumnNameNotFoundException { - Feed feed = socialStore.readFeed(feedId); - String feedOwnerId = feed.getEntityId(); - boolean isAppFeed = feed.isApplicationFeed(); + Feed post = socialStore.readFeed(feedId); + String feedOwnerId = post.getEntityId(); + boolean isAppFeed = post.isApplicationFeed(); //if the user who commented this post is not the user who posted it notifies the poster user (Feed owner) NotificationsManager nm = new ApplicationNotificationsManager( site, - feed.getVreid(), + post.getVreid(), new SocialNetworkingUser(fakeSession.getUsername(), fakeSession.getUserEmailAddress(), fakeSession.getUserFullName(), fakeSession.getUserAvatarId()), APP_ID_NEWSFEED ); @@ -454,13 +455,13 @@ public class PeriodicTask implements Runnable { } //if there are users who liked this post they get notified, asynchronously with this thread - ArrayList favorites = getAllLikesByFeed(feedId); - Thread likesThread = new Thread(new LikeNotificationsThread(commentText, nm, favorites, feedOwnerId, comment.getKey())); + ArrayList likes = getAllLikesByFeed(feedId); + Thread likesThread = new Thread(new LikeNotificationsThread(commentText, nm, likes, feedOwnerId, comment.getKey())); likesThread.start(); UserManager userManager = new LiferayUserManager(); //notify the other users who commented this post (excluding the ones above) - Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(socialStore, userManager, fakeSession.getUsername(), comment.getFeedid(), commentText, nm, feedOwnerId, comment.getKey(), favorites)); + Thread commentsNotificationthread = new Thread(new CommentNotificationsThread(socialStore, userManager, fakeSession.getUsername(), comment.getFeedid(), commentText, nm, feedOwnerId, comment.getKey(), likes)); commentsNotificationthread.start(); } /** @@ -603,7 +604,15 @@ public class PeriodicTask implements Runnable { sb.append("\n"); } + String toReturn = sb.toString().trim(); + //check if the reply is from iOS which add illegal character + String sanytisedLine = StringEscapeUtils.escapeJava(toReturn); + String replyFromIOS = sanytisedLine.replace("> \\uFEFF", ""); + if (replyFromIOS.length() == 0) { + toReturn = ""; + _log.debug("I think I found a Like done from an iOS device"); + } _log.debug("Returning text extracted = " + toReturn); return toReturn; }