Project

General

Profile

Feature #16626 ยป 0001-net-imap-Parsing-CAPABILITY-data-for-ResponseCode.patch

nevans (Nicholas Evans), 02/11/2020 06:48 PM

View differences:

lib/net/imap.rb
3112 3112
        token = match(T_ATOM)
3113 3113
        name = token.value.upcase
3114 3114
        match(T_SPACE)
3115
        UntaggedResponse.new(name, capability_data, @str)
3116
      end
3117

  
3118
      def capability_data
3115 3119
        data = []
3116 3120
        while true
3117 3121
          token = lookahead
3118 3122
          case token.symbol
3119
          when T_CRLF
3123
          when T_CRLF, T_RBRA
3120 3124
            break
3121 3125
          when T_SPACE
3122 3126
            shift_token
3123 3127
            next
3124 3128
          end
3125
          data.push(atom.upcase)
3129
          data.push(strict_atom.upcase)
3126 3130
        end
3127
        return UntaggedResponse.new(name, data, @str)
3131
        data
3128 3132
      end
3129 3133

  
3130 3134
      def resp_text
......
3154 3158
        when /\A(?:UIDVALIDITY|UIDNEXT|UNSEEN)\z/n
3155 3159
          match(T_SPACE)
3156 3160
          result = ResponseCode.new(name, number)
3161
        when /\A(?:CAPABILITY)\z/ni
3162
          result = ResponseCode.new(name, capability_data)
3157 3163
        else
3158 3164
          token = lookahead
3159 3165
          if token.symbol == T_SPACE
......
3297 3303
        return token.value.upcase
3298 3304
      end
3299 3305

  
3306
      # ATOM-CHAR in RFC3501 does not allow T_RBRA
3307
      def strict_atom
3308
        result = String.new
3309
        token = lookahead
3310
        while [T_ATOM, T_NUMBER, T_NIL, T_LBRA, T_PLUS].include? token.symbol
3311
          result.concat token.value.upcase
3312
          shift_token
3313
          token = lookahead
3314
        end
3315
        if result.empty?
3316
          parse_error("unexpected token %s", token.symbol)
3317
        else
3318
          return result
3319
        end
3320
      end
3321

  
3300 3322
      def atom
3301 3323
        result = String.new
3302 3324
        while true
test/net/imap/test_imap_response_parser.rb
234 234
    response = parser.parse("* CAPABILITY st11p00mm-iscream009 1Q49 XAPPLEPUSHSERVICE IMAP4 IMAP4rev1 SASL-IR AUTH=ATOKEN AUTH=PLAIN \r\n")
235 235
    assert_equal("CAPABILITY", response.name)
236 236
    assert_equal("AUTH=PLAIN", response.data.last)
237
    response = parser.parse("* OK [CAPABILITY IMAP4rev1 SASL-IR 1234 NIL THIS+THAT + AUTH=PLAIN ID] IMAP4rev1 Hello\r\n")
238
    assert_equal("OK", response.name)
239
    assert_equal(" IMAP4rev1 Hello", response.data.text)
240
    code = response.data.code
241
    assert_equal("CAPABILITY", code.name)
242
    assert_equal(
243
      ["IMAP4REV1", "SASL-IR", "1234", "NIL", "THIS+THAT", "+", "AUTH=PLAIN", "ID"],
244
      code.data
245
    )
237 246
  end
238 247

  
239 248
  def test_mixed_boundary
240
-