Commit db0f4e94 by Harsh Shah

Finish Hotfix-20190808

parents 24ab2c55 a3643e17
......@@ -30,7 +30,7 @@ public class PerformaEmailFetcher implements Runnable, InitialisationParticipant
private static final String ACC_USER_NAME = ConfigMgr.getKeyfileString("imap.email.acc.username");
private static final String ACC_PASSWORD = ConfigMgr.getKeyfileString("imap.email.acc.password");
private static final boolean SYNC_ALL_EXISTING_EMAILS = ConfigMgr.getKeyfileBoolean("sync.all.existing.emails", false);
private static final Integer SYNC_EMAILS_SINCE_MINUTES = ConfigMgr.getKeyfileInt("sync.emails.since.minutes", 10*24*60); //Applicable only when SYNC_ALL_EXISTING_EMAILS is false.
private static final Integer SYNC_EMAILS_SINCE_MINUTES = ConfigMgr.getKeyfileInt("sync.emails.since.minutes", 12*24*60); //Applicable only when SYNC_ALL_EXISTING_EMAILS is false.
public static final LoggingArea LOG = LoggingArea.createLoggingArea("PerformaEmailFetcher");
@Override
......@@ -85,7 +85,7 @@ public class PerformaEmailFetcher implements Runnable, InitialisationParticipant
for (Folder folder : folders)
{
if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0)
if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0 && folder.getFullName().equalsIgnoreCase("INBOX"))
{
LogMgr.log(LOG, LogLevel.PROCESSING1, "Processing folder " + folder.getFullName());
visitedNodes.add(folder.getFullName());
......@@ -229,6 +229,7 @@ public class PerformaEmailFetcher implements Runnable, InitialisationParticipant
LogMgr.log(LOG, LogLevel.PROCESSING2 , "processMessage called");
String tmpFromAdress = null;
String tmpFromPerson = null;
String tmpReplyTo = null;
String tmpFirstName = null;
String tmpLastName = null;
......@@ -265,20 +266,30 @@ public class PerformaEmailFetcher implements Runnable, InitialisationParticipant
tmpSubject = message.getSubject();
tmpSentDate = message.getReceivedDate();
tmpMessageID = ((MimeMessage)message).getMessageID();
tmpMessageBody = EmailFetcher.getText(message, new ArrayList());
if(message.getReplyTo() != null && message.getReplyTo().length > 0)
{
tmpReplyTo = ((InternetAddress) message.getReplyTo()[0]).getAddress();
String name = ((InternetAddress) message.getReplyTo()[0]).getPersonal();
tmpFromPerson = ((InternetAddress) message.getReplyTo()[0]).getPersonal();
if(tmpReplyTo != null && tmpReplyTo.equals("noreply@jobapplications.seek.com.au"))
{
tmpFromPerson = getApplicantName(tmpFromPerson);
Document document = Jsoup.parse(tmpMessageBody);
Element atag = document.select("a[title*=Email]").first();
tmpReplyTo = atag.text();
}
tmpFirstName = getFirstName(name);
tmpLastName = getLastName(name);
tmpFirstName = formatName(getFirstName(tmpFromPerson));
tmpLastName = formatName(getLastName(tmpFromPerson));
}
LogMgr.log(LOG, LogLevel.PROCESSING2 , "Mail Subject:" + tmpSubject, " Address:", tmpFromAdress, " MessageId:", tmpMessageID);
LogMgr.log(LOG, LogLevel.PROCESSING2 , "Mail Details: Received ", message.getReceivedDate(), " Sent:", message.getSentDate());
if(message.getAllRecipients() != null && message.getAllRecipients().length > 0)
{
for(Address receipientAddress : message.getAllRecipients())
......@@ -300,7 +311,6 @@ public class PerformaEmailFetcher implements Runnable, InitialisationParticipant
tmpEmailText = EmailFetcher.getText(message, new ArrayList<>());
tmpContents = getAttachments(message);
tmpMessageBody = EmailFetcher.getText(message, new ArrayList());
}
catch (MessagingException | IOException ex)
{
......@@ -351,7 +361,7 @@ public class PerformaEmailFetcher implements Runnable, InitialisationParticipant
// handle seek email
if(replyTo == null || replyTo.isEmpty())
{
// might have to check email body if reply to is not set
// email body is checked - retriving a tag with title="Email applicant name"
return;
}
......@@ -543,11 +553,21 @@ public class PerformaEmailFetcher implements Runnable, InitialisationParticipant
return ((name.split("\\w+").length > 1) && (name.lastIndexOf(' ') > 0 )) ? name.substring(name.lastIndexOf(" ")+1) : "";
}
private static String formatName(String name)
{
return name.length() > 1 ? name.substring(0,1).toUpperCase() + name.substring(1).toLowerCase() : name;
}
public static String getJobIdentifierFromEmail(String strReceipient)
{
int index = strReceipient.indexOf('@');
return strReceipient.substring(0, index).replace("job", "");
return strReceipient.substring(0, index).replace("job", "");
}
public static String getApplicantName(String strPerson)
{
return strPerson.replace("via SEEK", "").trim();
}
private static List<FileBinaryContent> getAttachments(Message message) throws IOException, MessagingException
......
......@@ -37,7 +37,7 @@
<TASK factory="Participant" class="oneit.appservices.batch.DefaultTask">
<RUN class="performa.utils.PerformaEmailFetcher" factory="Participant">
</RUN>
<WHEN factory="MetaComponent" component="BatchSchedule" selector="performa.runbatch">
<WHEN factory="MetaComponent" component="BatchSchedule" selector="performa.emailfetch">
<NODE name="schedule" class="oneit.appservices.batch.QuickSchedule">
<NODE name="period" factory="Integer" value="5"/>
</NODE>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment