1 38 39 44 45 import javax.mail.*; 46 47 56 57 public class copier { 58 59 public static void main(String argv[]) { 60 boolean debug = false; 62 if (argv.length != 5) { 63 System.out.println( "usage: copier <urlname> <src folder>" + 64 "<dest folder> <start msg #> <end msg #>"); 65 return; 66 } 67 68 try { 69 URLName url = new URLName(argv[0]); 70 String src = argv[1]; String dest = argv[2]; int start = Integer.parseInt(argv[3]); int end = Integer.parseInt(argv[4]); 75 77 Session session = Session.getInstance(System.getProperties(), null); 78 80 Store store = session.getStore(url); 83 store.connect(); 84 System.out.println("Connected..."); 85 86 Folder folder = store.getFolder(src); 88 folder.open(Folder.READ_WRITE); 89 System.out.println("Opened source..."); 90 91 if (folder.getMessageCount() == 0) { 92 System.out.println("Source folder has no messages .."); 93 folder.close(false); 94 store.close(); 95 } 96 97 Folder dfolder = store.getFolder(dest); 99 if (!dfolder.exists()) dfolder.create(Folder.HOLDS_MESSAGES); 101 System.out.println("Opened dest..."); 102 103 Message[] msgs = folder.getMessages(start, end); 104 System.out.println("Got messages..."); 105 106 folder.copyMessages(msgs, dfolder); 108 System.out.println("Copied messages..."); 109 110 folder.close(false); 112 dfolder.close(false); 113 store.close(); 114 System.out.println("Closed folders and store..."); 115 116 } catch (Exception e) { 117 e.printStackTrace(); 118 } 119 120 System.exit(0); 121 } 122 123 } 124 125 126 | Popular Tags |