1 38 39 import java.util.*; 40 import java.io.*; 41 import javax.mail.*; 42 43 49 50 public class namespace { 51 52 static String protocol; 53 static String host = null; 54 static String user = null; 55 static String password = null; 56 static String url = null; 57 static int port = -1; 58 static boolean debug = false; 59 static String suser = "other"; 60 61 public static void main(String argv[]) { 62 int msgnum = -1; 63 int optind; 64 65 for (optind = 0; optind < argv.length; optind++) { 66 if (argv[optind].equals("-T")) { 67 protocol = argv[++optind]; 68 } else if (argv[optind].equals("-H")) { 69 host = argv[++optind]; 70 } else if (argv[optind].equals("-U")) { 71 user = argv[++optind]; 72 } else if (argv[optind].equals("-P")) { 73 password = argv[++optind]; 74 } else if (argv[optind].equals("-D")) { 75 debug = true; 76 } else if (argv[optind].equals("-L")) { 77 url = argv[++optind]; 78 } else if (argv[optind].equals("-p")) { 79 port = Integer.parseInt(argv[++optind]); 80 } else if (argv[optind].equals("-u")) { 81 suser = argv[++optind]; 82 } else if (argv[optind].equals("--")) { 83 optind++; 84 break; 85 } else if (argv[optind].startsWith("-")) { 86 System.out.println( 87 "Usage: namespace [-L url] [-T protocol] [-H host] [-p port] [-U user]"); 88 System.out.println( 89 "\t[-P password] [-u other-user] [-D]"); 90 System.exit(1); 91 } else { 92 break; 93 } 94 } 95 96 try { 97 Properties props = System.getProperties(); 99 100 Session session = Session.getInstance(props, null); 102 session.setDebug(debug); 103 104 Store store = null; 106 if (url != null) { 107 URLName urln = new URLName(url); 108 store = session.getStore(urln); 109 store.connect(); 110 } else { 111 if (protocol != null) 112 store = session.getStore(protocol); 113 else 114 store = session.getStore(); 115 116 if (host != null || user != null || password != null) 118 store.connect(host, port, user, password); 119 else 120 store.connect(); 121 } 122 123 printFolders("Personal", store.getPersonalNamespaces()); 124 printFolders("User \"" + suser + "\"", 125 store.getUserNamespaces(suser)); 126 printFolders("Shared", store.getSharedNamespaces()); 127 128 store.close(); 129 } catch (Exception ex) { 130 System.out.println("Oops, got exception! " + ex.getMessage()); 131 ex.printStackTrace(); 132 } 133 System.exit(0); 134 } 135 136 private static void printFolders(String name, Folder[] folders) 137 throws MessagingException { 138 System.out.println(name + " Namespace:"); 139 if (folders == null || folders.length == 0) { 140 System.out.println(" <none>"); 141 return; 142 } 143 for (int i = 0; i < folders.length; i++) { 144 String fn = folders[i].getFullName(); 145 if (fn.length() == 0) 146 fn = "<default folder>"; 147 try { 148 System.out.println(" " + fn + 149 ", delimiter \"" + folders[i].getSeparator() + "\""); 150 Folder[] fl = folders[i].list(); 151 if (fl.length > 0) { 152 System.out.println(" Subfolders:"); 153 for (int j = 0; j < fl.length; j++) 154 System.out.println(" " + fl[j].getFullName()); 155 } 156 } catch (FolderNotFoundException ex) { } 157 } 158 } 159 } 160
| Popular Tags
|