1 17 18 package org.apache.james.imapserver; 19 20 import org.apache.james.imapserver.AccessControlException; 21 22 import java.util.*; 23 25 31 32 public abstract class BaseCommand 33 extends BaseConnectionHandler { 34 35 private static final boolean DEEP_DEBUG = true; 37 38 47 protected List decodeSet( String rawSet, int exists ) throws IllegalArgumentException { 48 if (rawSet == null) { 49 getLogger().debug("Null argument in decodeSet"); 50 throw new IllegalArgumentException ("Null argument"); 51 } else if (rawSet.equals("")) { 52 getLogger().debug("Empty argument in decodeSet"); 53 throw new IllegalArgumentException ("Empty string argument"); 54 } 55 getLogger().debug(" decodeSet called for: " + rawSet); 56 System.out.println(" decodeSet called for: " + rawSet); 57 List response = new ArrayList(); 58 59 int checkComma = rawSet.indexOf(","); 60 if (checkComma == -1) { 61 int checkColon = rawSet.indexOf(":"); 63 if (checkColon == -1) { 64 Integer seqNum; 66 if ( rawSet.equals( "*" ) ) { 67 seqNum = new Integer ( -1 ); 68 } 69 else { 70 seqNum = new Integer (rawSet.trim()); 71 if (seqNum.intValue() < 1) { 72 throw new IllegalArgumentException ("Not a positive integer1"); 73 } 74 } 75 response.add(seqNum); 76 } 77 else { 78 80 Integer firstNum = new Integer (rawSet.substring(0, checkColon)); 82 int first = firstNum.intValue(); 83 if ( first < 1 ) { 84 throw new IllegalArgumentException ("Not a positive integer2"); 85 } 86 response.add( firstNum ); 87 88 Integer lastNum; 89 int last; 90 if (rawSet.indexOf("*") != -1) { 91 lastNum = new Integer ( -1 ); 94 } 95 else { 96 lastNum = new Integer (rawSet.substring(checkColon + 1)); 98 last = lastNum.intValue(); 99 if ( last < 1 ) { 100 throw new IllegalArgumentException ("Not a positive integer3"); 101 } 102 if ( last < first ) { 103 throw new IllegalArgumentException ("Not an increasing range"); 104 } 105 106 for (int i = (first + 1); i <= last; i++) { 107 response.add(new Integer (i)); 108 } 109 } 110 } 111 } 112 else { 113 try { 115 String firstRawSet = rawSet.substring( 0, checkComma ); 116 String secondRawSet = rawSet.substring( checkComma + 1 ); 117 response.addAll(decodeSet(firstRawSet, exists)); 118 response.addAll(decodeSet(secondRawSet, exists)); 119 } catch (IllegalArgumentException e) { 120 getLogger().debug("Wonky arguments in: " + rawSet + " " + e); 121 throw e; 122 } 123 } 124 return response; 125 } 126 127 137 protected List decodeUIDSet( String rawSet, List uidsList ) 138 throws IllegalArgumentException { 139 if (rawSet == null) { 140 getLogger().debug("Null argument in decodeSet"); 141 throw new IllegalArgumentException ("Null argument"); 142 } else if (rawSet.equals("")) { 143 getLogger().debug("Empty argument in decodeSet"); 144 throw new IllegalArgumentException ("Empty string argument"); 145 } 146 getLogger().debug(" decodeUIDSet called for: " + rawSet); 147 System.out.println(" decodeUIDSet called for: " + rawSet); 148 Iterator it = uidsList.iterator(); 149 while (it.hasNext()) { 150 System.out.println ("uids present : " + (Integer )it.next() ); 151 } 152 List response = new ArrayList(); 153 int checkComma = rawSet.indexOf(","); 154 if (checkComma == -1) { 155 int checkColon = rawSet.indexOf(":"); 156 if (checkColon == -1) { 157 Integer seqNum = new Integer (rawSet.trim()); 158 if (seqNum.intValue() < 1) { 159 throw new IllegalArgumentException ("Not a positive integer4"); 160 } else { 161 response.add(seqNum); 162 } 163 } else { 164 Integer firstNum = new Integer (rawSet.substring(0, checkColon)); 165 int first = firstNum.intValue(); 166 167 Integer lastNum; 168 if (rawSet.indexOf("*") == -1) { 169 lastNum = new Integer (rawSet.substring(checkColon + 1)); 170 } else { 171 lastNum = (Integer )uidsList.get(uidsList.size()-1); 172 } 173 int last; 174 175 last = lastNum.intValue(); 176 if (first < 1 || last < 1) { 177 throw new IllegalArgumentException ("Not a positive integer"); 178 } else if (first < last) { 179 Collection uids; 180 if(uidsList.size() > 50) { 181 uids = new HashSet(uidsList); 182 } else { 183 uids = uidsList; 184 } 185 Iterator ite = uids.iterator(); 186 while (ite.hasNext()) { 187 int uidsint = ((Integer ) ite.next()).intValue(); 188 System.out.println("SCHLEIFEN f "+first+" l "+last+" uidsint "+uidsint); 189 190 if (uidsint >= first && uidsint <= last) { 191 response.add(new Integer (uidsint)); 192 } 193 } 194 } else if (first == last) { 195 response.add(firstNum); 196 } else { 197 System.out.println("NULLLIST"); 201 } 202 } 203 } else { 204 try { 205 String firstRawSet = rawSet.substring(0, checkComma); 206 String secondRawSet = rawSet.substring(checkComma + 1); 207 response.addAll(decodeUIDSet(firstRawSet, uidsList)); 208 response.addAll(decodeUIDSet(secondRawSet, uidsList)); 209 } catch (IllegalArgumentException e) { 210 getLogger().debug("Wonky arguments in: " + rawSet + " " + e); 211 throw e; 212 } 213 } 214 System.out.println("RETURNING"); 215 return response; 216 } 217 218 protected ACLMailbox getMailbox( ImapSession session, String mailboxName, String command ) 219 { 220 if ( session.getState() == ImapSessionState.SELECTED && session.getCurrentFolder().equals( mailboxName ) ) { 221 return session.getCurrentMailbox(); 222 } 223 else { 224 try { 225 return session.getImapHost().getMailbox( session.getCurrentUser(), mailboxName ); 226 } 227 catch ( MailboxException me ) { 228 if ( me.isRemote() ) { 229 session.noResponse( "[REFERRAL " + me.getRemoteServer() + "]" + "Remote mailbox" ); 230 } 231 else { 232 session.noResponse( command, "Unknown mailbox" ); 233 getLogger().info( "MailboxException in method getBox for user: " 234 + session.getCurrentUser() + " mailboxName: " + mailboxName + " was " 235 + me.getMessage() ); 236 } 237 return null; 238 } 239 catch ( AccessControlException e ) { 240 session.noResponse( command, "Unknown mailbox" ); 241 return null; 242 } 243 } 244 } 245 } 246 | Popular Tags |