    public void doJob() throws Exception {
        if(Play.configuration.getProperty("mailbox.username") == null || Play.configuration.getProperty("mailbox.password") == null) {
            Logger.error("Please configure mailbox credentials in conf/credentials.conf");
            return;
        }
        Properties props = new Properties();
        props.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.setProperty("mail.imap.socketFactory.port", "993");
        Session session = Session.getDefaultInstance(props);
        Store store = session.getStore("imap");
        store.connect("imap.gmail.com", Play.configuration.getProperty("mailbox.username"), Play.configuration.getProperty("mailbox.password"));
        Folder folder = store.getFolder("jobs");
        folder.open(Folder.READ_WRITE);
        SearchTerm unstarred = new FlagTerm(new Flags(Flags.Flag.FLAGGED), false);
        Message[] messages = folder.search(unstarred);
        for (Message message : messages) {
            String contentString = "";
            List<Attachment> attachments = new ArrayList<Attachment>();
            if (message.getContent() instanceof String) {
                contentString = (String) message.getContent();
            } else if (message.getContent() instanceof Multipart) {
                Multipart mp = (Multipart) message.getContent();
                for (int j = 0; j < mp.getCount(); j++) {
                    Part part = mp.getBodyPart(j);
                    String disposition = part.getDisposition();
                    if (disposition == null
                            || ((disposition != null) && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition
                                    .equalsIgnoreCase(Part.INLINE)))) {
                        MimeBodyPart mbp = (MimeBodyPart) part;
                        if (mbp.isMimeType("text/plain")) {
                            contentString += (String) mbp.getContent();
                        } else {
                            attachments.add(saveAttachment(part));
                        }
                    }
                }
            }
            String name = ((InternetAddress) message.getFrom()[0]).getPersonal();
            String email = ((InternetAddress) message.getFrom()[0]).getAddress();
            String to = ((InternetAddress) message.getAllRecipients()[0]).getAddress();
            if("jobs@zenexity.com".equals(to)) {
                JobApplication application = new JobApplication(name, email, contentString, attachments);
                application.create();
                for(Attachment attachment : attachments) {
                    attachment.jobApplication = application;
                    attachment.create();
                }
                Mails.applied(application);
            } else {
                Pattern regexp = Pattern.compile("^jobs[+][^@]{5}-([0-9]+)@.*$");
                Matcher matcher = regexp.matcher(to);
                if(matcher.matches()) {
                    Long id = Long.parseLong(matcher.group(1));
                    JobApplication application = JobApplication.findById(id);
                    if(application == null) {
                        Logger.warn("Job application not found %s, for %s", id, to);
                    } else {
                        application.addMessage(name, email, contentString);
                        application.save();
                    }
                } else {
                    Logger.warn("Unknow address --> %s", to);
                }
            }
            if (Play.mode == Play.Mode.PROD) {
                message.setFlag(Flag.FLAGGED, true);
            }
        }
        folder.close(false);
        store.close();
    }

    public void doJob() throws Exception {
        if(Play.configuration.getProperty("mailbox.username") == null || Play.configuration.getProperty("mailbox.password") == null) {
            Logger.error("Please configure mailbox credentials in conf/credentials.conf");
            return;
        }
        Properties props = new Properties();
        props.setProperty("mail.imap.socketFactory.class", "javax.net.ssl.SSLSocketFactory");
        props.setProperty("mail.imap.socketFactory.port", "993");
        Session session = Session.getDefaultInstance(props);
        Store store = session.getStore("imap");
        store.connect("imap.gmail.com", Play.configuration.getProperty("mailbox.username"), Play.configuration.getProperty("mailbox.password"));
        Folder folder = store.getFolder("jobs");
        folder.open(Folder.READ_WRITE);
        SearchTerm unstarred = new FlagTerm(new Flags(Flags.Flag.FLAGGED), false);
        Message[] messages = folder.search(unstarred);
        for (Message message : messages) {
            String contentString = "";
            List<Attachment> attachments = new ArrayList<Attachment>();
            if (message.getContent() instanceof String) {
                contentString = (String) message.getContent();
            } else if (message.getContent() instanceof Multipart) {
                Multipart mp = (Multipart) message.getContent();
                for (int j = 0; j < mp.getCount(); j++) {
                    Part part = mp.getBodyPart(j);
                    String disposition = part.getDisposition();
                    if (disposition == null
                            || ((disposition != null) && (disposition.equalsIgnoreCase(Part.ATTACHMENT) || disposition
                                    .equalsIgnoreCase(Part.INLINE)))) {
                        MimeBodyPart mbp = (MimeBodyPart) part;
                        if (mbp.isMimeType("text/plain")) {
                            contentString += (String) mbp.getContent();
                        } else {
                            attachments.add(saveAttachment(part));
                        }
                    }
                }
            }
            String name = ((InternetAddress) message.getFrom()[0]).getPersonal();
            String email = ((InternetAddress) message.getFrom()[0]).getAddress();
            String to = ((InternetAddress) message.getAllRecipients()[0]).getAddress();
            if("jobs@zenexity.com".equals(to)) {
                JobApplication application = new JobApplication(name, email, contentString, attachments);
                application.create();
                for(Attachment attachment : attachments) {
                    attachment.jobApplication = application;
                    attachment.create();
                }
                Mails.applied(application);
            } else {
                Pattern regexp = Pattern.compile("^jobs[+][^@]{5}-([0-9]+)@.*$");
                Matcher matcher = regexp.matcher(to);
                if(matcher.matches()) {
                    Long id = Long.parseLong(matcher.group(1));
                    JobApplication application = JobApplication.findById(id);
                    if(application == null) {
                        Logger.warn("Job application not found %s, for %s", id, to);
                    } else {
                        application.addMessage(name, email, contentString);
                        application.save();
                    }
                } else {
                    Logger.warn("Unknow address --> %s", to);
                }
            }
            if (Play.mode == Play.Mode.PROD || true) {
                message.setFlag(Flag.FLAGGED, true);
            }
        }
        folder.close(false);
        store.close();
    }
