- Timestamp:
- 08/02/08 05:15:29 PM (5 months ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
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 */
