public boolean isAccountBeingUsed(Account account) { if (log.isDebugEnabled()) log.debug( String.format( "Checking account %s, user_id %s for last registration with location service", account.getId(), account.getUser_id())); IPeekLocationService locationService = new PeekLocationService(); Date lastUpdated = null; try { lastUpdated = locationService.getLastUpdatedTimestamp(account.getUser_id()); } catch (DALException e) { log.error(UtilsTools.getExceptionStackTrace(e)); } if (lastUpdated == null) { log.debug("Last updated value not found, so we should still check this account"); return true; } Date now = new Date(); Long interval = dayMultiplier * mailcheckDisableIntervalInHours; Long sinceLastConnection = now.getTime() - lastUpdated.getTime(); if (sinceLastConnection > interval) { if (log.isDebugEnabled()) log.debug( String.format( "Last mail check was %s hours ago, > %s hour interval , we will not check this account", sinceLastConnection / dayMultiplier, interval / dayMultiplier)); return false; } return true; }
public static void dumpEnvelope(Message m) throws Exception { pr("This is the message envelope"); pr("---------------------------"); Address[] a; // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) pr("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) pr("TO: " + a[j].toString()); } // SUBJECT pr("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); pr("SendDate: " + (d != null ? d.toString() : "UNKNOWN")); // FLAGS Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } pr("FLAGS: " + sb.toString()); // X-MAILER String[] hdrs = m.getHeader("X-Mailer"); if (hdrs != null) pr("X-Mailer: " + hdrs[0]); else pr("X-Mailer NOT available"); }
public int handleFirstTime( Account account, FolderHelper folderHelper, int folderDepth, String messageStoreBucket, Set<String> storedMessageIds, String context, StopWatch watch) throws Exception { int newMessages = 0; Date lastMessageReceivedDate = null; log.info(String.format("handling first mailcheck for %s", context)); Folder folder; while ((folder = folderHelper.next()) != null) { String folderContext = context + " ,folderName=" + folder.getFullName(); IMAPFolder imapFolder = (IMAPFolder) folder; Collection<Integer> messages = getFirstTimeMessages(imapFolder, folderContext); if (messages.size() > 0) { storedMessageIds = new HashSet<String>(); for (Integer messageNumber : messages) { Message message = imapFolder.getMessage(messageNumber); if (lastMessageReceivedDate == null || lastMessageReceivedDate.before(message.getReceivedDate())) { lastMessageReceivedDate = message.getReceivedDate(); } String messageId = getId(account, imapFolder, message); if (processMessage( account, message, messageNumber, messageId, imapFolder, storedMessageIds, messageStoreBucket, folderContext, watch, folderHelper)) { newMessages++; } } } } updateAccount(account, null, 0, folderDepth, lastMessageReceivedDate); return newMessages; }
protected boolean areMessagesInReverseOrder(Folder inbox) throws MessagingException { try { Message msgFirst = inbox.getMessage(1); Message msgLast = inbox.getMessage(inbox.getMessageCount()); Date firstMessageDate = getDateToDetermineOrder(msgFirst); Date lastMessageDate = getDateToDetermineOrder(msgLast); return firstMessageDate != null && lastMessageDate != null && firstMessageDate.after(lastMessageDate); } catch (Exception e) { return false; } }
public static void dumpPart(Part p) throws Exception { if (p instanceof Message) { Message m = (Message) p; Address[] a; // FROM if ((a = m.getFrom()) != null) { for (int j = 0; j < a.length; j++) System.out.println("FROM: " + a[j].toString()); } // TO if ((a = m.getRecipients(Message.RecipientType.TO)) != null) { for (int j = 0; j < a.length; j++) System.out.println("TO: " + a[j].toString()); } // SUBJECT System.out.println("SUBJECT: " + m.getSubject()); // DATE Date d = m.getSentDate(); System.out.println("SendDate: " + (d != null ? d.toLocaleString() : "UNKNOWN")); // FLAGS: Flags flags = m.getFlags(); StringBuffer sb = new StringBuffer(); Flags.Flag[] sf = flags.getSystemFlags(); // get the system flags boolean first = true; for (int i = 0; i < sf.length; i++) { String s; Flags.Flag f = sf[i]; if (f == Flags.Flag.ANSWERED) s = "\\Answered"; else if (f == Flags.Flag.DELETED) s = "\\Deleted"; else if (f == Flags.Flag.DRAFT) s = "\\Draft"; else if (f == Flags.Flag.FLAGGED) s = "\\Flagged"; else if (f == Flags.Flag.RECENT) s = "\\Recent"; else if (f == Flags.Flag.SEEN) s = "\\Seen"; else continue; // skip it if (first) first = false; else sb.append(' '); sb.append(s); } String[] uf = flags.getUserFlags(); // get the user flag strings for (int i = 0; i < uf.length; i++) { if (first) first = false; else sb.append(' '); sb.append(uf[i]); } System.out.println("FLAGS = " + sb.toString()); } System.out.println("CONTENT-TYPE: " + p.getContentType()); /* Dump input stream InputStream is = ((MimeMessage)m).getInputStream(); int c; while ((c = is.read()) != -1) System.out.write(c); */ Object o = p.getContent(); if (o instanceof String) { System.out.println("This is a String"); System.out.println((String) o); } else if (o instanceof Multipart) { System.out.println("This is a Multipart"); Multipart mp = (Multipart) o; int count = mp.getCount(); for (int i = 0; i < count; i++) dumpPart(mp.getBodyPart(i)); } else if (o instanceof InputStream) { System.out.println("This is just an input stream"); InputStream is = (InputStream) o; int c; while ((c = is.read()) != -1) System.out.write(c); } }