Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iPhoneからの返信、転送メール受信時に例外発生 #45

Closed
k14a opened this issue Jul 25, 2012 · 16 comments
Closed

iPhoneからの返信、転送メール受信時に例外発生 #45

k14a opened this issue Jul 25, 2012 · 16 comments

Comments

@k14a
Copy link

k14a commented Jul 25, 2012

Jpmobile::Mailer::Baseを使用してメールの受信を行おうとしているのですが、iPhone(au)からのメールを受信した時に例外が発生します。
どうやら、本文中に「日」のような2バイト目に0x7Cが含まれている場合に例外が発生する模様です。
ちなみに、ActionMailer::Baseでは、受信できるのですが、ガラケーの利用も考えているので、Jpmobileで受信を行いたいと考えています。

以上、よろしくお願いします。

例外エラー

`eval': "l" followed by "\e" on ISO-2022-JP (Encoding::InvalidByteSequenceError)

スタックトレース

/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands/runner.rb:53:in `eval': "l" followed by "\e" on ISO-2022-JP (Encoding::InvalidByteSequenceError)  from
/usr/lib/ruby/gems/1.9.1/gems/jpmobile-3.0.4/lib/jpmobile/util.rb:146:in `jis_to_utf8'  from
/usr/lib/ruby/gems/1.9.1/gems/jpmobile-3.0.4/lib/jpmobile/mobile/au.rb:123:in `to_mail_internal' from
/usr/lib/ruby/gems/1.9.1/gems/jpmobile-3.0.4/lib/jpmobile/mobile/abstract_mobile.rb:160:in `decode_transfer_encoding'  from
/usr/lib/ruby/gems/1.9.1/gems/jpmobile-3.0.4/lib/jpmobile/mail.rb:276:in `convert_encoding_jpmobile'  from
/usr/lib/ruby/gems/1.9.1/gems/jpmobile-3.0.4/lib/jpmobile/mail.rb:98:in `parse_message_with_jpmobile'  from
/usr/lib/ruby/gems/1.9.1/gems/jpmobile-3.0.4/lib/jpmobile/mail.rb:109:in `init_with_string'  from
/usr/lib/ruby/gems/1.9.1/gems/mail-2.4.4/lib/mail/message.rb:125:in `initialize'  from
/usr/lib/ruby/gems/1.9.1/gems/mail-2.4.4/lib/mail/mail.rb:50:in `new'  from
/usr/lib/ruby/gems/1.9.1/gems/mail-2.4.4/lib/mail/mail.rb:50:in `new'  from
/usr/lib/ruby/gems/1.9.1/gems/actionmailer-3.2.1/lib/action_mailer/base.rb:401:in `block in receive'  from
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in `block in instrument'  from
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb:20:in `instrument'  from
/usr/lib/ruby/gems/1.9.1/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in `instrument'  from
/usr/lib/ruby/gems/1.9.1/gems/actionmailer-3.2.1/lib/action_mailer/base.rb:400:in `receive'  from (eval):1:in `<top (required)>'  from
/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands/runner.rb:53:in `eval'  from
/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands/runner.rb:53:in `<top (required)>'  from
/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:64:in `require'  from
/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands.rb:64:in `<top (required)>'  from script/rails:6:in `require'  from
script/rails:6:in `<main>'

使用バージョン

ruby : ruby 1.9.3p194 (2012-04-20) [i686-linux]
rails : 3.2.1
jpmobile : 3.0.4
@rust
Copy link
Member

rust commented Aug 8, 2012

こちらで検証したのですが、Subject/BodyともにISO-2022-JPで、本文が「日本」のみではエラーにはなりませんでした。

エラーを見ると、Encodingが誤って解釈されたか、来たメールのEncodingが実際とは異なるなどの問題だと思います。エラーになるメールの

  • Content-Type
  • Subject
  • 本文

を教えていただけますか。

@k14a
Copy link
Author

k14a commented Aug 9, 2012

エラーとなったメールは以下のとおりです。
ドメイン名等は変更しています。

  • Content-Type

    Content-Type: multipart/alternative;
    boundary=Apple-Mail-453BF7C8-E087-4CEB-A163-18A4B0CBB56C

  • Subject

    Subject: =?iso-2022-jp?B?RndkOiAbJEIhWhsoQk51cnNlcnlNYWlsGyRCIVtGfEZ8GyhC?=

  • 本文

    --Apple-Mail-453BF7C8-E087-4CEB-A163-18A4B0CBB56C
    Content-Transfer-Encoding: quoted-printable
    Content-Type: text/plain;
    charset=iso-2022-jp

    iPhone=1B$B$+$iAw?.=1B(B

    Begin forwarded message:

    =1B$B:9=3DP?M=1B(B: xxxx@example.com
    =1B$BF|;~=1B(B: 2012=1B$BG/=1B(B7=1B$B7n=1B(B30=1B$BF|=1B(B 10:09:12 JST
    =1B$B08@h=1B(B: xxxx@ezweb.ne.jp
    =1B$B7oL>=1B(B: =1B$B!Z=1B(BNurseryMail=1B$B![F|F|=1B(B
    Reply-To: yyyy@example.com
    =20
    =1B$BJ#?t;XDj1;y#1$/$s=1B(B =1B$B$NJ]8n<TMM=1B(B =20 =1B$BMh$k!{!{7n!{!{F|$KJ]0i1$K$F!"%9%$%+3d$jBg2q$r3+:ECW$7$^$9!#=1B(B
    =1B$B8f;22CD:$1$k>l9g$O=1B(B xxxx@example.com =1B$B$X=1B(=B
    =1B$BIT;22C$N>l9g$O=1B(B xxxx@example.com =1B$B$X=1B(B
    =1B$B%9%$%+$r;}$C$F$-$F$/$l$kJ}$O=1B(B xxxx@example.com =1B$B$X=1B(B
    =1B$B%9%$%+$8$c$J$/!"%a%m%s$r;}$C$F$-$F$/$l$kJ}$O=1B(B xxxx@example.com =1B$B$X=1B(B
    =1B$BLlGL$b;22C$7$?$$$H$$$&J}$O=1B(B xxxx@example.com =1B=$B$X=1B(B
    =1B$B%9%$%+$K$J$C$F$/$l$k$*Ic$5$s$O=1B(B xxxx@example.com=1B$B$X=1B(B
    =1B$B@N=3D$3XN99T$GGc$C$?LZEa$r;}$C$F$-$F$/$l$kJ}$O=1B(B xxxx@example.com =1B$B$X=1B(B
    =1B$B$J$s$G$b$$$$$+$i;22C$7$?$$$H$$$&J}$O=1B(B xxxx@example.com =1B$B$X=1B(B
    =1B$B0{$5$K~!9$N?M$O=1B(B xxxx@example.com =1B$B$X=1B(B =20 =1B$B6u%a!<%k$rAw?.$/$@$5$$!#=1B(B =20 =1B$B!!!!""""J]0i1!!!y!yAH!!C4G$!!#x#x#x#x#x=1B(B

    --Apple-Mail-453BF7C8-E087-4CEB-A163-18A4B0CBB56C
    Content-Transfer-Encoding: base64
    Content-Type: text/html;
    charset=utf-8

    以下、HTMLの本文が続きます

以上、宜しくお願いしいたします。

@rust
Copy link
Member

rust commented Aug 9, 2012

d5d7802 の lib/jpmobile/util.rb への変更でこの問題は解決すると思いますが、貼りつけてもらった本文ではそもそもquoted-printable の変換が間違っている部分があるため、別のエラーになるかもしれません。

リリースは絵文字関係のオプションを追加してからになるので、必要であればパッチとしてこの変更の部分だけを取り込んでください。

@k14a
Copy link
Author

k14a commented Aug 16, 2012

上記パッチを当てて試してみたのですが、同様にEncoding::InvalidByteSequenceErrorが発生しました
もし必要でしたら、使用したメールデータを送らせて頂きます。

  • スタックトレース

    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/railties-3.2.1/lib/rails/commands/runner.rb:53:in eval': "\xE3" on ISO-2022-JP (Encoding::InvalidByteSequenceError) from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/util.rb:146:injis_to_utf8' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/mobile/au.rb:116:in to_mail_internal' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/mobile/abstract_mobile.rb:160:indecode_transfer_encoding' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/mail.rb:371:in decode_transfer_encoding' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/mail.rb:123:inprocess_body_raw_with_jpmobile' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/message.rb:1155:in body' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/mail.rb:358:inblock in mobile=' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/mail.rb:355:in each' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/mail.rb:355:inmobile=' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/mail.rb:118:in process_body_raw_with_jpmobile' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/message.rb:1155:inbody' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/message.rb:1934:in identify_and_set_transfer_encoding' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/mail-2.4.4/lib/mail/message.rb:1689:inready_to_send!' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/mail.rb:65:in encoded_with_jpmobile' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/actionmailer-3.2.1/lib/action_mailer/base.rb:435:inset_payload_for_mail' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/jpmobile-3.0.4/lib/jpmobile/mailer.rb:42:in set_payload_for_mail' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/actionmailer-3.2.1/lib/action_mailer/base.rb:404:inblock in receive' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in block in instrument' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/activesupport-3.2.1/lib/active_support/notifications/instrumenter.rb:20:ininstrument' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/activesupport-3.2.1/lib/active_support/notifications.rb:123:in instrument' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/actionmailer-3.2.1/lib/action_mailer/base.rb:402:inreceive' from (eval):1:in <top (required)>' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/railties-3.2.1/lib/rails/commands/runner.rb:53:ineval' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/railties-3.2.1/lib/rails/commands/runner.rb:53:in <top (required)>' from /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/railties-3.2.1/lib/rails/commands.rb:64:inrequire' from
    /usr/lib/ruby/gems/ruby-1.9.3-p194/gems/railties-3.2.1/lib/rails/commands.rb:64:in <top (required)>' from script/rails:6:inrequire' from script/rails:6:in `

    '

