public void run() { try { Properties props = new Properties(); //props.put("mail.debug", "true"); Session session = Session.getInstance(props); int port = Integer.parseInt(worker.getParams().get("port")); String storeType = port == 993 ? "imaps" : "imap"; Store store = session.getStore(storeType); logger.info("Request " + worker.getParams().get("host")); store.connect(worker.getParams().get("host"), port, worker.getParams().get("username"), worker.getParams().get("password")); Folder inbox; if(worker.getParams().get("folder") == null || worker.getParams().get("folder").isEmpty()) { inbox = store.getFolder("Inbox"); } else { inbox = store.getFolder(worker.getParams().get("folder")); } inbox.open(Folder.READ_ONLY); javax.mail.Message[] messages; if(worker.getLastRequest() != null) { messages = inbox.search(new ReceivedDateTerm(ComparisonTerm.GT, worker.getLastRequest())); } else { messages = inbox.search(new FlagTerm(new Flags(Flags.Flag.SEEN), false)); } for(int i = 0; i < messages.length; i++) { String mid = messages[i].getHeader("Message-ID").toString(); if(mid == null || mid.isEmpty()) { mid = "urn:" + worker.getParams().get("host") + ":" + messages[i].getMessageNumber(); } Address[] addresses = messages[i].getFrom(); StringBuilder from = new StringBuilder(); StringBuilder producer = new StringBuilder(); if(addresses != null && addresses.length >= 1) { from.append(addresses[0].toString()); for(int j = 0; j < addresses.length; j++) { producer.append(addresses[j].toString()); } } Message message = new Message(); message.setMid(mid); message.setUrl("mailto://" + from.toString()); message.setMessage(messages[i].getSubject()); message.setDate(messages[i].getReceivedDate()); message.setProducer(producer.toString()); queue.push(this, message); } inbox.close(false); store.close(); } catch (Exception e) { logger.error(e.getMessage(), e); } }
/** * Set filter on message received date. * @param receiveddate messages will be filtered on receiveddate * @param notTerm negate condition */ public void setReceivedDateTermEQ(Date receiveddate) { if (this.protocol == MailConnectionMeta.PROTOCOL_POP3) { log.logError(BaseMessages.getString(PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported")); } else { addSearchTerm(new ReceivedDateTerm(ComparisonTerm.EQ, receiveddate)); } }
/** * Set filter on message received date. * @param futureDate messages will be filtered on futureDate * @param notTerm negate condition */ public void setReceivedDateTermLT(Date futureDate) { if (this.protocol == MailConnectionMeta.PROTOCOL_POP3) { log.logError(BaseMessages.getString(PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported")); } else { addSearchTerm(new ReceivedDateTerm(ComparisonTerm.LT, futureDate)); } }
/** * Set filter on message received date. * @param pastDate messages will be filtered on pastDate * @param notTerm negate condition */ public void setReceivedDateTermGT(Date pastDate) { if (this.protocol == MailConnectionMeta.PROTOCOL_POP3) { log.logError(BaseMessages.getString(PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported")); } else { addSearchTerm(new ReceivedDateTerm(ComparisonTerm.GT, pastDate)); } }
public void setReceivedDateTermBetween(Date beginDate, Date endDate) { if (this.protocol == MailConnectionMeta.PROTOCOL_POP3) { log.logError(BaseMessages.getString(PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported")); } else { addSearchTerm( new AndTerm(new ReceivedDateTerm(ComparisonTerm.LT, endDate), new ReceivedDateTerm(ComparisonTerm.GT, beginDate))); } }
public void setReceivedDateTermBetween( Date beginDate, Date endDate ) { if ( this.protocol == MailConnectionMeta.PROTOCOL_POP3 ) { log.logError( BaseMessages.getString( PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported" ) ); } else { addSearchTerm( new AndTerm( new ReceivedDateTerm( ComparisonTerm.LT, endDate ), new ReceivedDateTerm( ComparisonTerm.GT, beginDate ) ) ); } }
public SearchTermBuilder received(Op op, Comparison comparison, Date date) { ReceivedDateTerm st = new ReceivedDateTerm(comparison.asNum(), date); addTerm(op, st); return this; }
@Override public SearchTerm getCustomSearch(Folder folder) { return new ReceivedDateTerm(ComparisonTerm.GE, since); }
/** * Set filter on message received date. * * @param receiveddate * messages will be filtered on receiveddate * @param notTerm * negate condition */ public void setReceivedDateTermEQ( Date receiveddate ) { if ( this.protocol == MailConnectionMeta.PROTOCOL_POP3 ) { log.logError( BaseMessages.getString( PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported" ) ); } else { addSearchTerm( new ReceivedDateTerm( ComparisonTerm.EQ, receiveddate ) ); } }
/** * Set filter on message received date. * * @param futureDate * messages will be filtered on futureDate * @param notTerm * negate condition */ public void setReceivedDateTermLT( Date futureDate ) { if ( this.protocol == MailConnectionMeta.PROTOCOL_POP3 ) { log.logError( BaseMessages.getString( PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported" ) ); } else { addSearchTerm( new ReceivedDateTerm( ComparisonTerm.LT, futureDate ) ); } }
/** * Set filter on message received date. * * @param pastDate * messages will be filtered on pastDate * @param notTerm * negate condition */ public void setReceivedDateTermGT( Date pastDate ) { if ( this.protocol == MailConnectionMeta.PROTOCOL_POP3 ) { log.logError( BaseMessages.getString( PKG, "MailConnection.Error.ReceivedDatePOP3Unsupported" ) ); } else { addSearchTerm( new ReceivedDateTerm( ComparisonTerm.GT, pastDate ) ); } }