class DocomoWebMailer
Constants
- MAX_SIZE
メールボックスの最大値?
Public Class Methods
new()
click to toggle source
コンストラクタ
# File lib/docomo_web_mailer.rb, line 29 def initialize() @agent = Mechanize.new @id = 0 @agent.user_agent_alias = 'Mac Safari' end
Public Instance Methods
append_client_flag(uid,flag="flagged")
click to toggle source
uid で指定したメールにclient_flagをたてる。 uid は to_uid
によって変換される
# File lib/docomo_web_mailer.rb, line 104 def append_client_flag(uid,flag="flagged") rcp( "mail_label", [ [ T( A(:append), T( A(:client_flag), A(flag) ), null, [ to_uid(uid) ] ) ], 10000 ] ) end
attachment(mimepart)
click to toggle source
そのパートの添付ファイルを得る。String型のバイナリデータ。 mimepart は Mimepart型
# File lib/docomo_web_mailer.rb, line 79 def attachment(mimepart) url = "/pc/attachment.php?url=#{u(mimepart.attache_info)}" url += "&df=#{u(mimepart.filename.to_s)}" if mimepart.filename @agent.get_file(url) end
convert_mail(header)
click to toggle source
# File lib/docomo_web_mailer/convert_mail.rb, line 2 def convert_mail(header) text = headers.to_s text += "\n\n" if parts.parts.size == 1 data = mail_get_attache( parts.parts[0] ) text +="#{data}" else h = nil raise "unknown type header #{text}" unless headers.find{|k,v| k == "content-type" and v =~ /boundary=(.*)$/} boundary = $1.dup.strip.gsub(/^"(.*)"$/,'\1').gsub(/^'(.*)'$/,'\1') for part in parts.parts body = mail_get_attache( part ) header = [] header << "--#{boundary}" content_type = part.content_type if part.inline_head and part.inline_head.find{|n,v| n == 'content-type'} content_type = part.inline_head.find{|n,v| n == 'content-type'}[1] end puts "content_type=#{content_type}" header << "Content-Type: #{content_type}" is_text = content_type =~ /^text\// if is_text header << "Content-Transfer-Encoding: 8bit" else header << "Content-Transfer-Encoding: base64" end header << "Content-ID: #{part.contentid}" if part.contentid if part.disposition if part.filename header << "Content-Disposition: #{part.disposition}; filename=#{part.filename}" else header << "Content-Disposition: #{part.disposition}" end end header << "" if is_text header << body else header << Base64.encode64(body) end header << "" text += header.join("\n") end text +="--#{boundary}--\n" end text end
login(id,password)
click to toggle source
ログインする。失敗するとexception
# File lib/docomo_web_mailer.rb, line 35 def login(id,password) page = @agent.get("http://dwmail.jp/") form = page.form_with(:name => "f1") raise "login error: cant find login form" unless form form.field_with(:name => "uname").value = id form.field_with(:name => "pass").value = password res = @agent.submit(form) raise "login error (id/pass illegal) " if res.form_with(:name => "f1") end
mail_get_headers(maillistitem)
click to toggle source
uid で指定したメールのヘッダ(AllMailHeaders
)を得る。 uid は to_uid
によって変換される
# File lib/docomo_web_mailer.rb, line 94 def mail_get_headers(maillistitem) AllMailHeaders.new *rcp( "mail_get_headers", [ to_uid(maillistitem), A(:infinity) ] ) end
mail_get_parts(uid)
click to toggle source
uid で指定したメールの全パート情報を得る。Mailpartsを返す。 uid は to_uid
によって変換される
# File lib/docomo_web_mailer.rb, line 74 def mail_get_parts(uid) Mailparts.new *rcp("mail_get_parts", [ to_uid(uid), [ T( A(:bodypref), [ "*/*" ] ), T( A(:bodyparse), A(:off) ) ], MAX_SIZE ]) end
mail_label_list()
click to toggle source
ラベル(フォルダ)の一覧 MailLabelList
を得る。
# File lib/docomo_web_mailer.rb, line 85 def mail_label_list MailLabelList.new( *rcp( "mail_label", [ [ T( A(:list), [ A(:server_folder) ], A(:ascending) ), T( A(:list), [ A(:user_folder) ], A(:ascending) ), T( A(:list), [ A(:user_flag) ], A(:ascending) ) ], 10000 ] ) ) end
mail_list_get(maillist, start,limit )
click to toggle source
Maillistの続きのメールを得る。uid順。startからlimit個。新しいMaillistを返す。
# File lib/docomo_web_mailer.rb, line 69 def mail_list_get(maillist, start,limit ) Maillist.new( *rcp( "mail_list_get", [ maillist.sign, T( T( A(:plain), A(:uid) ), A(:descending), start, limit ), MAX_SIZE ] ) ) end
mail_list_start(maillabel,limit)
click to toggle source
MailLabel
のメールを得る。uid順。limit個。Maillistを返す。 maillabel の値がSymbolならサーバフォルダ、文字列ならユーザフォルダ。
# File lib/docomo_web_mailer.rb, line 46 def mail_list_start(maillabel,limit) place = [ A(:server_folder), A(maillabel) ] if maillabel.is_a? MailLabel place = [ A(maillabel.place), A(maillabel.index) ] elsif maillabel.is_a? String place[0]['$A']="user_folder" end Maillist.new( *rcp("mail_list_start",[ 1, T( nil, T( # 得たいフォルダの場所 [ T(*place) ], # 不明 [ ], # 不明 [ T( A(:client_flag), A(:recent) ) ], # 得たい付加情報? [ A(:server_flag), A(:client_flag), A(:server_folder), A(:user_folder), A(:user_flag) ] ) ), # 並び順と数? T( T( A(:plain), A(:uid) ), A(:descending), nil, limit ), # 不明 nil, MAX_SIZE, MAX_SIZE ]) ) end
make_mail_to_smtp(uid)
click to toggle source
uid で指定したメールのSMTP送信用テキストを作る uid は to_uid
によって変換される
# File lib/docomo_web_mailer.rb, line 99 def make_mail_to_smtp(uid) Builder.new(self).build( uid ) end
rcp( method,params )
click to toggle source
rcp 1.0 にパラメータを投げる
# File lib/docomo_web_mailer.rb, line 173 def rcp( method,params ) @id += 1 result = Parser.rcp_to_ruby(JSON.parse(@agent.post("http://pc.dwmail.jp/api/base/rpc/1.0", { :id => @id.to_s, :method => method.to_s, :params => params, :version=>"1.1" }.to_json ).body)) unless result["error"] return result["result"] else require 'pp' pp result['error'] pp params raise "error ! #{result['error']}" end end
remove_client_flag(uid,flag="flagged")
click to toggle source
uid で指定したメールからclient_flagを外す。 uid は to_uid
によって変換される
# File lib/docomo_web_mailer.rb, line 109 def remove_client_flag(uid,flag="flagged") rcp( "mail_label", [ [ T( A(:remove), T( A(:client_flag), A(flag) ), null, [ to_uid(uid) ] ) ], 10000 ] ) end
to_uid( maillistitem )
click to toggle source
maillistitem を uid にする。文字列なら数値化、数値以外ならuidプロパティーの値を返す
# File lib/docomo_web_mailer.rb, line 113 def to_uid( maillistitem ) maillistitem = maillistitem.to_i if maillistitem.is_a? String maillistitem = maillistitem.uid unless maillistitem.is_a? Numeric maillistitem end