@@ -618,10 +618,11 @@ func (c *Client) readResponse() error {
618618 token string
619619 err error
620620 startTLS * startTLSCommand
621+ compress * compressCommand
621622 )
622623 if tag != "" {
623624 token = "response-tagged"
624- startTLS , err = c .readResponseTagged (tag , typ )
625+ startTLS , compress , err = c .readResponseTagged (tag , typ )
625626 } else {
626627 token = "response-data"
627628 err = c .readResponseData (typ )
@@ -637,6 +638,9 @@ func (c *Client) readResponse() error {
637638 if startTLS != nil {
638639 c .upgradeStartTLS (startTLS )
639640 }
641+ if compress != nil {
642+ c .upgradeCompress (compress )
643+ }
640644
641645 return nil
642646}
@@ -666,10 +670,10 @@ func (c *Client) readContinueReq() error {
666670 return nil
667671}
668672
669- func (c * Client ) readResponseTagged (tag , typ string ) (startTLS * startTLSCommand , err error ) {
673+ func (c * Client ) readResponseTagged (tag , typ string ) (startTLS * startTLSCommand , compress * compressCommand , err error ) {
670674 cmd := c .deletePendingCmdByTag (tag )
671675 if cmd == nil {
672- return nil , fmt .Errorf ("received tagged response with unknown tag %q" , tag )
676+ return nil , nil , fmt .Errorf ("received tagged response with unknown tag %q" , tag )
673677 }
674678
675679 // We've removed the command from the pending queue above. Make sure we
@@ -687,14 +691,14 @@ func (c *Client) readResponseTagged(tag, typ string) (startTLS *startTLSCommand,
687691 var code string
688692 if hasSP && c .dec .Special ('[' ) { // resp-text-code
689693 if ! c .dec .ExpectAtom (& code ) {
690- return nil , fmt .Errorf ("in resp-text-code: %v" , c .dec .Err ())
694+ return nil , nil , fmt .Errorf ("in resp-text-code: %v" , c .dec .Err ())
691695 }
692696 // TODO: LONGENTRIES and MAXSIZE from METADATA
693697 switch code {
694698 case "CAPABILITY" : // capability-data
695699 caps , err := readCapabilities (c .dec )
696700 if err != nil {
697- return nil , fmt .Errorf ("in capability-data: %v" , err )
701+ return nil , nil , fmt .Errorf ("in capability-data: %v" , err )
698702 }
699703 c .setCaps (caps )
700704 case "APPENDUID" :
@@ -703,19 +707,19 @@ func (c *Client) readResponseTagged(tag, typ string) (startTLS *startTLSCommand,
703707 uid imap.UID
704708 )
705709 if ! c .dec .ExpectSP () || ! c .dec .ExpectNumber (& uidValidity ) || ! c .dec .ExpectSP () || ! c .dec .ExpectUID (& uid ) {
706- return nil , fmt .Errorf ("in resp-code-apnd: %v" , c .dec .Err ())
710+ return nil , nil , fmt .Errorf ("in resp-code-apnd: %v" , c .dec .Err ())
707711 }
708712 if cmd , ok := cmd .(* AppendCommand ); ok {
709713 cmd .data .UID = uid
710714 cmd .data .UIDValidity = uidValidity
711715 }
712716 case "COPYUID" :
713717 if ! c .dec .ExpectSP () {
714- return nil , c .dec .Err ()
718+ return nil , nil , c .dec .Err ()
715719 }
716720 uidValidity , srcUIDs , dstUIDs , err := readRespCodeCopyUID (c .dec )
717721 if err != nil {
718- return nil , fmt .Errorf ("in resp-code-copy: %v" , err )
722+ return nil , nil , fmt .Errorf ("in resp-code-copy: %v" , err )
719723 }
720724 if cmd , ok := cmd .(* CopyCommand ); ok {
721725 cmd .data .UIDValidity = uidValidity
@@ -728,13 +732,13 @@ func (c *Client) readResponseTagged(tag, typ string) (startTLS *startTLSCommand,
728732 }
729733 }
730734 if ! c .dec .ExpectSpecial (']' ) {
731- return nil , fmt .Errorf ("in resp-text: %v" , c .dec .Err ())
735+ return nil , nil , fmt .Errorf ("in resp-text: %v" , c .dec .Err ())
732736 }
733737 hasSP = c .dec .SP ()
734738 }
735739 var text string
736740 if hasSP && ! c .dec .ExpectText (& text ) {
737- return nil , fmt .Errorf ("in resp-text: %v" , c .dec .Err ())
741+ return nil , nil , fmt .Errorf ("in resp-text: %v" , c .dec .Err ())
738742 }
739743
740744 var cmdErr error
@@ -748,14 +752,17 @@ func (c *Client) readResponseTagged(tag, typ string) (startTLS *startTLSCommand,
748752 Text : text ,
749753 }
750754 default :
751- return nil , fmt .Errorf ("in resp-cond-state: expected OK, NO or BAD status condition, but got %v" , typ )
755+ return nil , nil , fmt .Errorf ("in resp-cond-state: expected OK, NO or BAD status condition, but got %v" , typ )
752756 }
753757
754758 c .completeCommand (cmd , cmdErr )
755759
756760 if cmd , ok := cmd .(* startTLSCommand ); ok && cmdErr == nil {
757761 startTLS = cmd
758762 }
763+ if cmd , ok := cmd .(* compressCommand ); ok && cmdErr == nil {
764+ compress = cmd
765+ }
759766
760767 if cmdErr == nil && code != "CAPABILITY" {
761768 switch cmd .(type ) {
@@ -765,7 +772,7 @@ func (c *Client) readResponseTagged(tag, typ string) (startTLS *startTLSCommand,
765772 }
766773 }
767774
768- return startTLS , nil
775+ return startTLS , compress , nil
769776}
770777
771778func (c * Client ) readResponseData (typ string ) error {
0 commit comments