Example usage for javax.mail Folder getParent

List of usage examples for javax.mail Folder getParent

Introduction

In this page you can find the example usage for javax.mail Folder getParent.

Prototype

public abstract Folder getParent() throws MessagingException;

Source Link

Document

Returns the parent folder of this folder.

Usage

From source file:com.sonicle.webtop.mail.MailAccount.java

public FolderCache moveFolder(String source, String dest) throws MessagingException {
    Folder oldfolder = getFolder(source);
    String oldname = oldfolder.getName();
    //System.out.println("moveFolder "+source+" -> "+dest);
    Folder newfolder;
    if (dest != null && dest.trim().length() > 0) {
        String newname = dest + folderSeparator + oldname;
        newfolder = getFolder(newname);//from ww  w.ja v  a2 s . c o  m
    } else {
        if (hasDifferentDefaultFolder) {
            String prefix = getDefaultFolder().getFullName();
            String newname = oldname;
            if (prefix != null)
                newname = prefix + folderSeparator + newname;
            newfolder = getFolder(newname);
        } else {
            String newname = oldname;
            if (folderPrefix != null) {
                newname = folderPrefix + newname;
            }
            newfolder = getFolder(newname);
        }
    }
    FolderCache fcsrc = getFolderCache(source);
    if (fcsrc != null) {
        destroyFolderCache(fcsrc);
    }
    boolean done = oldfolder.renameTo(newfolder);
    if (done) {
        if (dest != null) {
            FolderCache tfc = getFolderCache(newfolder.getParent().getFullName());
            return addFoldersCache(tfc, newfolder);
        } else {
            return addFoldersCache(fcRoot, newfolder);
        }
    }
    return null;
}

From source file:com.sonicle.webtop.mail.Service.java

public void processMoveFolder(HttpServletRequest request, HttpServletResponse response, PrintWriter out) {
    MailAccount account = getAccount(request);
    String folder = request.getParameter("folder");
    String to = request.getParameter("to");
    String sout = null;//from  www.j a v a 2s .  c om
    FolderCache mcache = null;
    try {
        account.checkStoreConnected();
        boolean result = true;
        sout = "{\n";
        mcache = account.getFolderCache(folder);
        if (account.isSpecialFolder(folder)) {
            result = false;
        } else {
            FolderCache newfc = account.moveFolder(folder, to);
            Folder newf = newfc.getFolder();
            sout += "oldid: '" + StringEscapeUtils.escapeEcmaScript(folder) + "',\n";
            sout += "newid: '" + StringEscapeUtils.escapeEcmaScript(newf.getFullName()) + "',\n";
            sout += "newname: '" + StringEscapeUtils.escapeEcmaScript(newf.getName()) + "',\n";
            if (to != null) {
                sout += "parent: '" + StringEscapeUtils.escapeEcmaScript(newf.getParent().getFullName())
                        + "',\n";
            }
            result = true;
        }
        sout += "result: " + result + "\n}";
    } catch (MessagingException exc) {
        Service.logger.error("Exception", exc);
        sout = "{\nresult: false, oldid: '" + StringEscapeUtils.escapeEcmaScript(folder) + "', oldname: '"
                + StringEscapeUtils.escapeEcmaScript(mcache != null ? mcache.getFolder().getName() : "unknown")
                + "', text:'" + StringEscapeUtils.escapeEcmaScript(exc.getMessage()) + "'\n}";
    }
    out.println(sout);
}