This is a cryptographically signed message in MIME format.

--------------ms000402090802010403030602
Content-Type: text/plain; charset=utf-8; format=flowed
Content-Language: en-US
Content-Transfer-Encoding: quoted-printable

DOCOMO 礇紕磚禺礑紂祀
リアルタイムに通知するためのプログラムを
作ろうとしているのですがうまく行きません。

インターネット上のブログ等の情報によると、
DOCOMO のメールで IMAP の IDLE を使って
プッシュ送信を実現しているという様な記事
があったので、下記のようなプログラムを書いた
のですが、Net::IMAP#idle を実行した時点で
接続が切れてしまうようなのですが、
どのようにすれば良いのでしょうか?

同じプログラムで gmail では正しく動いている
ことは確認しました。


江本


== 実行結果 ==

:~/src/ruby/imap ./test_imap2.rb
connected to imap server
["IMAP4REV1", "NAMESPACE", "IDLE", "LITERAL+", "UIDPLUS", "QUOTA", "AUTH=LOGIN", 
"ID"]
#<Net::IMAP::Error: connection closed>
connection closed: reconecting...
connected to imap server
["IMAP4REV1", "NAMESPACE", "IDLE", "LITERAL+", "UIDPLUS", "QUOTA", "AUTH=LOGIN", 
"ID"]
#<Net::IMAP::Error: connection closed>
connection closed: reconecting...
connected to imap server
["IMAP4REV1", "NAMESPACE", "IDLE", "LITERAL+", "UIDPLUS", "QUOTA", "AUTH=LOGIN", 
"ID"]
#<Net::IMAP::Error: connection closed>

== プログラム ==

#!/usr/bin/env ruby
# coding: utf-8
require 'net/imap'
require 'kconv'
require 'time'


imap_user ="ユーザ名"
imap_passwd = "パスワード"
imap_server = 'imap.spmode.ne.jp'

#imap_user ="ユーザ名"
#imap_passwd = "パスワード"
#imap_server = 'imap.gmail.com'


attr_name = 'BODY[HEADER.FIELDS (SUBJECT)]'
attr_addr = 'BODY[HEADER.FIELDS (FROM)]'

last_id = -1
while true
   begin
     unless $imap
       $imap = Net::IMAP.new(imap_server, 993, true)
       $imap.login(imap_user, imap_passwd)
       $imap.select('INBOX')
       puts "connected to imap server"
     end
     capabilities = $imap.capability
     p capabilities
     $imap.idle do |resp|
       if resp.name == "EXISTS"
         print "New Mail Arrived\n"
         last_id = resp.data
         $imap.idle_done
       else
         p resp
       end
     end

   rescue Net::IMAP::Error => e
     p e
     if e.inspect.include? "connection closed"
       puts "connection closed: reconecting..."
       $imap = nil
     else
       raise
     end
   end

   next unless $imap

   msgs = $imap.fetch((last_id..-1), [attr_name, attr_addr])
   msgs.each do |msg|
     subject = msg.attr[attr_name].toutf8.strip
     from = msg.attr[attr_addr].toutf8.strip
     print "#{from} #{subject}\n"
   end

end

== 実行環境 ==

% lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 16.04.3 LTS
Release:        16.04
Codename:       xenial
%  ruby --version
ruby 2.3.1p112 (2016-04-26) [x86_64-linux-gnu]


--------------ms000402090802010403030602
Content-Type: application/pkcs7-signature; name="smime.p7s"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="smime.p7s"
Content-Description: S/MIME Cryptographic Signature

MIAGCSqGSIb3DQEHAqCAMIACAQExDzANBglghkgBZQMEAgEFADCABgkqhkiG9w0BBwEAAKCC
CyswggU9MIIEJaADAgECAhBaNO6Dbr/4aIpiCPZMsf9DMA0GCSqGSIb3DQEBCwUAMIGXMQsw
CQYDVQQGEwJHQjEbMBkGA1UECBMSR3JlYXRlciBNYW5jaGVzdGVyMRAwDgYDVQQHEwdTYWxm
b3JkMRowGAYDVQQKExFDT01PRE8gQ0EgTGltaXRlZDE9MDsGA1UEAxM0Q09NT0RPIFJTQSBD
bGllbnQgQXV0aGVudGljYXRpb24gYW5kIFNlY3VyZSBFbWFpbCBDQTAeFw0xNzA4MDMwMDAw
MDBaFw0xODA4MDMyMzU5NTlaMCoxKDAmBgkqhkiG9w0BCQEWGWVtb3RvLm1hc2FoaWtvQG5p
ZnMuYWMuanAwggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAwggEKAoIBAQC1EyMwNbS+rlqX6xYl
nVNMt325FtYSwFHTMzy0lKPHoM6u/9cYeDpPa8V9FGeV2QOr8DNMj3rIiSo15S0mZsp7VKO3
ubN6iij/9aWMyW6sfbdFX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