List of usage examples for javax.mail Folder getSeparator
public abstract char getSeparator() throws MessagingException;
From source file:com.cubusmail.mail.imap.IMAPMailbox.java
/** * @throws MessagingException//w w w .j a v a 2 s .c o m */ private void loadMailFolder() throws MessagingException { logger.debug("loading folder tree..."); long millis = System.currentTimeMillis(); this.mailFolderMap.clear(); this.mailFolderList.clear(); Folder defaultFolder = this.store.getDefaultFolder(); this.folderSeparator = defaultFolder.getSeparator(); // read all folders to a map List<String> topFolderNames = new ArrayList<String>(); Folder[] allFolders = defaultFolder.list("*"); if (allFolders != null && allFolders.length > 0) { for (Folder folder : allFolders) { this.mailFolderMap.put(folder.getFullName(), createMailFolder(folder)); if (SessionManager.get().getPreferences().getInboxFolderName().equals(folder.getFullName())) { topFolderNames.add(0, SessionManager.get().getPreferences().getInboxFolderName()); } else { String folderName = folder.getFullName(); if (!StringUtils.isEmpty(this.personalNameSpace) && folderName.startsWith(this.personalNameSpace)) { folderName = StringUtils.substringAfter(folderName, this.personalNameSpace); } if (StringUtils.countMatches(folderName, String.valueOf(getFolderSeparator())) == 0) { topFolderNames.add(folder.getFullName()); } } } } // build the tree structure for (String folderName : topFolderNames) { IMailFolder mailFolder = this.mailFolderMap.get(folderName); this.mailFolderList.add(mailFolder); if (!SessionManager.get().getPreferences().getInboxFolderName().equals(folderName) && mailFolder.hasChildren()) { mailFolder.setSubfolders(getSubfolders(mailFolder)); } } logger.debug("...finish: " + (System.currentTimeMillis() - millis) + "ms"); }
From source file:com.cubusmail.server.mail.imap.IMAPMailbox.java
/** * @throws MessagingException//ww w. j a va2 s. c om */ private void loadMailFolder() throws MessagingException { log.debug("loading folder tree..."); long millis = System.currentTimeMillis(); this.mailFolderMap.clear(); this.mailFolderList.clear(); Folder defaultFolder = this.store.getDefaultFolder(); this.folderSeparator = defaultFolder.getSeparator(); // read all folders to a map List<String> topFolderNames = new ArrayList<String>(); Folder[] allFolders = defaultFolder.list("*"); if (allFolders != null && allFolders.length > 0) { for (Folder folder : allFolders) { this.mailFolderMap.put(folder.getFullName(), createMailFolder(folder)); if (SessionManager.get().getPreferences().getInboxFolderName().equals(folder.getFullName())) { topFolderNames.add(0, SessionManager.get().getPreferences().getInboxFolderName()); } else { String folderName = folder.getFullName(); if (!StringUtils.isEmpty(this.personalNameSpace) && folderName.startsWith(this.personalNameSpace)) { folderName = StringUtils.substringAfter(folderName, this.personalNameSpace); } if (StringUtils.countMatches(folderName, String.valueOf(getFolderSeparator())) == 0) { topFolderNames.add(folder.getFullName()); } } } } // build the tree structure for (String folderName : topFolderNames) { IMailFolder mailFolder = this.mailFolderMap.get(folderName); this.mailFolderList.add(mailFolder); if (mailFolder.hasChildren()) { mailFolder.setSubfolders(getSubfolders(mailFolder)); } } log.debug("...finish: " + (System.currentTimeMillis() - millis) + "ms"); }
From source file:com.liferay.mail.imap.IMAPAccessor.java
public String[] addFolder(String displayName) throws MailException { try {/*from w w w .jav a 2 s . c o m*/ String fullName = displayName; if (Validator.isNotNull(_account.getFolderPrefix())) { Store store = _imapConnection.getStore(true); Folder jxFolder = store.getDefaultFolder(); fullName = _account.getFolderPrefix() + jxFolder.getSeparator() + displayName; } Folder jxFolder = getFolder(fullName); if (jxFolder.exists()) { throw new MailException(MailException.FOLDER_ALREADY_EXISTS); } else { if (jxFolder.create(Folder.HOLDS_MESSAGES)) { return new String[] { jxFolder.getFullName(), jxFolder.getName() }; } throw new MailException(MailException.FOLDER_CREATE_FAILED); } } catch (MessagingException me) { throw new MailException(me); } }
From source file:com.liferay.mail.imap.IMAPAccessor.java
public String[] renameFolder(long folderId, String newDisplayName) throws PortalException { try {/* ww w .j a va 2s. c o m*/ Folder jxFolder = getFolder(folderId); String newFullName = StringPool.BLANK; if (Validator.isNotNull(_account.getFolderPrefix())) { Store store = _imapConnection.getStore(true); Folder defaultJxFolder = store.getDefaultFolder(); newFullName = _account.getFolderPrefix() + defaultJxFolder.getSeparator() + newDisplayName; } if (!jxFolder.exists()) { throw new MailException(MailException.FOLDER_DOES_NOT_EXIST); } if (jxFolder.renameTo(getFolder(newFullName))) { return new String[] { jxFolder.getFullName(), jxFolder.getName() }; } else { throw new MailException(MailException.FOLDER_RENAME_FAILED); } } catch (MessagingException me) { throw new MailException(me); } }
From source file:com.sonicle.webtop.mail.Service.java
private String getSharedFolderName(MailAccount account, String mailUser, String folder) throws MessagingException { FolderCache folderCache = null;// ww w .j av a 2 s .c o m String sharedFolderName = null; String folderName = null; // Clear mailUser removing any domain info (ldap auth contains // domain suffix), we don't want it! String user = StringUtils.split(mailUser, "@")[0]; // INBOX is a fake name, it's equals to user's direct folder boolean isInbox = folder.equals("INBOX"); FolderCache[] sharedCache = account.getSharedFoldersCache(); for (FolderCache sharedFolder : sharedCache) { sharedFolderName = sharedFolder.getFolderName(); folderCache = account.getFolderCache(sharedFolderName); for (Folder fo : folderCache.getFolder().list()) { folderName = fo.getFullName(); char sep = fo.getSeparator(); //if is a shared mailbox, and it contains an @, match it with mail user (NS7) //or just user instead (XStream and NS6) String name = isInbox ? (fo.getName().indexOf('@') > 0 ? mailUser : user) : folder; if (folderName.equals(sharedFolderName + sep + name)) return folderName; } } return null; }
From source file:com.sonicle.webtop.mail.Service.java
private void cycleMailFolder(MailAccount account, Folder folder, int cut, JarOutputStream jos) throws Exception { for (Folder child : folder.list()) { String fullname = child.getFullName(); String relname = fullname.substring(cut).replace(folder.getSeparator(), '/'); jos.putNextEntry(new JarEntry(relname + "/")); jos.closeEntry();//from w w w . ja v a 2s. c o m cycleMailFolder(account, child, cut, jos); FolderCache mcache = account.getFolderCache(fullname); Message msgs[] = mcache.getAllMessages(); if (msgs.length > 0) outputJarMailFolder(relname, msgs, jos); } }
From source file:org.apache.hupa.server.handler.FetchFoldersHandler.java
/** * Create a new IMAPFolder from the given Folder * //from www. j a va 2s . co m * @param folder Current folder * @return imapFolder Created IMAPFolder * @throws ActionException If an error occurs * @throws MessagingException If an error occurs */ private IMAPFolder createIMAPFolder(Folder folder) throws ActionException { String fullName = folder.getFullName(); String delimiter; IMAPFolder iFolder = null; try { logger.debug("Creating folder: " + fullName + " for user: " + getUser()); delimiter = String.valueOf(folder.getSeparator()); iFolder = new IMAPFolder(fullName); iFolder.setDelimiter(delimiter); if ("[Gmail]".equals(folder.getFullName())) return iFolder; iFolder.setMessageCount(folder.getMessageCount()); iFolder.setSubscribed(folder.isSubscribed()); iFolder.setUnseenMessageCount(folder.getUnreadMessageCount()); } catch (MessagingException e) { logger.error("Unable to construct folder " + folder.getFullName(), e); } return iFolder; }