#!/usr/bin/env ruby
# Copyright (C) 2003-2005 Kouichirou Eto, All rights reserved.

$LOAD_PATH << "../../lib" unless $LOAD_PATH.include?("../../lib")
require "qwik/test-module-quickml"
require "qwik/quickml"

class TC_MLUtilJapanese < Test::Unit::TestCase
  include TestQuickMLModule

  def test_class_methods
    # test_encode_field
    assert_equal("t", QuickML::Mail.encode_field("t"))
    assert_equal("=?iso-2022-jp?B?GyRCJCIbKEI=?= ",
		 QuickML::Mail.encode_field("あ"))
    assert_equal("=?iso-2022-jp?B?GyRCJCIkJBsoQg==?= ",
		 QuickML::Mail.encode_field("あい"))
    assert_equal("=?iso-2022-jp?B?GyRCJCIkJCQmJCgkKiQrJC0kLyQxJDMbKEI=?= 
 =?iso-2022-jp?B?GyRCJDUkNyQ5JDskPRsoQg==?= ",
		 QuickML::Mail.encode_field("あいうえおかきくけこさしすせそ"))
    assert_equal("=?iso-2022-jp?B?GyRCJCIbKEI=?= ",
		 QuickML::Mail.encode_field("あ"))
    assert_equal("\201@", "　")
    assert_equal("\352\242", "瑤")
    assert_equal("[test:1] Re: =?iso-2022-jp?B?GyRCJUYlOSVIGyhCICA=?= ",
		 QuickML::Mail.encode_field("[test:1] Re: テスト  "))
    assert_equal("[test:1] Re: =?iso-2022-jp?B?GyRCJCIbKEI=?= ",
		 QuickML::Mail.encode_field("[test:1] Re: あ"))
  end

    def test_mail_quoted_printable
      str = <<'EOT'
From user@gmail.com Sat Apr 02 18:43:00 2005
DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws;
        s=beta; d=gmail.com;
        h=received:message-id:date:from:reply-to:to:subject:mime-version:content-type:content-transfer-encoding;
        b=Dz/ibCBk+eqg1lLbj2QCzrrwCFes4+P+E2jYcXHcjT4j5gsNyfOfQTItkephpw8wemR1xjuivHNJVJhqm7FJKrJpmSue3m1smW0qA3BszX8FPq2ENPOJk9BVxCsEorEtFtNedjbzmvptL73jsZp4rkW2kby4hym+lpJ1NOywar4=
Message-ID: <696d838105040201435426dd76@mail.gmail.com>
Date: Sat, 2 Apr 2005 18:43:00 +0900
From: user <user@gmail.com>
To: test@example.com
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-2022-JP
Content-Transfer-Encoding: quoted-printable
Subject: [qwik-users:217] Gmail=?iso-2022-jp?B?GyRCJCwbKEJKSVMbJEIlKCVzJTMhPCVHJSMbKEI=?= 
 =?iso-2022-jp?B?GyRCJXMlMCRLO0VNTUpROTkbKEI=?= 
Reply-To: test@example.com
X-Mail-Count: 217
Precedence: bulk
X-ML-Address: test@example.com
X-ML-Name: test
X-ML-Info: http://qwik.jp/
X-QuickML: true

=1B$B$3$s$K$A$O!#=1B(B

--=20
user
EOT
      mail = ml_mail("user@gmail.com", "test@example.com", str)
      assert_equal("text/plain", mail.content_type)
      assert_equal("=1B$B$3$s$K$A$O!#=1B(B\n\n--=20\nuser\n", mail.body)
      assert_equal("こんにちは。\n\n-- \nuser\n".sjistojis, mail.decoded_body)
      assert_equal("quoted-printable", mail["Content-Transfer-Encoding"])
    end

end
