From 845134a9b72e2294e1025cf7b2a3d567a0a4b288 Mon Sep 17 00:00:00 2001 From: Massimiliano Assante Date: Thu, 16 Jul 2015 14:27:04 +0000 Subject: [PATCH] fixed bug not reading text of emails git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/portal/social-mail-servlet@117280 82a268e6-3cf1-43bd-a215-b396298e98cf --- .../gcube/portal/socialmail/PeriodicTask.java | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java b/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java index 05a2cfb..2b0bc9f 100644 --- a/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java +++ b/src/main/java/org/gcube/portal/socialmail/PeriodicTask.java @@ -72,7 +72,6 @@ public class PeriodicTask implements Runnable { @Override public void run() { - //check("pop.isti.cnr.it", "social.post", "kof9044+"); check(portalName, host, mailserver_username, password); } @@ -112,7 +111,8 @@ public class PeriodicTask implements Runnable { return SessionManager.getInstance().getASLSession(sessionID, username); } - + + public void check(String portalName, String host, String user, String password) { try { MailSSLSocketFactory sf = null; @@ -157,13 +157,12 @@ public class PeriodicTask implements Runnable { String commentText = extractText(portalName, feedId, message); String escapedCommentText = Utils.escapeHtmlAndTransformUrl(commentText); - - + Address[] froms = message.getFrom(); String emailAddress = froms == null ? null : ((InternetAddress) froms[0]).getAddress(); ASLSession fakeSession = getFakeASLSession(emailAddress); - if (commentText.trim().compareTo("") == 0) {//it is a favorite/subscription + if (escapedCommentText.trim().compareTo("") == 0) {//it is a favorite/subscription _log.debug("Found favorite/subscription for feed with subject: " + subject); favoriteFeed(feedId, fakeSession); } @@ -282,7 +281,7 @@ public class PeriodicTask implements Runnable { * @return * @throws MessagingException */ - private String extractFeedId(Message message) throws MessagingException { + private static String extractFeedId(Message message) throws MessagingException { Address[] emails = message.getRecipients(RecipientType.TO); String toParse = emails[0].toString(); int plus = toParse.indexOf('+'); @@ -299,12 +298,13 @@ public class PeriodicTask implements Runnable { * @return * @throws Exception */ - private String extractText(String portalName, String subjectId, Message message) throws Exception { + private static String extractText(String portalName, String subjectId, Message message) throws Exception { Object 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("Found Multipart Message, getting text part"); + _log.debug("Found Multipart Message, getting text part ... looking for separator " + SEPARATOR); Multipart multipart = (Multipart) messageContent; BodyPart part = multipart.getBodyPart(0); part.toString(); @@ -318,11 +318,12 @@ public class PeriodicTask implements Runnable { String[] lines = toParse.split(System.getProperty("line.separator")); int until = -1; for (int i = 0; i < lines.length; i++) { - if (lines[i].contains(EmailPlugin.WRITE_ABOVE_TO_REPLY)) { + if (lines[i].contains(SEPARATOR)) { until = i; break; } } + StringBuilder sb = new StringBuilder(); /* * this is needed to remove the text added by the email client like when you reply, e.g. On wrote ...