List of usage examples for javax.mail Folder getFullName
public abstract String getFullName();
From source file:com.liferay.mail.imap.IMAPAccessor.java
protected void getFolders(List<Folder> allJxFolders, Folder[] jxFolders) { for (Folder jxFolder : jxFolders) { try {//from w w w . j a v a2s .co m int folderType = jxFolder.getType(); if ((folderType & Folder.HOLDS_MESSAGES) != 0) { allJxFolders.add(jxFolder); } if ((folderType & Folder.HOLDS_FOLDERS) != 0) { getFolders(allJxFolders, jxFolder.list()); } } catch (MessagingException me) { _log.error("Unable to get folder " + jxFolder.getFullName(), me); } } }
From source file:com.sonicle.webtop.mail.MailAccount.java
public boolean deleteFolder(Folder folder) throws MessagingException { for (Folder subfolder : folder.list()) { deleteFolder(subfolder);/* w w w . ja v a2s .c o m*/ } try { folder.close(false); } catch (Throwable exc) { } boolean retval = folder.delete(true); if (retval) { destroyFolderCache(folder.getFullName()); } return retval; }
From source file:com.sonicle.webtop.mail.MailAccount.java
public String renameFolder(String orig, String newname) throws MessagingException { FolderCache fc = getFolderCache(orig); FolderCache fcparent = fc.getParent(); Folder oldfolder = fc.getFolder();//from www . j a v a2 s . co m destroyFolderCache(fc); Folder newfolder = fcparent.getFolder().getFolder(newname); boolean done = oldfolder.renameTo(newfolder); if (!done) { throw new MessagingException("Rename failed"); } //trick for Dovecot on NethServer: under shared folders, create and destroy a fake folder //or rename will not work correctly if (isUnderSharedFolder(newfolder.getFullName())) { Map<String, String> map = ((IMAPStore) store).id(null); if (map != null && map.containsKey("name") && map.get("name").equalsIgnoreCase("dovecot")) { String trickName = "_________" + System.currentTimeMillis(); Folder trickFolder = fcparent.getFolder().getFolder(trickName); try { trickFolder.create(Folder.READ_ONLY); trickFolder.delete(true); } catch (MessagingException exc) { } } } addFoldersCache(fcparent, newfolder); return newfolder.getFullName(); }
From source file:com.liferay.mail.imap.IMAPAccessor.java
public String[] renameFolder(long folderId, String newDisplayName) throws PortalException { try {//ww w . j a v a2 s. 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 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 ww w. j a v a 2 s .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:com.sonicle.webtop.mail.Service.java
private String getSharedFolderName(MailAccount account, String mailUser, String folder) throws MessagingException { FolderCache folderCache = null;/*from ww w . j ava2 s . c om*/ 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
public void processGetImapTree(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { String pfoldername = request.getParameter("node"); MailAccount account = getAccount(request); Folder folder = null;/* www. jav a 2s .co m*/ try { boolean connected = account.checkStoreConnected(); if (!connected) throw new Exception("Mail account authentication error"); boolean isroot = pfoldername.equals("/"); if (isroot) folder = account.getDefaultFolder(); else folder = account.getFolder(pfoldername); Folder folders[] = folder.list(); String fprefix = account.getFolderPrefix(); boolean level1 = (fprefix != null /*&& fprefix.equals("INBOX.")*/ && fprefix.trim().length() > 0); ArrayList<JsFolder> jsFolders = new ArrayList<>(); //out.print("{ data:["); if (isroot && account.hasDifferentDefaultFolder()) { Folder fcs[] = new Folder[0]; //check for other shared folders to be added Folder rfolders[] = account.getRealDefaultFolder().list(); ArrayList<Folder> afcs = new ArrayList<Folder>(); for (String sharedPrefix : account.getSharedPrefixes()) { for (Folder rfolder : rfolders) { if (rfolder.getFullName().equals(sharedPrefix)) afcs.add(rfolder); } } //don't mind about just the Shared folder with no child (size=1) if (afcs.size() > 0) fcs = afcs.toArray(fcs); Folder xfolders[] = new Folder[1 + folders.length + fcs.length]; xfolders[0] = folder; System.arraycopy(folders, 0, xfolders, 1, folders.length); if (fcs.length > 0) System.arraycopy(fcs, 0, xfolders, 1 + folders.length, fcs.length); folders = xfolders; } outputFolders(account, folder, folders, level1, false, jsFolders); new JsonResult("data", jsFolders).printTo(out, false); //out.println("], message: '' }"); } catch (Exception exc) { new JsonResult(exc).printTo(out); Service.logger.error("Exception", exc); } }
From source file:com.sonicle.webtop.mail.Service.java
public void processGetArchiveTree(HttpServletRequest request, HttpServletResponse response, PrintWriter out) { String pfoldername = request.getParameter("node"); MailAccount account = archiveAccount; //getAccount(request); Folder folder = null;//from www. ja va 2 s. c om try { boolean connected = account.checkStoreConnected(); if (!connected) throw new Exception("Mail account authentication error"); if (!account.hasFolderCache()) account.loadFoldersCache(account, true); boolean isroot = pfoldername.equals("/"); if (isroot) folder = account.getDefaultFolder(); else folder = account.getFolder(pfoldername); Folder folders[] = folder.list(); String fprefix = account.getFolderPrefix(); boolean level1 = (fprefix != null && fprefix.equals("INBOX.")); ArrayList<JsFolder> jsFolders = new ArrayList<>(); //out.print("{ data:["); if (isroot && account.hasDifferentDefaultFolder()) { Folder fcs[] = new Folder[0]; //check for other shared folders to be added Folder rfolders[] = account.getRealDefaultFolder().list(); ArrayList<Folder> afcs = new ArrayList<Folder>(); for (String sharedPrefix : account.getSharedPrefixes()) { for (Folder rfolder : rfolders) { if (rfolder.getFullName().equals(sharedPrefix)) afcs.add(rfolder); } } if (afcs.size() > 0) fcs = afcs.toArray(fcs); Folder xfolders[] = new Folder[1 + folders.length + fcs.length]; xfolders[0] = folder; System.arraycopy(folders, 0, xfolders, 1, folders.length); if (fcs.length > 0) System.arraycopy(fcs, 0, xfolders, 1 + folders.length, fcs.length); folders = xfolders; } outputFolders(account, folder, folders, level1, false, jsFolders); new JsonResult("data", jsFolders).printTo(out, false); //out.println("], message: '' }"); } catch (Exception exc) { new JsonResult(exc).printTo(out); Service.logger.error("Exception", exc); } }
From source file:com.sonicle.webtop.mail.Service.java
public String getInternationalFolderName(FolderCache fc) { Folder folder = fc.getFolder(); String desc = folder.getName(); String fullname = folder.getFullName(); //WebTopApp webtopapp=environment.getWebTopApp(); Locale locale = environment.getProfile().getLocale(); if (fc.isInbox()) { desc = lookupResource(MailLocaleKey.FOLDERS_INBOX); } else if (fc.isSharedFolder()) { desc = lookupResource(MailLocaleKey.FOLDERS_SHARED); } else if (fc.isDrafts()) { desc = lookupResource(MailLocaleKey.FOLDERS_DRAFTS); } else if (fc.isTrash()) { desc = lookupResource(MailLocaleKey.FOLDERS_TRASH); } else if (fc.isArchive()) { desc = lookupResource(MailLocaleKey.FOLDERS_ARCHIVE); } else if (fc.isSent()) { desc = lookupResource(MailLocaleKey.FOLDERS_SENT); } else if (fc.isSpam()) { desc = lookupResource(MailLocaleKey.FOLDERS_SPAM); }//from w ww . j a v a 2 s . c o m return desc; }
From source file:com.sonicle.webtop.mail.Service.java
protected ArrayList<Folder> sortFolders(MailAccount account, Folder folders[]) { ArrayList<Folder> afolders = new ArrayList<Folder>(); ArrayList<Folder> sfolders = new ArrayList<Folder>(); HashMap<String, Folder> mfolders = new HashMap<String, Folder>(); //add all non special fo the array and map special ones for later insert Folder inbox = null;/*from w w w . ja va 2s. c o m*/ Folder sent = null; Folder drafts = null; Folder trash = null; Folder archive = null; Folder spam = null; for (Folder f : folders) { String foldername = f.getFullName(); String shortfoldername = account.getShortFolderName(foldername); if (!mfolders.containsKey(shortfoldername)) { mfolders.put(shortfoldername, f); if (account.isInboxFolder(shortfoldername)) inbox = f; else if (account.isSentFolder(shortfoldername)) sent = f; else if (account.isDraftsFolder(shortfoldername)) drafts = f; else if (account.isTrashFolder(shortfoldername)) trash = f; else if (account.isSpamFolder(shortfoldername)) spam = f; else if (account.isArchiveFolder(shortfoldername)) archive = f; else if (account.isSharedFolder(foldername)) sfolders.add(f); else afolders.add(f); } } if (sortfolders) { Collections.sort(afolders, new Comparator<Folder>() { @Override public int compare(Folder f1, Folder f2) { return f1.getFullName().toLowerCase().compareTo(f2.getFullName().toLowerCase()); } }); Collections.sort(sfolders, new Comparator<Folder>() { @Override public int compare(Folder f1, Folder f2) { return f1.getFullName().toLowerCase().compareTo(f2.getFullName().toLowerCase()); } }); } //add any mapped special folder in order on top if (archive != null) { afolders.add(0, archive); } if (trash != null) { afolders.add(0, trash); } if (spam != null) { afolders.add(0, spam); } if (sent != null) { afolders.add(0, sent); } if (drafts != null) { afolders.add(0, drafts); } if (inbox != null) { afolders.add(0, inbox); } //add shared folders at the end afolders.addAll(sfolders); return afolders; }