1 21 22 27 28 package com.sun.mail.imap; 29 30 import java.util.Vector ; 31 32 import javax.mail.*; 33 34 import com.sun.mail.util.*; 35 import com.sun.mail.imap.protocol.MessageSet; 36 import com.sun.mail.imap.protocol.UIDSet; 37 38 45 46 public final class Utility { 47 48 private Utility() { } 50 51 61 public static 62 MessageSet[] toMessageSet(Message[] msgs, Condition cond) { 63 Vector v = new Vector (1); 64 int current, next; 65 66 IMAPMessage msg; 67 for (int i = 0; i < msgs.length; i++) { 68 msg = (IMAPMessage)msgs[i]; 69 if (msg.isExpunged()) continue; 71 72 current = msg.getSequenceNumber(); 73 if ((cond != null) && !cond.test(msg)) 75 continue; 76 77 MessageSet set = new MessageSet(); 78 set.start = current; 79 80 for (++i; i < msgs.length; i++) { 82 msg = (IMAPMessage)msgs[i]; 84 85 if (msg.isExpunged()) continue; 87 next = msg.getSequenceNumber(); 88 89 if ((cond != null) && !cond.test(msg)) 91 continue; 92 93 if (next == current+1) 94 current = next; 95 else { i--; 100 break; 101 } 102 } 103 set.end = current; 104 v.addElement(set); 105 } 106 107 if (v.isEmpty()) return null; 109 else { 110 MessageSet[] sets = new MessageSet[v.size()]; 111 v.copyInto(sets); 112 return sets; 113 } 114 } 115 116 120 public static UIDSet[] toUIDSet(Message[] msgs) { 121 Vector v = new Vector (1); 122 long current, next; 123 124 IMAPMessage msg; 125 for (int i = 0; i < msgs.length; i++) { 126 msg = (IMAPMessage)msgs[i]; 127 if (msg.isExpunged()) continue; 129 130 current = msg.getUID(); 131 132 UIDSet set = new UIDSet(); 133 set.start = current; 134 135 for (++i; i < msgs.length; i++) { 137 msg = (IMAPMessage)msgs[i]; 139 140 if (msg.isExpunged()) continue; 142 next = msg.getUID(); 143 144 if (next == current+1) 145 current = next; 146 else { i--; 151 break; 152 } 153 } 154 set.end = current; 155 v.addElement(set); 156 } 157 158 if (v.isEmpty()) return null; 160 else { 161 UIDSet[] sets = new UIDSet[v.size()]; 162 v.copyInto(sets); 163 return sets; 164 } 165 } 166 167 171 public static interface Condition { 172 public boolean test(IMAPMessage message); 173 } 174 } 175 | Popular Tags |