List of usage examples for javax.mail FetchProfile FetchProfile
public FetchProfile()
From source file:com.funambol.email.items.manager.ImapEntityManager.java
/** * get messages from folders./*from ww w.j a v a2s . co m*/ * the cache is not filter dependent. This method * return all the items in the server without filter * * @param fullpath path of the folder * @param folderId parent id * @param filter EmailFilter * @return map with all mail server CrcSyncItemInfo * @throws EntityException */ private LinkedHashMap getAllEmailsInfoRest(String fullpath, String FID, EmailFilter filter) throws EntityException { LinkedHashMap syncItemInfos = new LinkedHashMap(); IMAPFolder f = null; Message msg = null; long lastCRC = 0; String messageID = null; java.util.Date headerDate = null; String internal = null; String internalS = null; int itemsNum = 0; String GUID = null; String FMID = null; String UIDV = null; EntityException finalExc = null; try { f = (IMAPFolder) this.imsw.getMailDefaultFolder().getFolder(fullpath); // check folder if (!f.exists()) { return syncItemInfos; } timeStart = System.currentTimeMillis(); f.open(Folder.READ_WRITE); Message[] items = this.ied.getAllEmails(f, FID, filter); // we use a fetch method in the imap protocol (not in the pop) if (items != null) { FetchProfile fp = new FetchProfile(); fp.add(FetchProfile.Item.ENVELOPE); fp.add(FetchProfile.Item.FLAGS); f.fetch(items, fp); // create the info itemsNum = items.length; for (int i = 0; i < itemsNum; i++) { msg = items[i]; messageID = Utility.getHeaderMessageID(msg); try { // REVIEWED THE FILTER TIME STRATEGY //headerDate = UtilityDate.getHeaderDate(msg,null); headerDate = UtilityDate.getDateForTimeFilter(msg, null); } catch (Exception e) { log.error("Error parsing header date for Caching System ", e); } //String dateForCRC = Utility.getHeaderDateForCRC(msg); //lastCRC = Utility.createCRC(msg, messageID, dateForCRC); String flagList = Utility.createFlagsList(msg); lastCRC = Utility.createCRC(flagList, Def.PROTOCOL_IMAP); FMID = String.valueOf(f.getUID(msg)); UIDV = String.valueOf(f.getUIDValidity()); GUID = Utility.createIMAPGUID(FID, FMID, UIDV); internalS = Utility.getHeaderSyncLabel(msg); if (internalS != null) { internal = "Y"; } SyncItemInfo sii = new SyncItemInfo(new SyncItemKey(GUID), lastCRC, messageID, headerDate, null, null, null, null, internal, "Y", null); syncItemInfos.put(GUID, sii); } } } catch (MessagingException e) { throw new EntityException(e); } finally { if (f != null) { try { if (f.isOpen()) { f.close(true); timeStop = System.currentTimeMillis(); if (log.isTraceEnabled()) { log.trace("getEmailsInfo Execution Time: " + (timeStop - timeStart) + " ms"); } } } catch (MessagingException me) { finalExc = new EntityException(me); } } } if (finalExc != null) { throw finalExc; } return syncItemInfos; }