<commit_before># -*- coding: utf-8 -*-
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
require 'mail'
require 'jpmobile/mail'

describe "Jpmobile::Mail#receive" do
  include Jpmobile::Util

  before(:each) do
    @to = "<EMAIL>"
  end

  describe "PC mail" do
    before(:each) do
      @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/pc-mail-single.eml")).read)
    end

    it "subject should be parsed correctly" do
      @mail.subject.should == "タイトルの長いメールの場合の対処を実装するためのテストケースとしてのメールに含まれている件名であるサブジェクト部分"
    end

    it "body should be parsed correctly" do
      @mail.body.to_s.should == "本文です"
    end

    context "to_s" do
      it "should have subject which is same as original" do
        ascii_8bit(@mail.to_s).should match("GyRCJT8lJCVIJWskTkQ5JCQlYSE8JWskTj5s")
      end

      it "should have body which is same as original" do
        ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape(ascii_8bit(utf8_to_jis("本文です")))))
      end
    end

    context "modify and to_s" do
      it "should encode subject correctly" do
        @mail.subject = "大江戸"
        ascii_8bit(@mail.to_s).should match("GyRCQmc5PjhNGyhC")
      end

      it "should encode body correctly" do
        @mail.body = "会議が開催"
        ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape(ascii_8bit(utf8_to_jis("会議が開催")))))
      end
    end
  end

  describe "multipart" do
    describe "PC mail" do
      before(:each) do
        @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/pc-mail-multi.eml")).read)
      end

      it "subject should be parsed correctly" do
        @mail.subject.should == "タイトルの長いメールの場合の対処を実装するためのテストケースとしてのメールに含まれている件名であるサブジェクト部分"
      end

      it "body should be parsed correctly" do
        @mail.body.parts.size.should == 2
        @mail.body.parts.first.body.to_s.should == "本文です"
      end

      it "should encode correctly" do
        ascii_8bit(@mail.to_s).should match(/GyRCJT8lJCVIJWskTkQ5JCQlYSE8JWskTj5s/)
      end
    end

    describe "Docomo" do
      before(:each) do
        @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml")).read)
      end

      it "subject should be parsed correctly" do
        @mail.subject.should == "テスト&#xe6ec;"
      end

      it "body should be parsed correctly" do
        @mail.body.parts.size.should == 1
        @mail.body.parts.first.parts.size == 2
        @mail.body.parts.first.parts.first.body.should match("テストです&#xe72d;")
        @mail.body.parts.first.parts.last.body.raw_source.should match("テストです&#xe72d;")
      end

      it "should encode correctly" do
        @mail.to_s.should match(Regexp.escape("g2WDWINn+ZE"))
      end
    end

    describe "Au" do
      before(:each) do
        @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/au-decomail.eml")).read)
      end

      it "subject should be parsed correctly" do
        @mail.subject.should == "テスト&#xe4f4;"
      end

      it "body should be parsed correctly" do
        @mail.body.parts.size.should == 1
        @mail.body.parts.first.parts.size == 1
        @mail.body.parts.first.parts.first.body.to_s.should == "テストです&#xe595;"
      end

      it "should encode correctly" do
        ascii_8bit(@mail.to_s).should match(Regexp.escape("GyRCJUYlOSVIGyhCGyRCdk8bKEI="))
      end
    end

    describe "Softbank" do
      context "Shift_JIS" do
        before(:each) do
          @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/softbank-gmail-sjis.eml")).read)
        end

        it "subject should be parsed correctly" do
          @mail.subject.should == "テスト&#xf221;&#xf223;&#xf221;"<commit_msg>Add au decomail spec for quoted-printable encoded mail<commit_after># -*- coding: utf-8 -*-
require File.join(File.expand_path(File.dirname(__FILE__)), 'spec_helper')
require 'mail'
require 'jpmobile/mail'

