Create this folder, with the specified type.
(final int type)
| 778 | * Create this folder, with the specified type. |
| 779 | */ |
| 780 | @Override |
| 781 | public synchronized boolean create(final int type) |
| 782 | throws MessagingException { |
| 783 | |
| 784 | char c = 0; |
| 785 | if ((type & HOLDS_MESSAGES) == 0) // only holds folders |
| 786 | c = getSeparator(); |
| 787 | final char sep = c; |
| 788 | Object ret = doCommandIgnoreFailure(new ProtocolCommand() { |
| 789 | @Override |
| 790 | public Object doCommand(IMAPProtocol p) |
| 791 | throws ProtocolException { |
| 792 | if ((type & HOLDS_MESSAGES) == 0) // only holds folders |
| 793 | p.create(fullName + sep); |
| 794 | else { |
| 795 | p.create(fullName); |
| 796 | |
| 797 | // Certain IMAP servers do not allow creation of folders |
| 798 | // that can contain messages *and* subfolders. So, if we |
| 799 | // were asked to create such a folder, we should verify |
| 800 | // that we could indeed do so. |
| 801 | if ((type & HOLDS_FOLDERS) != 0) { |
| 802 | // we want to hold subfolders and messages. Check |
| 803 | // whether we could create such a folder. |
| 804 | ListInfo[] li = p.list("", fullName); |
| 805 | if (li != null && !li[0].hasInferiors) { |
| 806 | // Hmm ..the new folder |
| 807 | // doesn't support Inferiors ? Fail |
| 808 | p.delete(fullName); |
| 809 | throw new ProtocolException("Unsupported type"); |
| 810 | } |
| 811 | } |
| 812 | } |
| 813 | return Boolean.TRUE; |
| 814 | } |
| 815 | }); |
| 816 | |
| 817 | if (ret == null) |
| 818 | return false; // CREATE failure, maybe this |
| 819 | // folder already exists ? |
| 820 | |
| 821 | // exists = true; |
| 822 | // this.type = type; |
| 823 | boolean retb = exists(); // set exists, type, and attributes |
| 824 | if (retb) // Notify listeners on self and our Store |
| 825 | notifyFolderListeners(FolderEvent.CREATED); |
| 826 | return retb; |
| 827 | } |
| 828 | |
| 829 | /** |
| 830 | * Check whether this folder has new messages. |
no test coverage detected