(final String pattern, final boolean subscribed)
| 634 | } |
| 635 | |
| 636 | private synchronized Folder[] doList(final String pattern, |
| 637 | final boolean subscribed) throws MessagingException { |
| 638 | checkExists(); // insure that this folder does exist. |
| 639 | |
| 640 | // Why waste a roundtrip to the server? |
| 641 | if (attributes != null && !isDirectory()) |
| 642 | return new Folder[0]; |
| 643 | |
| 644 | final char c = getSeparator(); |
| 645 | |
| 646 | ListInfo[] li = (ListInfo[])doCommandIgnoreFailure( |
| 647 | new ProtocolCommand() { |
| 648 | @Override |
| 649 | public Object doCommand(IMAPProtocol p) |
| 650 | throws ProtocolException { |
| 651 | if (subscribed) |
| 652 | return p.lsub("", fullName + c + pattern); |
| 653 | else |
| 654 | return p.list("", fullName + c + pattern); |
| 655 | } |
| 656 | }); |
| 657 | |
| 658 | if (li == null) |
| 659 | return new Folder[0]; |
| 660 | |
| 661 | /* |
| 662 | * The UW based IMAP4 servers (e.g. SIMS2.0) include |
| 663 | * current folder (terminated with the separator), when |
| 664 | * the LIST pattern is '%' or '*'. i.e, <LIST "" mail/%> |
| 665 | * returns "mail/" as the first LIST response. |
| 666 | * |
| 667 | * Doesn't make sense to include the current folder in this |
| 668 | * case, so we filter it out. Note that I'm assuming that |
| 669 | * the offending response is the *first* one, my experiments |
| 670 | * with the UW & SIMS2.0 servers indicate that .. |
| 671 | */ |
| 672 | int start = 0; |
| 673 | // Check the first LIST response. |
| 674 | if (li.length > 0 && li[0].name.equals(fullName + c)) |
| 675 | start = 1; // start from index = 1 |
| 676 | |
| 677 | IMAPFolder[] folders = new IMAPFolder[li.length - start]; |
| 678 | IMAPStore st = (IMAPStore)store; |
| 679 | for (int i = start; i < li.length; i++) |
| 680 | folders[i-start] = st.newIMAPFolder(li[i]); |
| 681 | return folders; |
| 682 | } |
| 683 | |
| 684 | /** |
| 685 | * Get the separator character. |
no test coverage detected