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
This commit is contained in:
parent
93b0031f10
commit
845134a9b7
|
@ -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 <day> <sender> wrote ...
|
||||
|
|
Loading…
Reference in New Issue