|
|
|
@ -54,6 +54,9 @@ import com.sun.mail.util.MailSSLSocketFactory;
|
|
|
|
|
public class PeriodicTask implements Runnable {
|
|
|
|
|
private static final Logger _log = LoggerFactory.getLogger(PeriodicTask.class);
|
|
|
|
|
|
|
|
|
|
private static final String ACCEPTED_SUBJECT_1 = "shared a news";
|
|
|
|
|
private static final String ACCEPTED_SUBJECT_2 = "commented on";
|
|
|
|
|
|
|
|
|
|
private DatabookStore socialStore;
|
|
|
|
|
private String host;
|
|
|
|
|
private String mailserver_username;
|
|
|
|
@ -106,13 +109,14 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
|
|
|
|
|
} catch (PortalException | SystemException e) {
|
|
|
|
|
_log.error("Exception while trying to get the user from email address: " + e.getMessage());
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return SessionManager.getInstance().getASLSession(sessionID, username);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void check(String portalName, String host, String user, String password) {
|
|
|
|
|
try {
|
|
|
|
|
MailSSLSocketFactory sf = null;
|
|
|
|
@ -151,37 +155,46 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
Message message = messages[i];
|
|
|
|
|
_log.info("--------------- FOUND EMAIL ------------------");
|
|
|
|
|
String subject = message.getSubject();
|
|
|
|
|
_log.debug("Parsing email of " + message.getFrom()[0] + " with subject: " + subject);
|
|
|
|
|
|
|
|
|
|
String feedId = extractFeedId(message);
|
|
|
|
|
String commentText = extractText(portalName, feedId, message);
|
|
|
|
|
_log.info("Extracted id: " + feedId + " text=" + commentText);
|
|
|
|
|
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(commentText);
|
|
|
|
|
|
|
|
|
|
Address[] froms = message.getFrom();
|
|
|
|
|
String emailAddress = froms == null ? null : ((InternetAddress) froms[0]).getAddress();
|
|
|
|
|
|
|
|
|
|
ASLSession fakeSession = getFakeASLSession(emailAddress);
|
|
|
|
|
if (escapedCommentText.trim().compareTo("") == 0) {//it is a favorite/subscription
|
|
|
|
|
_log.debug("Found favorite/subscription for feed with subject: " + subject);
|
|
|
|
|
favoriteFeed(feedId, fakeSession);
|
|
|
|
|
_log.info("Parsing email of " + message.getFrom()[0] + " with subject: " + subject);
|
|
|
|
|
if (subject.contains(ACCEPTED_SUBJECT_1) || subject.contains(ACCEPTED_SUBJECT_2)) {
|
|
|
|
|
|
|
|
|
|
String feedId = extractFeedId(message);
|
|
|
|
|
String commentText = extractText(portalName, feedId, message);
|
|
|
|
|
_log.info("Extracted id: " + feedId + " text=" + commentText);
|
|
|
|
|
String escapedCommentText = Utils.escapeHtmlAndTransformUrl(commentText);
|
|
|
|
|
|
|
|
|
|
Address[] froms = message.getFrom();
|
|
|
|
|
String emailAddress = froms == null ? null : ((InternetAddress) froms[0]).getAddress();
|
|
|
|
|
|
|
|
|
|
ASLSession fakeSession = getFakeASLSession(emailAddress);
|
|
|
|
|
if (fakeSession != null) {
|
|
|
|
|
if (escapedCommentText.trim().compareTo("") == 0) {//it is a favorite/subscription
|
|
|
|
|
_log.debug("Found favorite/subscription for feed with subject: " + subject);
|
|
|
|
|
favoriteFeed(feedId, fakeSession);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Comment comment = new Comment(UUID.randomUUID().toString(), fakeSession.getUsername(),
|
|
|
|
|
new Date(), feedId, escapedCommentText, fakeSession.getUserFullName(), fakeSession.getUserAvatarId());
|
|
|
|
|
|
|
|
|
|
_log.debug("The EscapedCommentText =>" + escapedCommentText);
|
|
|
|
|
boolean commentCommitResult = false;
|
|
|
|
|
try {
|
|
|
|
|
if (socialStore.addComment(comment))
|
|
|
|
|
commentCommitResult = true;
|
|
|
|
|
} catch (FeedIDNotFoundException e) {
|
|
|
|
|
_log.error("Related post not found for this comment " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (commentCommitResult) { //the notifications should start
|
|
|
|
|
notifyUsersInvolved(comment, escapedCommentText, feedId, fakeSession);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
_log.warn("User Not Recognized, going to discard Message from emailAddress = " + emailAddress);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
Comment comment = new Comment(UUID.randomUUID().toString(), fakeSession.getUsername(),
|
|
|
|
|
new Date(), feedId, escapedCommentText, fakeSession.getUserFullName(), fakeSession.getUserAvatarId());
|
|
|
|
|
|
|
|
|
|
_log.debug("The EscapedCommentText =>" + escapedCommentText);
|
|
|
|
|
boolean commentCommitResult = false;
|
|
|
|
|
try {
|
|
|
|
|
if (socialStore.addComment(comment))
|
|
|
|
|
commentCommitResult = true;
|
|
|
|
|
} catch (FeedIDNotFoundException e) {
|
|
|
|
|
_log.error("Related post not found for this comment " + e.getMessage());
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
if (commentCommitResult) { //the notifications should start
|
|
|
|
|
notifyUsersInvolved(comment, escapedCommentText, feedId, fakeSession);
|
|
|
|
|
}
|
|
|
|
|
_log.warn("Message Subject is not one of the accepted ones, going to discard Message with subject = " + subject);
|
|
|
|
|
}
|
|
|
|
|
//delete this message
|
|
|
|
|
message.setFlag(Flags.Flag.DELETED, true);
|
|
|
|
@ -210,11 +223,11 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
_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());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
boolean likeCommitResult = false;
|
|
|
|
|
try {
|
|
|
|
|
if (socialStore.like(like));
|
|
|
|
@ -329,7 +342,7 @@ public class PeriodicTask implements Runnable {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
/*
|
|
|
|
|
* this is needed to remove the text added by the email client like when you reply, e.g. On <day> <sender> wrote ...
|
|
|
|
|