Changeset 471
- Timestamp:
- 07/27/09 16:53:20 (3 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 14 edited
-
LogicMail/LogicMail.jdp (modified) (1 diff)
-
LogicMail/src/org/logicprobe/LogicMail/LogicMail.rrc (modified) (1 diff)
-
LogicMail/src/org/logicprobe/LogicMail/mail/AbstractMailConnectionHandler.java (modified) (3 diffs)
-
LogicMail/src/org/logicprobe/LogicMail/mail/IncomingMailClient.java (modified) (5 diffs)
-
LogicMail/src/org/logicprobe/LogicMail/mail/IncomingMailConnectionHandler.java (modified) (7 diffs)
-
LogicMail/src/org/logicprobe/LogicMail/mail/MailProgressHandler.java (added)
-
LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapClient.java (modified) (29 diffs)
-
LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapProtocol.java (modified) (31 diffs)
-
LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopClient.java (modified) (12 diffs)
-
LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopProtocol.java (modified) (4 diffs)
-
LogicMail/src/org/logicprobe/LogicMail/ui/MessagePropertiesScreen.java (modified) (2 diffs)
-
LogicMail/src/org/logicprobe/LogicMail/util/Connection.java (modified) (10 diffs)
-
LogicMail/src/org/logicprobe/LogicMail/util/StringParser.java (modified) (1 diff)
-
LogicMailTests/src/org/logicprobe/LogicMail/mail/NetworkMailStoreTest.java (modified) (1 diff)
-
LogicMailTests/src/org/logicprobe/LogicMail/mail/imap/ImapProtocolTest.java (modified) (12 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LogicMail/LogicMail.jdp
r469 r471 108 108 src\org\logicprobe\LogicMail\mail\MailException.java 109 109 src\org\logicprobe\LogicMail\mail\MailFactory.java 110 src\org\logicprobe\LogicMail\mail\MailProgressHandler.java 110 111 src\org\logicprobe\LogicMail\mail\MailSenderEvent.java 111 112 src\org\logicprobe\LogicMail\mail\MailSenderListener.java -
trunk/LogicMail/src/org/logicprobe/LogicMail/LogicMail.rrc
r470 r471 70 70 MAILCONNECTION_CLOSING_CONNECTION#0="Closing connection..."; 71 71 MAILCONNECTION_OPENING_CONNECTION#0="Opening connection..."; 72 MAILCONNECTION_REQUEST_FOLDER_MESSAGES#0="Getting folder messages ...";72 MAILCONNECTION_REQUEST_FOLDER_MESSAGES#0="Getting folder messages"; 73 73 MAILCONNECTION_REQUEST_FOLDER_STATUS#0="Refreshing folder status..."; 74 74 MAILCONNECTION_REQUEST_FOLDER_TREE#0="Getting folder tree..."; -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/AbstractMailConnectionHandler.java
r470 r471 40 40 import org.logicprobe.LogicMail.LogicMailResource; 41 41 import org.logicprobe.LogicMail.util.Queue; 42 import org.logicprobe.LogicMail.util.StringParser; 42 43 43 44 /** … … 417 418 protected void showStatus(String message, int progress) { 418 419 MailConnectionManager.getInstance().fireMailConnectionStatus(client.getConnectionConfig(), message, progress); 420 } 421 422 /** 423 * Gets a progress handler for a request with the provided status message. 424 * <p> 425 * This default progress handler displays the message along with the 426 * amount of data downloaded for network updates, and percentage complete 427 * for processing updates. 428 * </p> 429 * 430 * @param message The status message for the request 431 * @return The progress handler 432 */ 433 protected MailProgressHandler getProgressHandler(String message) { 434 return new MailConnectionProgressHandler(message); 419 435 } 420 436 … … 613 629 } 614 630 } 631 632 /** 633 * Standard progress handler to be used for mail connection handlers. 634 * This takes the operation's message and appends a relevant status 635 * indicator to it. 636 */ 637 private class MailConnectionProgressHandler implements MailProgressHandler { 638 private int total = 0; 639 private int lastTotal = 0; 640 private int threshold = 128; 641 private String messageStart; 642 private String networkMessageEnd = ")..."; 643 private String processingMessageEnd = "%)..."; 644 645 public MailConnectionProgressHandler(String message) { 646 this.messageStart = message + " ("; 647 } 648 649 public void mailProgress(int type, int count, int max) { 650 if(type == MailProgressHandler.TYPE_NETWORK) { 651 total += count; 652 if((total - lastTotal) >= threshold) { 653 showStatus(messageStart + StringParser.toDataSizeString(total) + networkMessageEnd); 654 lastTotal = total; 655 if(threshold < 1024 && total >= 1024) { threshold = 1024; } 656 } 657 } 658 else if(type == MailProgressHandler.TYPE_PROCESSING && max > 0){ 659 if(count > 0) { count = count / max; } 660 showStatus(messageStart + count + processingMessageEnd); 661 } 662 } 663 }; 615 664 } -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/IncomingMailClient.java
r407 r471 41 41 * Provides a generic interface to different incoming mail protocols. 42 42 * This class allows most of the UI code to be protocol-agnostic. 43 * 43 * <p> 44 44 * Since a number of features may not be supported by all protocols, 45 * a variety of hasXXXX()methods are provided by this interface to45 * a variety of <tt>hasXXXX()</tt> methods are provided by this interface to 46 46 * determine whether those features exist. 47 * </p> 48 * <p> 49 * Methods that involve a noticeable amount of network traffic and/or 50 * parsing overhead take an instance of {@link MailProgressHandler} as 51 * a parameter. This allows more granular progress monitoring than would 52 * otherwise be available. 53 * </p> 47 54 */ 48 55 public interface IncomingMailClient extends MailClient { … … 83 90 * reference an invisible root node. Otherwise, this should 84 91 * reference the visible root folder. 85 * 92 * 93 * @param progressHandler the progress handler 94 * 86 95 * @return Root folder of the tree, and all children below it 87 * @throws IOException on I/O errors 88 * @throws MailException on protocol errors 89 */ 90 public abstract FolderTreeItem getFolderTree() 96 * 97 * @throws IOException on I/O errors 98 * @throws MailException on protocol errors 99 */ 100 public abstract FolderTreeItem getFolderTree(MailProgressHandler progressHandler) 91 101 throws IOException, MailException; 92 102 93 103 /** 94 104 * Refresh the folder status. 95 * 105 * 96 106 * @param folders The folders to refresh 97 * @throws IOException on I/O errors 98 * @throws MailException on protocol errors 99 */ 100 public abstract void refreshFolderStatus(FolderTreeItem[] folders) 107 * @param progressHandler the progress handler 108 * 109 * @throws IOException on I/O errors 110 * @throws MailException on protocol errors 111 */ 112 public abstract void refreshFolderStatus(FolderTreeItem[] folders, MailProgressHandler progressHandler) 101 113 throws IOException, MailException; 102 114 … … 150 162 /** 151 163 * Get a list of the messages in the selected folder. 152 * 164 * 153 165 * @param firstIndex Index of the first message 154 166 * @param lastIndex Index of the last message 167 * @param progressHandler the progress handler 168 * 155 169 * @return List of message envelopes 156 * @throws IOException on I/O errors 157 * @throws MailException on protocol errors 158 */ 159 public abstract FolderMessage[] getFolderMessages(int firstIndex, int lastIndex) 170 * 171 * @throws IOException on I/O errors 172 * @throws MailException on protocol errors 173 */ 174 public abstract FolderMessage[] getFolderMessages(int firstIndex, int lastIndex, MailProgressHandler progressHandler) 160 175 throws IOException, MailException; 161 176 … … 169 184 * did on the first invocation. 170 185 * 186 * @param progressHandler the progress handler 187 * 171 188 * @return List of message envelopes 172 * @throws IOException on I/O errors 173 * @throws MailException on protocol errors 174 */ 175 public abstract FolderMessage[] getNewFolderMessages() throws IOException, MailException; 189 * 190 * @throws IOException on I/O errors 191 * @throws MailException on protocol errors 192 */ 193 public abstract FolderMessage[] getNewFolderMessages(MailProgressHandler progressHandler) throws IOException, MailException; 176 194 177 195 /** … … 180 198 * protocol-specific capabilities, application-wide data 181 199 * format capabilities, and user configuration options. 182 * 183 * @throws IOException on I/O errors 184 * @throws MailException on protocol errors 185 */ 186 public abstract Message getMessage(MessageToken messageToken) throws IOException, MailException; 200 * 201 * @param messageToken the message token 202 * @param progressHandler the progress handler 203 * 204 * @return the message 205 * 206 * @throws IOException on I/O errors 207 * @throws MailException on protocol errors 208 */ 209 public abstract Message getMessage(MessageToken messageToken, MailProgressHandler progressHandler) throws IOException, MailException; 187 210 188 211 /** -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/IncomingMailConnectionHandler.java
r470 r471 201 201 202 202 private void handleRequestFolderTree() throws IOException, MailException { 203 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_TREE)); 204 FolderTreeItem root = incomingClient.getFolderTree(); 203 String message = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_TREE); 204 showStatus(message); 205 FolderTreeItem root = incomingClient.getFolderTree(getProgressHandler(message)); 205 206 206 207 MailConnectionHandlerListener listener = getListener(); … … 211 212 212 213 private void handleRequestFolderStatus(FolderTreeItem[] folders) throws IOException, MailException { 213 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_STATUS)); 214 incomingClient.refreshFolderStatus(folders); 214 String message = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_STATUS); 215 showStatus(message); 216 incomingClient.refreshFolderStatus(folders, getProgressHandler(message)); 215 217 216 218 MailConnectionHandlerListener listener = getListener(); … … 221 223 222 224 private void handleRequestFolderMessagesRange(FolderTreeItem folder, int firstIndex, int lastIndex) throws IOException, MailException { 223 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_MESSAGES)); 225 String message = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_MESSAGES); 226 showStatus(message + "..."); 224 227 checkActiveFolder(folder); 225 228 226 FolderMessage[] messages = incomingClient.getFolderMessages(firstIndex, lastIndex );229 FolderMessage[] messages = incomingClient.getFolderMessages(firstIndex, lastIndex, getProgressHandler(message)); 227 230 228 231 MailConnectionHandlerListener listener = getListener(); … … 245 248 246 249 private void handleRequestFolderMessagesRecent(FolderTreeItem folder) throws IOException, MailException { 247 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_MESSAGES)); 250 String message = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_FOLDER_MESSAGES); 251 showStatus(message + "..."); 248 252 checkActiveFolder(folder); 249 253 250 FolderMessage[] messages = incomingClient.getNewFolderMessages( );254 FolderMessage[] messages = incomingClient.getNewFolderMessages(getProgressHandler(message)); 251 255 252 256 MailConnectionHandlerListener listener = getListener(); … … 257 261 258 262 private void handleRequestMessage(MessageToken messageToken) throws IOException, MailException { 259 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_MESSAGE)); 263 String statusMessage = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_MESSAGE); 264 showStatus(statusMessage); 260 265 checkActiveFolder(messageToken); 261 266 262 Message message = incomingClient.getMessage(messageToken );267 Message message = incomingClient.getMessage(messageToken, getProgressHandler(statusMessage)); 263 268 264 269 MailConnectionHandlerListener listener = getListener(); … … 269 274 270 275 private void handleRequestMessageParts(MessageToken messageToken, MimeMessagePart[] messageParts) throws IOException, MailException { 271 showStatus(resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_MESSAGE)); 276 String statusMessage = resources.getString(LogicMailResource.MAILCONNECTION_REQUEST_MESSAGE); 277 showStatus(statusMessage); 272 278 checkActiveFolder(messageToken); 273 279 … … 279 285 for(int i=0; i<messageParts.length; i++) { 280 286 MimeMessageContent content = 281 ((org.logicprobe.LogicMail.mail.imap.ImapClient)incomingClient).getMessagePart(messageToken, messageParts[i] );287 ((org.logicprobe.LogicMail.mail.imap.ImapClient)incomingClient).getMessagePart(messageToken, messageParts[i], getProgressHandler(statusMessage)); 282 288 if(content != null) { 283 289 messageContentVector.addElement(content); -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapClient.java
r467 r471 46 46 import org.logicprobe.LogicMail.mail.IncomingMailClient; 47 47 import org.logicprobe.LogicMail.mail.MailException; 48 import org.logicprobe.LogicMail.mail.MailProgressHandler; 48 49 import org.logicprobe.LogicMail.mail.MessageToken; 49 50 import org.logicprobe.LogicMail.message.FolderMessage; … … 168 169 } 169 170 171 /* (non-Javadoc) 172 * @see org.logicprobe.LogicMail.mail.MailClient#open() 173 */ 170 174 public boolean open() throws IOException, MailException { 171 175 try { … … 204 208 if(nsPersonal == null) { 205 209 // Discover folder delimiter 206 Vector resp = imapProtocol.executeList("", "" );210 Vector resp = imapProtocol.executeList("", "", null); 207 211 if(resp.size() > 0) { 208 212 folderDelim = ((ImapProtocol.ListResponse)resp.elementAt(0)).delim; … … 222 226 } 223 227 228 /* (non-Javadoc) 229 * @see org.logicprobe.LogicMail.mail.MailClient#close() 230 */ 224 231 public void close() throws IOException, MailException { 225 232 if(connection.isConnected()) { … … 247 254 } 248 255 256 /* (non-Javadoc) 257 * @see org.logicprobe.LogicMail.mail.MailClient#isConnected() 258 */ 249 259 public boolean isConnected() { 250 260 return connection.isConnected(); 251 261 } 252 262 263 /* (non-Javadoc) 264 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getAcctConfig() 265 */ 253 266 public AccountConfig getAcctConfig() { 254 267 return accountConfig; 255 268 } 256 269 270 /* (non-Javadoc) 271 * @see org.logicprobe.LogicMail.mail.MailClient#getConnectionConfig() 272 */ 257 273 public ConnectionConfig getConnectionConfig() { 258 274 return getAcctConfig(); 259 275 } 260 276 277 /* (non-Javadoc) 278 * @see org.logicprobe.LogicMail.mail.MailClient#getUsername() 279 */ 261 280 public String getUsername() { 262 281 return username; 263 282 } 264 283 284 /* (non-Javadoc) 285 * @see org.logicprobe.LogicMail.mail.MailClient#setUsername(java.lang.String) 286 */ 265 287 public void setUsername(String username) { 266 288 this.username = username; 267 289 } 268 290 291 /* (non-Javadoc) 292 * @see org.logicprobe.LogicMail.mail.MailClient#getPassword() 293 */ 269 294 public String getPassword() { 270 295 return password; 271 296 } 272 297 298 /* (non-Javadoc) 299 * @see org.logicprobe.LogicMail.mail.MailClient#setPassword(java.lang.String) 300 */ 273 301 public void setPassword(String password) { 274 302 this.password = password; 275 303 } 276 304 305 /* (non-Javadoc) 306 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasFolders() 307 */ 277 308 public boolean hasFolders() { 278 309 return true; 279 310 } 280 311 312 /* (non-Javadoc) 313 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasUndelete() 314 */ 281 315 public boolean hasUndelete() { 282 316 return true; 283 317 } 284 318 319 /* (non-Javadoc) 320 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasIdle() 321 */ 285 322 public boolean hasIdle() { 286 323 return true; 287 324 } 288 325 289 public FolderTreeItem getFolderTree() throws IOException, MailException { 326 /* (non-Javadoc) 327 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getFolderTree(org.logicprobe.LogicMail.mail.MailProgressHandler) 328 */ 329 public FolderTreeItem getFolderTree(MailProgressHandler progressHandler) throws IOException, MailException { 290 330 FolderTreeItem rootItem = new FolderTreeItem("", "", folderDelim); 291 331 … … 296 336 if(folderPrefix != null && folderPrefix.length() > 0) { 297 337 FolderTreeItem fakeRootItem = new FolderTreeItem("", folderPrefix, folderDelim); 298 getFolderTreeImpl(fakeRootItem, 0, childrenExtension );338 getFolderTreeImpl(fakeRootItem, 0, childrenExtension, progressHandler); 299 339 300 340 // Since we have no way to find the inbox with a hard-coded prefix, … … 303 343 // safely ignore. Otherwise, create a folder item and add it. 304 344 try { 305 imapProtocol.executeStatus(new String[] { strINBOX } );345 imapProtocol.executeStatus(new String[] { strINBOX }, null); 306 346 FolderTreeItem inboxItem = new FolderTreeItem(rootItem, strINBOX, strINBOX, folderDelim, true, true); 307 347 rootItem.addChild(inboxItem); … … 318 358 } 319 359 else { 320 getFolderTreeImpl(rootItem, 0, childrenExtension );360 getFolderTreeImpl(rootItem, 0, childrenExtension, progressHandler); 321 361 } 322 362 … … 330 370 } 331 371 332 private void getFolderTreeImpl(FolderTreeItem baseFolder, int depth, boolean childrenExtension ) throws IOException, MailException {372 private void getFolderTreeImpl(FolderTreeItem baseFolder, int depth, boolean childrenExtension, MailProgressHandler progressHandler) throws IOException, MailException { 333 373 Vector respList; 334 374 if(depth == 0) { 335 respList = imapProtocol.executeList(baseFolder.getPath(), "%" );375 respList = imapProtocol.executeList(baseFolder.getPath(), "%", progressHandler); 336 376 } 337 377 else { 338 respList = imapProtocol.executeList(baseFolder.getPath() + baseFolder.getDelim(), "%" );378 respList = imapProtocol.executeList(baseFolder.getPath() + baseFolder.getDelim(), "%", progressHandler); 339 379 } 340 380 … … 347 387 // The folder has children, so lets go and list them 348 388 if(depth+1 < accountConfig.getMaxFolderDepth()) { 349 getFolderTreeImpl(childItem, depth+1, childrenExtension );389 getFolderTreeImpl(childItem, depth+1, childrenExtension, progressHandler); 350 390 } 351 391 } … … 357 397 // folder that matches the personal namespace prefix, so 358 398 // look for children anyways. 359 getFolderTreeImpl(childItem, depth+1, childrenExtension); 360 } 361 } 362 } 363 364 public void refreshFolderStatus(FolderTreeItem[] folders) throws IOException, MailException { 399 getFolderTreeImpl(childItem, depth+1, childrenExtension, progressHandler); 400 } 401 } 402 } 403 404 /* (non-Javadoc) 405 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#refreshFolderStatus(org.logicprobe.LogicMail.mail.FolderTreeItem[]) 406 */ 407 public void refreshFolderStatus(FolderTreeItem[] folders, MailProgressHandler progressHandler) throws IOException, MailException { 365 408 int i; 366 409 … … 379 422 380 423 // Execute the STATUS command on the folders 381 ImapProtocol.StatusResponse[] response = imapProtocol.executeStatus(mboxPathsArray );424 ImapProtocol.StatusResponse[] response = imapProtocol.executeStatus(mboxPathsArray, progressHandler); 382 425 383 426 // Iterate through the results and update the FolderTreeItem objects … … 447 490 } 448 491 492 /* (non-Javadoc) 493 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getActiveFolder() 494 */ 449 495 public FolderTreeItem getActiveFolder() { 450 496 return activeMailbox; 451 497 } 452 498 499 /* (non-Javadoc) 500 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#setActiveFolder(org.logicprobe.LogicMail.mail.FolderTreeItem) 501 */ 453 502 public void setActiveFolder(FolderTreeItem mailbox) throws IOException, MailException { 454 503 // Shortcut out if a folder change is not necessary … … 468 517 } 469 518 519 /* (non-Javadoc) 520 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#setActiveFolder(org.logicprobe.LogicMail.mail.MessageToken) 521 */ 470 522 public void setActiveFolder(MessageToken messageToken) throws IOException, MailException { 471 523 ImapMessageToken imapMessageToken = (ImapMessageToken)messageToken; … … 504 556 } 505 557 506 public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex) throws IOException, MailException { 558 /* (non-Javadoc) 559 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getFolderMessages(int, int, org.logicprobe.LogicMail.mail.MailProgressHandler) 560 */ 561 public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex, MailProgressHandler progressHandler) throws IOException, MailException { 507 562 // Sanity check 508 563 if(activeMailbox == null) { … … 516 571 517 572 ImapProtocol.FetchEnvelopeResponse[] response = 518 imapProtocol.executeFetchEnvelope(firstIndex, lastIndex );573 imapProtocol.executeFetchEnvelope(firstIndex, lastIndex, progressHandler); 519 574 520 575 return prepareFolderMessages(response); 521 576 } 522 577 523 public FolderMessage[] getNewFolderMessages() throws IOException, MailException { 578 /* (non-Javadoc) 579 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getNewFolderMessages(org.logicprobe.LogicMail.mail.MailProgressHandler) 580 */ 581 public FolderMessage[] getNewFolderMessages(MailProgressHandler progressHandler) throws IOException, MailException { 524 582 // Sanity check 525 583 if(activeMailbox == null) { … … 532 590 int msgCount = activeMailbox.getMsgCount(); 533 591 int firstIndex = Math.max(1, msgCount - count); 534 result = getFolderMessages(firstIndex, activeMailbox.getMsgCount() );592 result = getFolderMessages(firstIndex, activeMailbox.getMsgCount(), progressHandler); 535 593 seenMailboxes.put(activeMailbox, new Object()); 536 594 } … … 538 596 int uidNext = ((ImapProtocol.SelectResponse)knownMailboxes.get(activeMailbox)).uidNext; 539 597 ImapProtocol.FetchEnvelopeResponse[] response = 540 imapProtocol.executeFetchEnvelopeUid(uidNext );598 imapProtocol.executeFetchEnvelopeUid(uidNext, progressHandler); 541 599 result = prepareFolderMessages(response); 542 600 … … 569 627 } 570 628 571 public Message getMessage(MessageToken messageToken) throws IOException, MailException { 629 /* (non-Javadoc) 630 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.mail.MailProgressHandler) 631 */ 632 public Message getMessage(MessageToken messageToken, MailProgressHandler progressHandler) throws IOException, MailException { 572 633 ImapMessageToken imapMessageToken = (ImapMessageToken)messageToken; 573 634 if(!imapMessageToken.getFolderPath().equalsIgnoreCase(activeMailbox.getPath())) { … … 579 640 MimeMessagePart rootPart = 580 641 getMessagePart(contentMap, imapMessageToken.getMessageUid(), 581 structure, accountConfig.getMaxMessageSize()); 642 structure, accountConfig.getMaxMessageSize(), 643 progressHandler); 582 644 Message msg = new Message(rootPart); 583 645 Enumeration e = contentMap.keys(); … … 589 651 } 590 652 591 public MimeMessageContent getMessagePart(MessageToken messageToken, MimeMessagePart mimeMessagePart ) throws IOException, MailException {653 public MimeMessageContent getMessagePart(MessageToken messageToken, MimeMessagePart mimeMessagePart, MailProgressHandler progressHandler) throws IOException, MailException { 592 654 ImapMessageToken imapMessageToken = (ImapMessageToken)messageToken; 593 655 if(!imapMessageToken.getFolderPath().equalsIgnoreCase(activeMailbox.getPath())) { … … 607 669 608 670 609 String data = getMessageBody(imapMessageToken.getMessageUid(), partAddress );671 String data = getMessageBody(imapMessageToken.getMessageUid(), partAddress, progressHandler); 610 672 MimeMessageContent content; 611 673 try { … … 621 683 int uid, 622 684 ImapParser.MessageSection structure, 623 int maxSize) 685 int maxSize, 686 MailProgressHandler progressHandler) 624 687 throws IOException, MailException 625 688 { … … 631 694 else { 632 695 if(structure.size < maxSize) { 633 data = getMessageBody(uid, structure.address );696 data = getMessageBody(uid, structure.address, progressHandler); 634 697 maxSize -= structure.size; 635 698 } … … 666 729 if((part instanceof MultiPart)&&(structure.subsections != null)&&(structure.subsections.length > 0)) { 667 730 for(int i=0;i<structure.subsections.length;i++) { 668 MimeMessagePart subPart = getMessagePart(contentMap, uid, structure.subsections[i], maxSize );731 MimeMessagePart subPart = getMessagePart(contentMap, uid, structure.subsections[i], maxSize, progressHandler); 669 732 if(subPart != null) { 670 733 ((MultiPart)part).addPart(subPart); … … 731 794 } 732 795 733 private String getMessageBody(int uid, String address ) throws IOException, MailException {796 private String getMessageBody(int uid, String address, MailProgressHandler progressHandler) throws IOException, MailException { 734 797 if(activeMailbox.equals("")) { 735 798 throw new MailException("Mailbox not selected"); 736 799 } 737 738 return imapProtocol.executeFetchBody(uid, address); 739 } 740 800 return imapProtocol.executeFetchBody(uid, address, progressHandler); 801 } 802 803 /* (non-Javadoc) 804 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#deleteMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.message.MessageFlags) 805 */ 741 806 public void deleteMessage(MessageToken messageToken, MessageFlags messageFlags) throws IOException, MailException { 742 807 ImapMessageToken imapMessageToken = (ImapMessageToken)messageToken; … … 751 816 752 817 818 /* (non-Javadoc) 819 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#undeleteMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.message.MessageFlags) 820 */ 753 821 public void undeleteMessage(MessageToken messageToken, MessageFlags messageFlags) throws IOException, MailException { 754 822 ImapMessageToken imapMessageToken = (ImapMessageToken)messageToken; … … 810 878 } 811 879 880 /* (non-Javadoc) 881 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#noop() 882 */ 812 883 public boolean noop() throws IOException, MailException { 813 884 boolean result = imapProtocol.executeNoop(); … … 815 886 } 816 887 888 /* (non-Javadoc) 889 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModeBegin() 890 */ 817 891 public void idleModeBegin() throws IOException, MailException { 818 892 imapProtocol.executeIdle(); 819 893 } 820 894 895 /* (non-Javadoc) 896 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModeEnd() 897 */ 821 898 public void idleModeEnd() throws IOException, MailException { 822 899 imapProtocol.executeIdleDone(); 823 900 } 824 901 902 /* (non-Javadoc) 903 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModePoll() 904 */ 825 905 public boolean idleModePoll() throws IOException, MailException { 826 906 return imapProtocol.executeIdlePoll(); -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapProtocol.java
r434 r471 36 36 import org.logicprobe.LogicMail.AppInfo; 37 37 import org.logicprobe.LogicMail.mail.MailException; 38 import org.logicprobe.LogicMail.mail.MailProgressHandler; 38 39 import org.logicprobe.LogicMail.message.MessageEnvelope; 39 40 import org.logicprobe.LogicMail.util.Connection; … … 82 83 execute("LOGIN", 83 84 "\"" + StringParser.addEscapedChars(username) + "\" \"" + 84 StringParser.addEscapedChars(password) + "\"" );85 StringParser.addEscapedChars(password) + "\"", null); 85 86 } catch (MailException exp) { 86 87 // Invalid users are caught by execute() … … 102 103 } 103 104 104 execute("LOGOUT", null );105 execute("LOGOUT", null, null); 105 106 } 106 107 … … 115 116 } 116 117 117 execute("CLOSE", null );118 execute("CLOSE", null, null); 118 119 } 119 120 … … 130 131 } 131 132 132 String[] replyText = execute("CAPABILITY", null );133 String[] replyText = execute("CAPABILITY", null, null); 133 134 134 135 if ((replyText == null) || (replyText.length < 1)) { … … 160 161 } 161 162 162 String[] replyText = execute("NAMESPACE", null );163 String[] replyText = execute("NAMESPACE", null, null); 163 164 164 165 if ((replyText == null) || (replyText.length < 1)) { … … 276 277 277 278 String[] replyText = execute("SELECT", 278 "\"" + StringParser.addEscapedChars(mboxpath) + "\"" );279 "\"" + StringParser.addEscapedChars(mboxpath) + "\"", null); 279 280 SelectResponse response = new SelectResponse(); 280 281 … … 351 352 } 352 353 353 public StatusResponse[] executeStatus(String[] mboxpaths )354 public StatusResponse[] executeStatus(String[] mboxpaths, MailProgressHandler progressHandler) 354 355 throws IOException, MailException { 355 356 if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { … … 380 381 } 381 382 382 String[] result = executeBatch("STATUS", arguments );383 String[] result = executeBatch("STATUS", arguments, progressHandler); 383 384 384 385 if ((result == null) || (result.length != arguments.length)) { … … 432 433 */ 433 434 public FetchEnvelopeResponse[] executeFetchEnvelope(int firstIndex, 434 int lastIndex ) throws IOException, MailException {435 int lastIndex, MailProgressHandler progressHandler) throws IOException, MailException { 435 436 if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 436 437 EventLogger.logEvent(AppInfo.GUID, … … 441 442 String[] rawList = execute("FETCH", 442 443 Integer.toString(firstIndex) + ":" + 443 Integer.toString(lastIndex) + " (FLAGS UID ENVELOPE BODYSTRUCTURE)" );444 445 return prepareFetchEnvelopeResponse(rawList );444 Integer.toString(lastIndex) + " (FLAGS UID ENVELOPE BODYSTRUCTURE)", progressHandler); 445 446 return prepareFetchEnvelopeResponse(rawList, progressHandler); 446 447 } 447 448 … … 451 452 * @return Array of FetchEnvelopeResponse objects 452 453 */ 453 public FetchEnvelopeResponse[] executeFetchEnvelopeUid(int uidNext )454 public FetchEnvelopeResponse[] executeFetchEnvelopeUid(int uidNext, MailProgressHandler progressHandler) 454 455 throws IOException, MailException { 455 456 if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { … … 460 461 461 462 String[] rawList = execute("UID FETCH", 462 Integer.toString(uidNext) + ":*" + " (FLAGS UID ENVELOPE BODYSTRUCTURE)" );463 464 return prepareFetchEnvelopeResponse(rawList );463 Integer.toString(uidNext) + ":*" + " (FLAGS UID ENVELOPE BODYSTRUCTURE)", progressHandler); 464 465 return prepareFetchEnvelopeResponse(rawList, progressHandler); 465 466 } 466 467 467 468 private FetchEnvelopeResponse[] prepareFetchEnvelopeResponse( 468 String[] rawList ) throws IOException, MailException {469 String[] rawList, MailProgressHandler progressHandler) throws IOException, MailException { 469 470 // Preprocess the returned text to clean up mid-field line breaks 470 471 // This should all become unnecessary once execute() … … 474 475 Vector rawList2 = new Vector(); 475 476 477 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, 0, -1); } 476 478 for (int i = 0; i < rawList.length; i++) { 477 479 line = rawList[i]; … … 494 496 int size = rawList2.size(); 495 497 498 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, 0, size); } 496 499 for (int i = 0; i < size; i++) { 497 500 try { … … 567 570 System.err.println("Parse error: " + exp); 568 571 } 572 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, i, size); } 569 573 } 570 574 571 575 FetchEnvelopeResponse[] result = new FetchEnvelopeResponse[envResponses.size()]; 572 576 envResponses.copyInto(result); 577 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, size, size); } 573 578 574 579 return result; … … 588 593 } 589 594 590 String[] rawList = execute("UID FETCH", uid + " (BODYSTRUCTURE)" );595 String[] rawList = execute("UID FETCH", uid + " (BODYSTRUCTURE)", null); 591 596 592 597 // Pre-process the returned text to clean up mid-field line breaks … … 632 637 * @param uid Unique ID of the message 633 638 * @param address Address of the body section (i.e. "1", "1.2") 639 * @param progressHandler the progress handler 634 640 * @return Body text as a string 635 641 */ 636 public String executeFetchBody(int uid, String address )642 public String executeFetchBody(int uid, String address, MailProgressHandler progressHandler) 637 643 throws IOException, MailException { 638 644 if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { … … 642 648 } 643 649 644 String[] rawList = execute("UID FETCH", uid + " (BODY[" + address + 645 "])"); 650 String[] rawList = execute( 651 "UID FETCH", 652 uid + " (BODY[" + address + "])", 653 progressHandler); 646 654 647 655 if (rawList.length <= 1) { … … 741 749 buf.append(')'); 742 750 743 String[] rawList = execute("UID STORE", buf.toString() );751 String[] rawList = execute("UID STORE", buf.toString(), null); 744 752 745 753 if (rawList.length < 1) { … … 807 815 808 816 /** 809 * Execute the "LIST" command, and return a fully parsed response 817 * Execute the "LIST" command, and return a fully parsed response. 818 * 810 819 * @param refName Reference name 811 820 * @param mboxName Mailbox name or wildcards (i.e. "%") 821 * @param progressHandler the progress handler 812 822 * @return Vector of ListResponse objects 813 823 */ 814 public Vector executeList(String refName, String mboxName )824 public Vector executeList(String refName, String mboxName, MailProgressHandler progressHandler) 815 825 throws IOException, MailException { 816 826 if (EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { … … 823 833 results = execute("LIST", 824 834 "\"" + StringParser.addEscapedChars(refName) + "\" \"" + 825 StringParser.addEscapedChars(mboxName) + "\"" );835 StringParser.addEscapedChars(mboxName) + "\"", progressHandler); 826 836 827 837 Vector retVec = new Vector(results.length); … … 837 847 int line = 0; 838 848 849 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, 0, -1); } 850 839 851 while (line < results.length) { 840 852 p = results[line].indexOf('{'); … … 855 867 int resultsSize = resultsVec.size(); 856 868 869 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, 0, resultsSize); } 857 870 for (int i = 0; i < resultsSize; i++) { 858 871 // Separate out the flag and argument strings … … 943 956 // Prevent parse errors from being fatal 944 957 } 945 } 958 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, i, resultsSize); } 959 } 960 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_PROCESSING, resultsSize, resultsSize); } 946 961 947 962 return retVec; … … 959 974 EventLogger.DEBUG_INFO); 960 975 } 961 String[] replyText = execute("NOOP", null );976 String[] replyText = execute("NOOP", null, null); 962 977 963 978 if ((replyText == null) || (replyText.length < 1)) { … … 1026 1041 * @param command IMAP command 1027 1042 * @param arguments Arguments for the commands 1043 * @param progressHandler the progress handler 1028 1044 * @return List of returned strings 1029 1045 */ 1030 protected String[] executeBatch(String command, String[] arguments )1046 protected String[] executeBatch(String command, String[] arguments, MailProgressHandler progressHandler) 1031 1047 throws IOException, MailException { 1032 1048 String[] result = new String[arguments.length]; … … 1047 1063 } 1048 1064 1065 int preCount = connection.getBytesReceived(); 1049 1066 connection.sendRaw(commandBuf.toString()); 1067 int postCount = connection.getBytesReceived(); 1068 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 1050 1069 1051 1070 String temp; … … 1054 1073 1055 1074 while (count < arguments.length) { 1075 preCount = postCount; 1056 1076 temp = connection.receive(); 1077 postCount = connection.getBytesReceived(); 1078 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 1057 1079 1058 1080 String temp2 = temp.substring(temp.indexOf(" ") + 1); … … 1083 1105 * @return List of returned strings 1084 1106 */ 1085 protected String[] execute(String command, String arguments )1107 protected String[] execute(String command, String arguments, MailProgressHandler progressHandler) 1086 1108 throws IOException, MailException { 1087 1109 String[] result = new String[0]; … … 1091 1113 ((arguments == null) ? "" : (" " + arguments))); 1092 1114 1115 int preCount = connection.getBytesReceived(); 1093 1116 String temp = connection.receive(); 1094 1117 int postCount = connection.getBytesReceived(); 1118 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 1119 1095 1120 while (!temp.startsWith(tag)) { 1096 1121 Arrays.add(result, temp); 1122 preCount = postCount; 1097 1123 temp = connection.receive(); 1124 postCount = connection.getBytesReceived(); 1125 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 1098 1126 } 1099 1127 -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopClient.java
r467 r471 46 46 import org.logicprobe.LogicMail.mail.IncomingMailClient; 47 47 import org.logicprobe.LogicMail.mail.MailException; 48 import org.logicprobe.LogicMail.mail.MailProgressHandler; 48 49 import org.logicprobe.LogicMail.mail.MessageToken; 49 50 import org.logicprobe.LogicMail.message.FolderMessage; … … 132 133 } 133 134 135 /* (non-Javadoc) 136 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getAcctConfig() 137 */ 134 138 public AccountConfig getAcctConfig() { 135 139 return accountConfig; 136 140 } 137 141 142 /* (non-Javadoc) 143 * @see org.logicprobe.LogicMail.mail.MailClient#getConnectionConfig() 144 */ 138 145 public ConnectionConfig getConnectionConfig() { 139 146 return getAcctConfig(); 140 147 } 141 148 149 /* (non-Javadoc) 150 * @see org.logicprobe.LogicMail.mail.MailClient#open() 151 */ 142 152 public boolean open() throws IOException, MailException { 143 153 if(!openStarted) { … … 162 172 } 163 173 174 /* (non-Javadoc) 175 * @see org.logicprobe.LogicMail.mail.MailClient#close() 176 */ 164 177 public void close() throws IOException, MailException { 165 178 if(connection.isConnected()) { … … 182 195 } 183 196 197 /* (non-Javadoc) 198 * @see org.logicprobe.LogicMail.mail.MailClient#isConnected() 199 */ 184 200 public boolean isConnected() { 185 201 return connection.isConnected(); 186 202 } 187 203 204 /* (non-Javadoc) 205 * @see org.logicprobe.LogicMail.mail.MailClient#getUsername() 206 */ 188 207 public String getUsername() { 189 208 return username; 190 209 } 191 210 211 /* (non-Javadoc) 212 * @see org.logicprobe.LogicMail.mail.MailClient#setUsername(java.lang.String) 213 */ 192 214 public void setUsername(String username) { 193 215 this.username = username; 194 216 } 195 217 218 /* (non-Javadoc) 219 * @see org.logicprobe.LogicMail.mail.MailClient#getPassword() 220 */ 196 221 public String getPassword() { 197 222 return password; 198 223 } 199 224 225 /* (non-Javadoc) 226 * @see org.logicprobe.LogicMail.mail.MailClient#setPassword(java.lang.String) 227 */ 200 228 public void setPassword(String password) { 201 229 this.password = password; 202 230 } 203 231 232 /* (non-Javadoc) 233 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasFolders() 234 */ 204 235 public boolean hasFolders() { 205 236 return false; 206 237 } 207 238 239 /* (non-Javadoc) 240 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasUndelete() 241 */ 208 242 public boolean hasUndelete() { 209 243 return false; 210 244 } 211 245 246 /* (non-Javadoc) 247 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#hasIdle() 248 */ 212 249 public boolean hasIdle() { 213 250 return false; 214 251 } 215 252 216 public FolderTreeItem getFolderTree() throws IOException, MailException { 253 /* (non-Javadoc) 254 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getFolderTree(org.logicprobe.LogicMail.mail.MailProgressHandler) 255 */ 256 public FolderTreeItem getFolderTree(MailProgressHandler progressHandler) throws IOException, MailException { 217 257 return null; 218 258 } 219 259 220 public void refreshFolderStatus(FolderTreeItem[] folders) throws IOException, MailException { 221 // Only one mailbox can exist, so we just pull the message counts 260 /* (non-Javadoc) 261 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#refreshFolderStatus(org.logicprobe.LogicMail.mail.FolderTreeItem[], org.logicprobe.LogicMail.mail.MailProgressHandler) 262 */ 263 public void refreshFolderStatus(FolderTreeItem[] folders, MailProgressHandler progressHandler) throws IOException, MailException { 264 // Only one mailbox can exist, so we just pull the message counts. 265 // Since this is a single operation with POP, there is no reason to 266 // provide more detailed status through the progress handler. 222 267 activeMailbox.setMsgCount(popProtocol.executeStat()); 223 268 if(folders.length == 1 && folders[0] != activeMailbox) { … … 226 271 } 227 272 273 /* (non-Javadoc) 274 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getInboxFolder() 275 */ 228 276 public FolderTreeItem getInboxFolder() { 229 277 return activeMailbox; 230 278 } 231 279 280 /* (non-Javadoc) 281 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getActiveFolder() 282 */ 232 283 public FolderTreeItem getActiveFolder() { 233 284 return activeMailbox; 234 285 } 235 286 287 /* (non-Javadoc) 288 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#setActiveFolder(org.logicprobe.LogicMail.mail.FolderTreeItem) 289 */ 236 290 public void setActiveFolder(FolderTreeItem mailbox) throws IOException, MailException { 237 291 // Mailbox cannot be changed, so we just pull the message counts … … 239 293 } 240 294 295 /* (non-Javadoc) 296 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#setActiveFolder(org.logicprobe.LogicMail.mail.MessageToken) 297 */ 241 298 public void setActiveFolder(MessageToken messageToken) throws IOException, MailException { 242 299 // Mailbox cannot be changed, so we just pull the message counts … … 244 301 } 245 302 246 public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex) throws IOException, MailException { 247 FolderMessage[] folderMessages = new FolderMessage[(lastIndex - firstIndex)+1]; 303 /* (non-Javadoc) 304 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getFolderMessages(int, int, org.logicprobe.LogicMail.mail.MailProgressHandler) 305 */ 306 public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex, MailProgressHandler progressHandler) throws IOException, MailException { 307 FolderMessage[] folderMessages = new FolderMessage[(lastIndex - firstIndex)+1]; 248 308 int index = 0; 249 309 String[] headerText; 250 310 String uid; 251 311 MessageEnvelope env; 312 int preCount; 313 int postCount = connection.getBytesReceived(); 252 314 for(int i=firstIndex; i<=lastIndex; i++) { 315 preCount = postCount; 253 316 headerText = popProtocol.executeTop(i, 0); 254 317 uid = popProtocol.executeUidl(i); … … 257 320 new PopMessageToken(i, uid), 258 321 env, i, uid.hashCode()); 322 postCount = connection.getBytesReceived(); 323 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 259 324 } 260 325 return folderMessages; 261 326 } 262 327 263 public FolderMessage[] getNewFolderMessages() throws IOException, MailException { 328 /* (non-Javadoc) 329 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getNewFolderMessages(org.logicprobe.LogicMail.mail.MailProgressHandler) 330 */ 331 public FolderMessage[] getNewFolderMessages(MailProgressHandler progressHandler) throws IOException, MailException { 264 332 int count = MailSettings.getInstance().getGlobalConfig().getRetMsgCount(); 265 333 int msgCount = activeMailbox.getMsgCount(); 266 334 int firstIndex = Math.max(1, msgCount - count); 267 return getFolderMessages(firstIndex, activeMailbox.getMsgCount()); 268 } 269 270 public Message getMessage(MessageToken messageToken) throws IOException, MailException { 335 return getFolderMessages(firstIndex, activeMailbox.getMsgCount(), progressHandler); 336 } 337 338 /* (non-Javadoc) 339 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#getMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.mail.MailProgressHandler) 340 */ 341 public Message getMessage(MessageToken messageToken, MailProgressHandler progressHandler) throws IOException, MailException { 271 342 PopMessageToken popMessageToken = (PopMessageToken)messageToken; 272 343 … … 275 346 276 347 // Download the message text 277 String[] message = popProtocol.executeTop((popMessageToken.getMessageIndex()), maxLines );348 String[] message = popProtocol.executeTop((popMessageToken.getMessageIndex()), maxLines, progressHandler); 278 349 279 350 Hashtable contentMap = new Hashtable(); … … 288 359 } 289 360 361 /* (non-Javadoc) 362 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#deleteMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.message.MessageFlags) 363 */ 290 364 public void deleteMessage(MessageToken messageToken, MessageFlags messageFlags) throws IOException, MailException { 291 365 PopMessageToken popMessageToken = (PopMessageToken)messageToken; … … 295 369 } 296 370 371 /* (non-Javadoc) 372 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#undeleteMessage(org.logicprobe.LogicMail.mail.MessageToken, org.logicprobe.LogicMail.message.MessageFlags) 373 */ 297 374 public void undeleteMessage(MessageToken messageToken, MessageFlags messageFlags) throws IOException, MailException { 298 375 // Undelete is not supported, so we do nothing here. 299 376 } 300 377 378 /* (non-Javadoc) 379 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#noop() 380 */ 301 381 public boolean noop() throws IOException, MailException { 302 382 popProtocol.executeNoop(); … … 304 384 } 305 385 386 /* (non-Javadoc) 387 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModeBegin() 388 */ 306 389 public void idleModeBegin() throws IOException, MailException { 307 390 // Idle mode is not supported, so we do nothing here. 308 391 } 309 392 393 /* (non-Javadoc) 394 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModeEnd() 395 */ 310 396 public void idleModeEnd() throws IOException, MailException { 311 397 // Idle mode is not supported, so we do nothing here. 312 398 } 313 399 400 /* (non-Javadoc) 401 * @see org.logicprobe.LogicMail.mail.IncomingMailClient#idleModePoll() 402 */ 314 403 public boolean idleModePoll() throws IOException, MailException { 315 404 // Idle mode is not supported, so we do nothing here. 316 405 return false; 317 406 } 318 319 407 } -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopProtocol.java
r303 r471 37 37 import org.logicprobe.LogicMail.AppInfo; 38 38 import org.logicprobe.LogicMail.mail.MailException; 39 import org.logicprobe.LogicMail.mail.MailProgressHandler; 39 40 import org.logicprobe.LogicMail.util.Connection; 40 41 … … 122 123 */ 123 124 public String[] executeTop(int index, int lines) throws IOException, MailException { 125 return executeTop(index, lines, null); 126 } 127 128 /** 129 * Execute the "TOP" command 130 * @param index Message index 131 * @param lines Number of lines to retrieve 132 * @param progressHandler progress handler 133 */ 134 public String[] executeTop(int index, int lines, MailProgressHandler progressHandler) throws IOException, MailException { 124 135 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 125 136 EventLogger.logEvent( … … 128 139 EventLogger.DEBUG_INFO); 129 140 } 130 return executeFollow("TOP " + index + " " + lines );141 return executeFollow("TOP " + index + " " + lines, progressHandler); 131 142 } 132 143 … … 188 199 * 189 200 * @param command The command to execute 201 * @param progressHandler progress handler 190 202 * @return An array of lines containing the response 191 203 */ 192 private String[] executeFollow(String command) throws IOException, MailException { 204 private String[] executeFollow(String command, MailProgressHandler progressHandler) throws IOException, MailException { 205 int preCount = connection.getBytesReceived(); 193 206 execute(command); 194 207 195 208 String buffer = connection.receive(); 209 int postCount = connection.getBytesReceived(); 210 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 211 196 212 String[] lines = new String[0]; 197 213 while(buffer != null && !buffer.equals(".")) { 198 214 Arrays.add(lines, buffer); 215 preCount = postCount; 199 216 buffer = connection.receive(); 217 postCount = connection.getBytesReceived(); 218 if(progressHandler != null) { progressHandler.mailProgress(MailProgressHandler.TYPE_NETWORK, (postCount - preCount), -1); } 200 219 } 201 220 return lines; -
trunk/LogicMail/src/org/logicprobe/LogicMail/ui/MessagePropertiesScreen.java
r467 r471 38 38 import org.logicprobe.LogicMail.model.Address; 39 39 import org.logicprobe.LogicMail.model.MessageNode; 40 import org.logicprobe.LogicMail.util.StringParser; 40 41 import org.logicprobe.LogicMail.util.UnicodeNormalizer; 41 42 … … 211 212 if(partSize > 0) { 212 213 buf.append(" ("); 213 if(partSize < 1024) { 214 buf.append(partSize); 215 buf.append('B'); 216 } 217 else { 218 partSize /= 1024; 219 buf.append(partSize); 220 buf.append("kB"); 221 } 214 buf.append(StringParser.toDataSizeString(partSize)); 222 215 buf.append(')'); 223 216 } -
trunk/LogicMail/src/org/logicprobe/LogicMail/util/Connection.java
r449 r471 119 119 private boolean useWiFi; 120 120 private int fakeAvailable = -1; 121 121 private int bytesSent = 0; 122 private int bytesReceived = 0; 123 122 124 /** 123 125 * Provides a buffer used for incoming data. … … 193 195 output = socket.openDataOutputStream(); 194 196 localAddress = ((SocketConnection) socket).getLocalAddress(); 195 197 bytesSent = 0; 198 bytesReceived = 0; 199 196 200 if (EventLogger.getMinimumLevel() >= EventLogger.INFORMATION) { 197 201 String msg = "Connection established:\r\n" + "Socket: " + … … 305 309 } 306 310 311 /** 312 * Gets the number of bytes that have been sent since the 313 * connection was opened. 314 * <p> 315 * The counter is not synchronized, so it should only be 316 * called from the same thread as the send and receive 317 * methods. 318 * </p> 319 * @return bytes sent 320 */ 321 public int getBytesSent() { 322 return bytesSent; 323 } 324 325 /** 326 * Gets the number of bytes that have been received since the 327 * connection was opened. 328 * <p> 329 * The counter is not synchronized, so it should only be 330 * called from the same thread as the send and receive 331 * methods. 332 * </p> 333 * @return bytes received 334 */ 335 public int getBytesReceived() { 336 return bytesReceived; 337 } 338 307 339 /** 308 340 * Sends a string to the server. This method is used internally for … … 328 360 329 361 output.write(CRLF, 0, 2); 362 bytesSent += 2; 330 363 } 331 364 /** … … 356 389 * Write the string up to there and terminate it properly. 357 390 */ 358 output.write((s.substring(i, j) + "\r\n").getBytes()); 391 byte[] buf = (s.substring(i, j) + "\r\n").getBytes(); 392 output.write(buf); 393 bytesSent += buf.length; 359 394 360 395 /** … … 386 421 if (s == null) { 387 422 output.write(CRLF, 0, 2); 423 bytesSent += 2; 388 424 } else { 389 output.write((s + "\r\n").getBytes()); 425 byte[] buf = (s + "\r\n").getBytes(); 426 output.write(buf); 427 bytesSent += buf.length; 390 428 } 391 429 … … 402 440 */ 403 441 public synchronized void sendRaw(String s) throws IOException { 404 byte[] b ytes= s.getBytes();442 byte[] buf = s.getBytes(); 405 443 406 444 if (globalConfig.getConnDebug()) { … … 409 447 } 410 448 411 output.write(bytes, 0, bytes.length); 412 449 output.write(buf, 0, buf.length); 450 bytesSent += buf.length; 451 413 452 output.flush(); 414 453 } … … 487 526 while (true) { 488 527 int actual = input.read(buffer, count, 1); 489 528 490 529 /** 491 530 * If -1 is returned, the InputStream is already closed, … … 524 563 // approach which screws up on mid-line LFs. (DK) 525 564 else { 565 bytesReceived += actual; 566 526 567 byte b = buffer[count]; 527 568 readBytes++; -
trunk/LogicMail/src/org/logicprobe/LogicMail/util/StringParser.java
r446 r471 1176 1176 return result; 1177 1177 } 1178 1179 /** 1180 * Converts a numerical byte quantity into a nicer human-readable 1181 * unit representation. 1182 * 1183 * @param dataSize Size in bytes 1184 * @return Printable string 1185 */ 1186 public static String toDataSizeString(int dataSize) { 1187 StringBuffer buf = new StringBuffer(); 1188 1189 if(dataSize < 1024) { 1190 buf.append(dataSize); 1191 buf.append('B'); 1192 } 1193 else { 1194 buf.append((int)(dataSize / 1024)); 1195 buf.append('k'); 1196 } 1197 1198 return buf.toString(); 1199 } 1178 1200 } -
trunk/LogicMailTests/src/org/logicprobe/LogicMail/mail/NetworkMailStoreTest.java
r453 r471 345 345 public FolderTreeItem getInboxFolder() { return inboxFolder; } 346 346 public FolderTreeItem getActiveFolder() { return activeFolder; } 347 public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex )347 public FolderMessage[] getFolderMessages(int firstIndex, int lastIndex, MailProgressHandler progressHandler) 348 348 throws IOException, MailException { this.firstIndex = firstIndex; this.lastIndex = lastIndex; return this.folderMessages; } 349 public FolderMessage[] getNewFolderMessages( ) throws IOException, MailException { return null; }350 public FolderTreeItem getFolderTree( ) throws IOException, MailException { return this.folderTree; }351 public Message getMessage(MessageToken messageToken )349 public FolderMessage[] getNewFolderMessages(MailProgressHandler progressHandler) throws IOException, MailException { return null; } 350 public FolderTreeItem getFolderTree(MailProgressHandler progressHandler) throws IOException, MailException { return this.folderTree; } 351 public Message getMessage(MessageToken messageToken, MailProgressHandler progressHandler) 352 352 throws IOException, MailException { this.messageToken = messageToken; return this.message; } 353 public void refreshFolderStatus(FolderTreeItem[] folders )353 public void refreshFolderStatus(FolderTreeItem[] folders, MailProgressHandler progressHandler) 354 354 throws IOException, MailException { folders[0].setMsgCount(refreshedMsgCount); } 355 355 public void setActiveFolder(FolderTreeItem folderItem) -
trunk/LogicMailTests/src/org/logicprobe/LogicMail/mail/imap/ImapProtocolTest.java
r435 r471 36 36 import j2meunit.framework.TestSuite; 37 37 38 import org.logicprobe.LogicMail.mail.MailProgressHandler; 38 39 import org.logicprobe.LogicMail.message.MessageEnvelope; 39 40 import org.logicprobe.LogicMail.util.StringParser; … … 154 155 new String[] { "* LIST (\\HasChildren) \".\" \"INBOX\"" }); 155 156 156 Vector result = instance.executeList("", "%" );157 Vector result = instance.executeList("", "%", null); 157 158 assertNotNull(result); 158 159 assertEquals(1, result.size()); … … 181 182 }); 182 183 183 Vector result = instance.executeList("INBOX.", "%" );184 Vector result = instance.executeList("INBOX.", "%", null); 184 185 assertNotNull(result); 185 186 assertEquals(2, result.size()); … … 216 217 }); 217 218 218 Vector result = instance.executeList("", "%" );219 Vector result = instance.executeList("", "%", null); 219 220 assertNotNull(result); 220 221 assertEquals(2, result.size()); … … 252 253 }); 253 254 254 Vector result = instance.executeList("INBOX.", "%" );255 Vector result = instance.executeList("INBOX.", "%", null); 255 256 assertNotNull(result); 256 257 assertEquals(2, result.size()); … … 287 288 }); 288 289 289 Vector result = instance.executeList("INBOX\\", "%" );290 Vector result = instance.executeList("INBOX\\", "%", null); 290 291 assertNotNull(result); 291 292 assertEquals(2, result.size()); … … 322 323 }); 323 324 324 Vector result = instance.executeList("2007\\", "%" );325 Vector result = instance.executeList("2007\\", "%", null); 325 326 assertNotNull(result); 326 327 assertEquals(2, result.size()); … … 363 364 }); 364 365 365 ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1 );366 ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1, null); 366 367 assertNotNull(result); 367 368 assertEquals(1, result.length); … … 447 448 }); 448 449 449 ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1 );450 ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1, null); 450 451 assertNotNull(result); 451 452 assertEquals(1, result.length); … … 531 532 }); 532 533 533 ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1 );534 ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1, null); 534 535 assertNotNull(result); 535 536 assertEquals(1, result.length); … … 618 619 }); 619 620 620 ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1 );621 ImapProtocol.FetchEnvelopeResponse[] result = instance.executeFetchEnvelope(1, 1, null); 621 622 assertNotNull(result); 622 623 assertEquals(1, result.length); … … 858 859 } 859 860 860 protected String[] execute(String command, String arguments ) {861 protected String[] execute(String command, String arguments, MailProgressHandler progressHandler) { 861 862 assertTrue("No expectations", !executeExpectations.isEmpty()); 862 863
Note: See TracChangeset
for help on using the changeset viewer.
