fix for Bug #476 Social Mail Replies: vacation notice auto reply to post is treated as "Favorite"

git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-mail-servlet@117703 82a268e6-3cf1-43bd-a215-b396298e98cf
Feature/21689
Massimiliano Assante 9 years ago
parent 9b5a6fa8f8
commit fcfcaff7fb

@ -54,9 +54,6 @@ 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;
@ -156,8 +153,7 @@ public class PeriodicTask implements Runnable {
_log.info("--------------- FOUND EMAIL ------------------");
String subject = message.getSubject();
_log.info("Parsing email of " + message.getFrom()[0] + " with subject: " + subject);
if (subject.contains(ACCEPTED_SUBJECT_1) || subject.contains(ACCEPTED_SUBJECT_2)) {
if (isValidReply(message)) {
String feedId = extractFeedId(message);
String commentText = extractText(portalName, feedId, message);
_log.info("Extracted id: " + feedId + " text=" + commentText);
@ -194,7 +190,7 @@ public class PeriodicTask implements Runnable {
}
}
else {
_log.warn("Message Subject is not one of the accepted ones, going to discard Message with subject = " + subject);
_log.warn("Message is not a valid reply, going to discard Message with subject = " + subject);
}
//delete this message
message.setFlag(Flags.Flag.DELETED, true);
@ -309,6 +305,40 @@ public class PeriodicTask implements Runnable {
return null;
return toParse.substring(plus+1, at);
}
/**
* the email is considered a valid reply if and only of it contains the EmailPlugin.WRITE_ABOVE_TO_REPLY text in the body
* @param message the message to check
* @return true if the email is a valid reply, false otherwise
*/
private boolean isValidReply(Message message) {
Object messageContent;
try {
messageContent = message.getContent();
String toParse = null;
final String SEPARATOR = EmailPlugin.WRITE_ABOVE_TO_REPLY.substring(0, 23);
// Check if content is pure text/html or in parts
if (messageContent instanceof Multipart) {
_log.debug("Checking if isValidReply, found Multipart Message, getting text part ... looking for separator " + SEPARATOR);
Multipart multipart = (Multipart) messageContent;
BodyPart part = multipart.getBodyPart(0);
part.toString();
toParse = part.getContent().toString();
}
else {
_log.debug("Found a text/plain Message, getting text ... looking for separator " + SEPARATOR);
toParse = messageContent.toString();
}
String[] lines = toParse.split(System.getProperty("line.separator"));
for (int i = 0; i < lines.length; i++) {
if (lines[i].contains(SEPARATOR))
return true;
}
return false;
} catch (Exception e) {
e.printStackTrace();
return false;
}
}
/**
*
* @param portalName

Loading…
Cancel
Save