1 38 39 import java.util.Properties ; 40 import javax.mail.*; 41 42 49 50 public class folderlist { 51 static String protocol = null; 52 static String host = null; 53 static String user = null; 54 static String password = null; 55 static String url = null; 56 static String root = null; 57 static String pattern = "%"; 58 static boolean recursive = false; 59 static boolean verbose = false; 60 static boolean debug = false; 61 62 public static void main(String argv[]) throws Exception { 63 int optind; 64 for (optind = 0; optind < argv.length; optind++) { 65 if (argv[optind].equals("-T")) { 66 protocol = argv[++optind]; 67 } else if (argv[optind].equals("-H")) { 68 host = argv[++optind]; 69 } else if (argv[optind].equals("-U")) { 70 user = argv[++optind]; 71 } else if (argv[optind].equals("-P")) { 72 password = argv[++optind]; 73 } else if (argv[optind].equals("-L")) { 74 url = argv[++optind]; 75 } else if (argv[optind].equals("-R")) { 76 root = argv[++optind]; 77 } else if (argv[optind].equals("-r")) { 78 recursive = true; 79 } else if (argv[optind].equals("-v")) { 80 verbose = true; 81 } else if (argv[optind].equals("-D")) { 82 debug = true; 83 } else if (argv[optind].equals("--")) { 84 optind++; 85 break; 86 } else if (argv[optind].startsWith("-")) { 87 System.out.println( 88 "Usage: folderlist [-T protocol] [-H host] [-U user] [-P password] [-L url]"); 89 System.out.println( 90 "\t[-R root] [-r] [-v] [-D] [pattern]"); 91 System.exit(1); 92 } else { 93 break; 94 } 95 } 96 if (optind < argv.length) 97 pattern = argv[optind]; 98 99 Properties props = System.getProperties(); 101 102 Session session = Session.getInstance(props, null); 104 session.setDebug(debug); 105 106 Store store = null; 108 Folder rf = null; 109 if (url != null) { 110 URLName urln = new URLName(url); 111 store = session.getStore(urln); 112 store.connect(); 113 } else { 114 if (protocol != null) 115 store = session.getStore(protocol); 116 else 117 store = session.getStore(); 118 119 if (host != null || user != null || password != null) 121 store.connect(host, user, password); 122 else 123 store.connect(); 124 } 125 126 if (root != null) 128 rf = store.getFolder(root); 129 else 130 rf = store.getDefaultFolder(); 131 132 dumpFolder(rf, false, ""); 133 if ((rf.getType() & Folder.HOLDS_FOLDERS) != 0) { 134 Folder[] f = rf.list(pattern); 135 for (int i = 0; i < f.length; i++) 136 dumpFolder(f[i], recursive, " "); 137 } 138 139 store.close(); 140 } 141 142 static void dumpFolder(Folder folder, boolean recurse, String tab) 143 throws Exception { 144 System.out.println(tab + "Name: " + folder.getName()); 145 System.out.println(tab + "Full Name: " + folder.getFullName()); 146 System.out.println(tab + "URL: " + folder.getURLName()); 147 148 if (verbose) { 149 if (!folder.isSubscribed()) 150 System.out.println(tab + "Not Subscribed"); 151 152 if ((folder.getType() & Folder.HOLDS_MESSAGES) != 0) { 153 if (folder.hasNewMessages()) 154 System.out.println(tab + "Has New Messages"); 155 System.out.println(tab + "Total Messages: " + 156 folder.getMessageCount()); 157 System.out.println(tab + "New Messages: " + 158 folder.getNewMessageCount()); 159 System.out.println(tab + "Unread Messages: " + 160 folder.getUnreadMessageCount()); 161 } 162 if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) 163 System.out.println(tab + "Is Directory"); 164 } 165 166 System.out.println(); 167 168 if ((folder.getType() & Folder.HOLDS_FOLDERS) != 0) { 169 if (recurse) { 170 Folder[] f = folder.list(); 171 for (int i = 0; i < f.length; i++) 172 dumpFolder(f[i], recurse, tab + " "); 173 } 174 } 175 } 176 } 177
| Popular Tags
|