describe "Jpmobile::Mail#receive" do
  include Jpmobile::Util

  before(:each) do
    @to = "<EMAIL>"
  end

  describe "PC mail" do
    before(:each) do
      @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/pc-mail-single.eml")).read)
    end

    it "subject should be parsed correctly" do
      @mail.subject.should == "タイトルの長いメールの場合の対処を実装するためのテストケースとしてのメールに含まれている件名であるサブジェクト部分"
    end

    it "body should be parsed correctly" do
      @mail.body.to_s.should == "本文です"
    end

    context "to_s" do
      it "should have subject which is same as original" do
        ascii_8bit(@mail.to_s).should match("GyRCJT8lJCVIJWskTkQ5JCQlYSE8JWskTj5s")
      end

      it "should have body which is same as original" do
        ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape(ascii_8bit(utf8_to_jis("本文です")))))
      end
    end

    context "modify and to_s" do
      it "should encode subject correctly" do
        @mail.subject = "大江戸"
        ascii_8bit(@mail.to_s).should match("GyRCQmc5PjhNGyhC")
      end

      it "should encode body correctly" do
        @mail.body = "会議が開催"
        ascii_8bit(@mail.to_s).should match(Regexp.compile(Regexp.escape(ascii_8bit(utf8_to_jis("会議が開催")))))
      end
    end
  end

  describe "multipart" do
    describe "PC mail" do
      before(:each) do
        @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "email-fixtures/pc-mail-multi.eml")).read)
      end

      it "subject should be parsed correctly" do
        @mail.subject.should == "タイトルの長いメールの場合の対処を実装するためのテストケースとしてのメールに含まれている件名であるサブジェクト部分"
      end

      it "body should be parsed correctly" do
        @mail.body.parts.size.should == 2
        @mail.body.parts.first.body.to_s.should == "本文です"
      end

      it "should encode correctly" do
        ascii_8bit(@mail.to_s).should match(/GyRCJT8lJCVIJWskTkQ5JCQlYSE8JWskTj5s/)
      end
    end

    describe "Docomo" do
      before(:each) do
        @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/docomo-gmail-sjis.eml")).read)
      end

      it "subject should be parsed correctly" do
        @mail.subject.should == "テスト&#xe6ec;"
      end

      it "body should be parsed correctly" do
        @mail.body.parts.size.should == 1
        @mail.body.parts.first.parts.size == 2
        @mail.body.parts.first.parts.first.body.should match("テストです&#xe72d;")
        @mail.body.parts.first.parts.last.body.raw_source.should match("テストです&#xe72d;")
      end

      it "should encode correctly" do
        @mail.to_s.should match(Regexp.escape("g2WDWINn+ZE"))
      end
    end

    describe "Au" do
      before(:each) do
        @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/au-decomail.eml")).read)
      end

      it "subject should be parsed correctly" do
        @mail.subject.should == "テスト&#xe4f4;"
      end

      it "body should be parsed correctly" do
        @mail.body.parts.size.should == 1
        @mail.body.parts.first.parts.size == 1
        @mail.body.parts.first.parts.first.body.to_s.should match("テストです&#xe595;")
        @mail.body.parts.first.parts.last.body.raw_source.should match("テストです&#xe595;")
      end

      it "should encode correctly" do
        ascii_8bit(@mail.to_s).should match(Regexp.escape("GyRCJUYlOSVIGyhCGyRCdk8bKEI="))
      end
    end

    describe "Softbank" do
      context "Shift_JIS" do
        before(:each) do
          @mail = Mail.new(open(File.join(File.expand_path(File.dirname(__FILE__)), "../../test/rails/overrides/spec/fixtures/mobile_mailer/softbank-gmail-sjis.eml")).read)
        end

        it "subject should be parsed correctly" do
          @mail.subject.should == "テスト&#xf221;&#xf223;&#xf221;"
{'fraction_non_alphanumeric': 0.13071651090342679, 'fraction_numerical': 0.011838006230529595, 'mean_word_length': 2.896116504854369, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, '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': '7533251', 'n_tokens_mistral': 3097, 'n_tokens_neox': 2912, 'n_words': 528}