Changeset 262
- Timestamp:
- 08/02/08 05:15:29 PM (4 months ago)
- Location:
- trunk/LogicMail/src/org/logicprobe/LogicMail
- Files:
-
- 6 modified
-
mail/imap/ImapClient.java (modified) (9 diffs)
-
mail/imap/ImapParser.java (modified) (2 diffs)
-
mail/imap/ImapProtocol.java (modified) (11 diffs)
-
mail/pop/PopClient.java (modified) (1 diff)
-
mail/pop/PopProtocol.java (modified) (1 diff)
-
message/FolderMessage.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapClient.java
r259 r262 377 377 FolderMessage[] folderMessages = new FolderMessage[response.length]; 378 378 for(int i=0;i<response.length;i++) { 379 folderMessages[i] = new FolderMessage(response[i].envelope, response[i].index );379 folderMessages[i] = new FolderMessage(response[i].envelope, response[i].index, response[i].uid); 380 380 folderMessages[i].setSeen(response[i].flags.seen); 381 381 folderMessages[i].setAnswered(response[i].flags.answered); … … 391 391 392 392 public Message getMessage(FolderMessage folderMessage) throws IOException, MailException { 393 ImapParser.MessageSection structure = getMessageStructure(folderMessage.get Index());393 ImapParser.MessageSection structure = getMessageStructure(folderMessage.getUid()); 394 394 MessagePart rootPart = 395 getMessagePart(folderMessage.get Index(),395 getMessagePart(folderMessage.getUid(), 396 396 structure, globalConfig.getImapMaxMsgSize()); 397 397 Message msg = new Message(folderMessage.getEnvelope(), rootPart); … … 399 399 } 400 400 401 private MessagePart getMessagePart(int index,401 private MessagePart getMessagePart(int uid, 402 402 ImapParser.MessageSection structure, 403 403 int maxSize) … … 411 411 else { 412 412 if(structure.size < maxSize) { 413 data = getMessageBody( index, structure.address);413 data = getMessageBody(uid, structure.address); 414 414 maxSize -= structure.size; 415 415 } … … 426 426 if((part instanceof MultiPart)&&(structure.subsections != null)&&(structure.subsections.length > 0)) { 427 427 for(int i=0;i<structure.subsections.length;i++) { 428 MessagePart subPart = getMessagePart( index, structure.subsections[i], maxSize);428 MessagePart subPart = getMessagePart(uid, structure.subsections[i], maxSize); 429 429 if(subPart != null) { 430 430 ((MultiPart)part).addPart(subPart); … … 439 439 * This tree is used to build the final message tree. 440 440 */ 441 private ImapParser.MessageSection getMessageStructure(int msgIndex) throws IOException, MailException {441 private ImapParser.MessageSection getMessageStructure(int uid) throws IOException, MailException { 442 442 if(activeMailbox.equals("")) { 443 443 throw new MailException("Mailbox not selected"); 444 444 } 445 445 446 return imapProtocol.executeFetchBodystructure( msgIndex);446 return imapProtocol.executeFetchBodystructure(uid); 447 447 } 448 448 … … 466 466 } 467 467 468 private String getMessageBody(int index, String address) throws IOException, MailException {468 private String getMessageBody(int uid, String address) throws IOException, MailException { 469 469 if(activeMailbox.equals("")) { 470 470 throw new MailException("Mailbox not selected"); 471 471 } 472 472 473 return imapProtocol.executeFetchBody( index, address);473 return imapProtocol.executeFetchBody(uid, address); 474 474 } 475 475 476 476 public void deleteMessage(FolderMessage folderMessage) throws IOException, MailException { 477 477 ImapProtocol.MessageFlags updatedFlags = 478 imapProtocol.executeStore(folderMessage.get Index(), true, new String[] { "\\Deleted" });478 imapProtocol.executeStore(folderMessage.getUid(), true, new String[] { "\\Deleted" }); 479 479 refreshMessageFlags(updatedFlags, folderMessage); 480 480 } … … 483 483 public void undeleteMessage(FolderMessage folderMessage) throws IOException, MailException { 484 484 ImapProtocol.MessageFlags updatedFlags = 485 imapProtocol.executeStore(folderMessage.get Index(), false, new String[] { "\\Deleted" });485 imapProtocol.executeStore(folderMessage.getUid(), false, new String[] { "\\Deleted" }); 486 486 refreshMessageFlags(updatedFlags, folderMessage); 487 487 } … … 495 495 public void messageAnswered(FolderMessage folderMessage) throws IOException, MailException { 496 496 ImapProtocol.MessageFlags updatedFlags = 497 imapProtocol.executeStore(folderMessage.get Index(), true, new String[] { "\\Answered" });497 imapProtocol.executeStore(folderMessage.getUid(), true, new String[] { "\\Answered" }); 498 498 refreshMessageFlags(updatedFlags, folderMessage); 499 499 } -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapParser.java
r198 r262 257 257 258 258 // Sanity checking 259 if(parsedText.size() < 2||260 !(parsedText.elementAt( 1) instanceof Vector)) {259 if(parsedText.size() < 4 || 260 !(parsedText.elementAt(3) instanceof Vector)) { 261 261 EventLogger.logEvent( 262 262 AppInfo.GUID, … … 266 266 } 267 267 268 Vector parsedStruct = (Vector)parsedText.elementAt( 1);268 Vector parsedStruct = (Vector)parsedText.elementAt(3); 269 269 MessageSection msgStructure = parseMessageStructureHelper(null, 1, parsedStruct); 270 270 fixMessageStructure(msgStructure); -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/imap/ImapProtocol.java
r255 r262 454 454 public static class FetchEnvelopeResponse { 455 455 public int index; 456 public int uid; 456 457 public MessageFlags flags; 457 458 public MessageEnvelope envelope; … … 459 460 460 461 /** 461 * Execute the "FETCH ( ENVELOPE)" command462 * Execute the "FETCH (FLAGS UID ENVELOPE)" command 462 463 * @param firstIndex Index of the first message 463 464 * @param lastIndex Index of the last message … … 475 476 Integer.toString(firstIndex) + ":" + 476 477 Integer.toString(lastIndex) + 477 " (FLAGS ENVELOPE)");478 " (FLAGS UID ENVELOPE)"); 478 479 479 480 FetchEnvelopeResponse[] envResponses = new FetchEnvelopeResponse[(lastIndex - firstIndex)+1]; … … 526 527 envRespItem.flags = ImapParser.parseMessageFlags((Vector)parsedText.elementAt(j+1)); 527 528 } 529 else if(((String)parsedText.elementAt(j)).equals("UID") && 530 parsedSize > j+1 && 531 parsedText.elementAt(j+1) instanceof String) { 532 try { 533 envRespItem.uid = Integer.parseInt((String)parsedText.elementAt(j+1)); 534 } catch (NumberFormatException e) { 535 envRespItem.uid = -1; 536 } 537 } 528 538 else if(((String)parsedText.elementAt(j)).equals("ENVELOPE") && 529 539 parsedSize > j+1 && … … 559 569 /** 560 570 * Execute the "FETCH (BODYSTRUCTURE)" command 561 * @param index Indexof the message571 * @param uid Unique ID of the message 562 572 * @return Body structure tree 563 573 */ 564 public ImapParser.MessageSection executeFetchBodystructure(int index) throws IOException, MailException {565 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 566 EventLogger.logEvent( 567 AppInfo.GUID, 568 ("ImapProtocol.executeFetchBodyStructure("+ index+")").getBytes(),569 EventLogger.DEBUG_INFO); 570 } 571 572 String[] rawList = execute(" FETCH", index+ " (BODYSTRUCTURE)");574 public ImapParser.MessageSection executeFetchBodystructure(int uid) throws IOException, MailException { 575 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 576 EventLogger.logEvent( 577 AppInfo.GUID, 578 ("ImapProtocol.executeFetchBodyStructure("+uid+")").getBytes(), 579 EventLogger.DEBUG_INFO); 580 } 581 582 String[] rawList = execute("UID FETCH", uid + " (BODYSTRUCTURE)"); 573 583 574 584 // Pre-process the returned text to clean up mid-field line breaks … … 607 617 /** 608 618 * Execute the "FETCH (BODY)" command 609 * @param index Indexof the message619 * @param uid Unique ID of the message 610 620 * @param address Address of the body section (i.e. "1", "1.2") 611 621 * @return Body text as a string 612 622 */ 613 public String executeFetchBody(int index, String address) throws IOException, MailException {614 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 615 EventLogger.logEvent( 616 AppInfo.GUID, 617 ("ImapProtocol.executeFetchBody("+ index+", \""+address+"\")").getBytes(),618 EventLogger.DEBUG_INFO); 619 } 620 621 String[] rawList = execute(" FETCH", index+ " (BODY["+ address +"])");623 public String executeFetchBody(int uid, String address) throws IOException, MailException { 624 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 625 EventLogger.logEvent( 626 AppInfo.GUID, 627 ("ImapProtocol.executeFetchBody("+uid+", \""+address+"\")").getBytes(), 628 EventLogger.DEBUG_INFO); 629 } 630 631 String[] rawList = execute("UID FETCH", uid + " (BODY["+ address +"])"); 622 632 623 633 if(rawList.length <= 1) { … … 636 646 /** 637 647 * Execute the "STORE" command to update message flags. 638 * @param index The message indexto modify.648 * @param uid The message unique ID to modify. 639 649 * @param addOrRemove True to add flags, false to remove them. 640 650 * @param flags Array of flags to change. (i.e. "\Seen", "\Answered") 641 651 * @return Updated standard message flags, or null if there was a parse error. 642 652 */ 643 public MessageFlags executeStore(int index, boolean addOrRemove, String[] flags) throws IOException, MailException {653 public MessageFlags executeStore(int uid, boolean addOrRemove, String[] flags) throws IOException, MailException { 644 654 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 645 655 StringBuffer buf = new StringBuffer(); … … 654 664 EventLogger.logEvent( 655 665 AppInfo.GUID, 656 ("ImapProtocol.executeStore("+ index+", "+(addOrRemove?"add":"remove")+", {"+buf.toString()+"})").getBytes(),666 ("ImapProtocol.executeStore("+uid+", "+(addOrRemove?"add":"remove")+", {"+buf.toString()+"})").getBytes(), 657 667 EventLogger.DEBUG_INFO); 658 668 } 659 669 660 670 StringBuffer buf = new StringBuffer(); 661 buf.append( index);671 buf.append(uid); 662 672 buf.append(' '); 663 673 buf.append(addOrRemove?'+':'-'); … … 670 680 } 671 681 buf.append(')'); 672 String[] rawList = execute(" STORE", buf.toString());682 String[] rawList = execute("UID STORE", buf.toString()); 673 683 if(rawList.length < 1) { 674 684 throw new MailException("Unable to set message flags"); … … 676 686 677 687 try { 678 int p = rawList[0].indexOf(' '); 679 int q = rawList[0].indexOf(' ', p+1); 680 int fetchIndex = Integer.parseInt(rawList[0].substring(p+1, q)); 681 if(fetchIndex != index) { 682 return null; 688 int p = rawList[0].indexOf("UID"); 689 int q = rawList[0].lastIndexOf(')'); 690 if(p != -1 && q != -1 && p < q) { 691 int fetchIndex = Integer.parseInt(rawList[0].substring(p+4, q)); 692 if(fetchIndex != uid) { 693 return null; 694 } 683 695 } 684 696 p = rawList[0].indexOf("FLAGS ("); 685 q = rawList[0].indexOf(") )");697 q = rawList[0].indexOf(") UID"); 686 698 if(p == -1 || q == -1) { 687 699 return null; … … 702 714 * Execute the "APPEND" command to add a message to an existing mailbox. 703 715 * @param mboxName Mailbox name. 704 * @param rawMessage The raw message text, in RFC2822-compl iant format.716 * @param rawMessage The raw message text, in RFC2822-complaint format. 705 717 * @param flags Flags to store the message with. 706 718 */ -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopClient.java
r259 r262 235 235 int index = 0; 236 236 String[] headerText; 237 String uid; 237 238 MessageEnvelope env; 238 239 for(int i=firstIndex; i<=lastIndex; i++) { 239 240 headerText = popProtocol.executeTop(i, 0); 241 uid = popProtocol.executeUidl(i); 240 242 env = PopParser.parseMessageEnvelope(headerText); 241 folderMessages[index++] = new FolderMessage(env, i );243 folderMessages[index++] = new FolderMessage(env, i, uid.hashCode()); 242 244 } 243 245 return folderMessages; -
trunk/LogicMail/src/org/logicprobe/LogicMail/mail/pop/PopProtocol.java
r172 r262 130 130 return executeFollow("TOP " + index + " " + lines); 131 131 } 132 132 133 /** 134 * Execute the "UIDL" command 135 * @param index Message index 136 */ 137 public String executeUidl(int index) throws IOException, MailException { 138 if(EventLogger.getMinimumLevel() >= EventLogger.DEBUG_INFO) { 139 EventLogger.logEvent( 140 AppInfo.GUID, 141 ("PopProtocol.executeUidl("+index+")").getBytes(), 142 EventLogger.DEBUG_INFO); 143 } 144 String result = execute("UIDL " + index); 145 int p = result.lastIndexOf(' '); 146 if(p < result.length() - 2) { 147 return result.substring(p+1); 148 } 149 else { 150 return null; 151 } 152 } 153 133 154 /** 134 155 * Execute the "DELE" command. -
trunk/LogicMail/src/org/logicprobe/LogicMail/message/FolderMessage.java
r253 r262 40 40 private MessageEnvelope envelope; 41 41 private int index; 42 private int uid; 42 43 private MessageFlags messageFlags; 43 44 … … 47 48 * @param index The index of the message within the folder 48 49 */ 49 public FolderMessage(MessageEnvelope envelope, int index ) {50 public FolderMessage(MessageEnvelope envelope, int index, int uid) { 50 51 this.envelope = envelope; 51 52 this.index = index; 53 this.uid = uid; 52 54 this.messageFlags = new MessageFlags(); 53 55 } … … 69 71 } 70 72 73 /** 74 * Get the unique ID of this message 75 * @return unique ID 76 */ 77 public int getUid() { 78 return uid; 79 } 80 71 81 /** 72 82 * Gets the flags associated with this message.