宜しくお願いいたします。

@rust
Copy link
Member

rust commented Aug 18, 2012

ここに貼り付けていただいたメールのデータですが、=1B(=Bのようにそもそも不正なデータになっていたので、decode時にエラーになってしまうようです。よろしければメールデータをtarとかzipで圧縮して送っていただけますか?

とは言え、そういう不正なメールが来ないとも限らないので、どこかでrescueしてASCII-8BITで返す必要があるとは思ってますので、そちらはそちらで対処予定です。

@rust
Copy link
Member

rust commented Aug 20, 2012

現象を確認しました。ただ結構根深そうなので、すぐには修正できそうにありません。もう少々お待ちください。

rust added a commit that referenced this issue Aug 21, 2012
@rust
Copy link
Member

rust commented Aug 21, 2012

742f2a3 で受信時のエラーは大丈夫そうですので、一度試してみていただけますか。

@k14a
Copy link
Author

k14a commented Aug 22, 2012

受信エラーが無くなりました。
もう少しいろんなパターンで試してみたいと思います。
ありがとうございました。

@k14a k14a closed this as completed Aug 22, 2012
@k14a k14a reopened this Aug 22, 2012
@k14a
Copy link
Author

k14a commented Aug 22, 2012

au版iPhoneのMessageアプリでエラーになってしまいました。

/usr/lib/ruby/gems/1.9.1/gems/railties-3.2.1/lib/rails/commands/runner.rb:53:in `eval': "\xE7" on ISO-2022-JP (Encoding::InvalidByteSequenceError)  from
/usr/lib/ruby/gems/1.9.1/gems/jpmobile-3.0.4/lib/jpmobile/util.rb:148:in `jis_to_utf8'

送信したメールは以下のとおりです

Subject:=?UTF-8?B?aVBob25lIGF1IOODoeODg+OCu+ODvOOCuA==?=
Message-ID: <212212358846052174@-212212358846052175>
Date: Tue, 22 Aug 2012 01:27:26 +0000
MIME-Version:1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: base64

JVvlnJLlhZDlkI1dJeOBriVb5L+d6K236ICF5ZCNXSUg5qeYCgrmlr3oqK3jgavpgIHkv6HjgIIK
6YG45oqeMeOBryVb44Ki44OJ44Os44K5MV0l44G4CumBuOaKnjLjga8lW+OCouODieODrOOCuTJd
JeOBuArov5Tkv6HjgZfjgabkuIvjgZXjgYTjgIIKCmlQaG9uZSBhdSDjg6Hjg4Pjgrvjg7zjgrg=

宜しくお願いいたします。

@rust
Copy link
Member

rust commented Aug 22, 2012

runnerの実行時のエラーのようですが、メールの受信か送信かのどちらでしょうか。おそらく受信だとは思うのですが、受信時のエラーでしょうか。

上記のメールをそのまま受信->送信ではエラーにはなりませんでした。

@k14a
Copy link
Author

k14a commented Aug 22, 2012

メール受信時にエラーとなります。
上で貼った部分だけを受信させるとエラーになりませんが、メールヘッダを含めて受信させるとエラーになりました。
メール全文を別途送らせて頂きます。

@rust
Copy link
Member

rust commented Aug 23, 2012

68fbf6e で送ってもらったメールがうまく処理できるように修正しました。こちらでどうでしょうか。

@k14a
Copy link
Author

k14a commented Aug 23, 2012

受信できるようになりました。
ありがとうございました。

@k14a k14a closed this as completed Aug 28, 2012
@k14a
Copy link
Author

k14a commented Aug 30, 2012

また受信時にエラーとなるパターンがでました。
メールにてエラーとなったものを送らせてもらいます。
よろしくお願いします。

@k14a k14a reopened this Aug 30, 2012
@rust
Copy link
Member

rust commented Sep 3, 2012

どんなエラーになりましたか?

@rust
Copy link
Member

rust commented Sep 3, 2012

あと同じissueではないので、別のチケットとしてください。そのときにbacktraceもお願いします。

@rust rust closed this as completed Sep 3, 2012
rust added a commit that referenced this issue Oct 9, 2012
rust added a commit that referenced this issue Oct 9, 2012
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants