fix Bug #18875 Social networking Mail Parser empty replies to posts

Feature/21689
Massimiliano Assante 4 years ago
parent 9c226f9595
commit e275083243

@ -15,6 +15,7 @@
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="test" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
@ -23,9 +24,9 @@
<attribute name="org.eclipse.jst.component.dependency" value="/WEB-INF/lib"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7">
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

@ -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

@ -3,6 +3,6 @@
<fixed facet="wst.jsdt.web"/>
<installed facet="jst.web" version="3.0"/>
<installed facet="wst.jsdt.web" version="1.0"/>
<installed facet="java" version="1.7"/>
<installed facet="jst.jaxrs" version="2.0"/>
<installed facet="java" version="1.8"/>
</faceted-project>

@ -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<Like> favorites = getAllLikesByFeed(feedId);
Thread likesThread = new Thread(new LikeNotificationsThread(commentText, nm, favorites, feedOwnerId, comment.getKey()));
ArrayList<Like> 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;
}

Loading…
Cancel
Save