<commit_before>require 'mail'

module Savon
  module Multipart
    class Response < Savon::Response
      attr_reader :parts

      def initialize(*args)
        @parts = []
        super
      end

      def attachments
        if multipart?
          parse_body unless @has_parsed_body
          @parts.attachments
        else
          []
        end
      end

      def xml
        if multipart?
          parse_body unless @has_parsed_body
          @parts.first.body.to_s
        else
          super
        end
      end

      private
      def multipart?
        http.headers['content-type'] =~ /^multipart/
      end

      def boundary
        return unless multipart?
        @boundary ||= Mail::Field.new('content-type', http.headers['content-type']).parameters['boundary']
      end

      def parse_body
        @parts = Mail::Part.new(
          :headers => http.headers,
          :body => http.body
        ).body.split!(boundary).parts
        @has_parsed_body = true
      end
    end
  end
end<commit_msg>Fix multipart detection<commit_after>require 'mail'

module Savon
  module Multipart
    class Response < Savon::Response
      attr_reader :parts

      def initialize(*args)
        @parts = []
        super
      end

      def attachments
        if multipart?
          parse_body unless @has_parsed_body
          @parts.attachments
        else
          []
        end
      end

      def xml
        if multipart?
          parse_body unless @has_parsed_body
          @parts.first.body.to_s
        else
          super
        end
      end

      private
      def multipart?
        !(http.headers['content-type'] =~ /^multipart/).nil?
      end

      def boundary
        return unless multipart?
        @boundary ||= Mail::Field.new('content-type', http.headers['content-type']).parameters['boundary']
      end

      def parse_body
        @parts = Mail::Part.new(
          :headers => http.headers,
          :body => http.body
        ).body.split!(boundary).parts
        @has_parsed_body = true
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.08815028901734104, 'fraction_numerical': 0.0, 'mean_word_length': 1.635786802030457, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '498029', 'n_tokens_mistral': 590, 'n_tokens_neox': 575, 'n_words': 139}