プログラマな会話3

■TMailで携帯から送信した添付ファイルが上手く認識できないもんだいに
ついてコードリーディングする。の巻き


メールと画像 # Receives a raw email, parses it into an email object, decodes
it,
# instantiates a new mailer, and passes the email object to the mailer
# object's #receive method. If you want your mailer to be able to
# process incoming messages, you'll need to implement a #receive
# method that accepts the email object as a parameter:
#
# class MyMailer < ActionMailer::Base
# def receive(mail)
# ...
# end
# end
def receive(raw_email)
logger.info "Received mail:\n #{raw_email}" unless logger.nil?
mail = TMail::Mail.parse(raw_email)
mail.base64_decode
new.receive(mail)
end) ActionMailer::Base20:38 (yuta) ここでTMail::Mail のインスタンスつくってbase64 decode して、自分のインスタンスにそれ渡してる20:38 (yuta) この
base64_decode がmultipart 見てない気配このself.bodyが def body(to_charset =
'utf-8', &block)
attachment_presenter = block || Proc.new { |file_name| "Attachment:
#{file_name}\n" }

if multipart?
parts.collect { |part|
header = part["content-type"]

if part.multipart?
part.body(to_charset, &attachment_presenter)
elsif header.nil?
""
elsif !attachment?(part)
part.unquoted_body(to_charset)
else
attachment_presenter.call(header["name"] || "(unnamed)")
end
}.join
else
unquoted_body(to_charset)
end
end
end
20:47 (fuk) Base64.decode(email.attachments[0]) かな。。。
20:47 (hammer) (email.attachments[0])
20:49 (yut) あーそうか、email.attachments[0] はTMail::Mail のインスタンスじゃなかった
20:49 (yut) ase64.decode(email.attachments[0]string)
20:49 (hammer) (email.attachments[0]string)
20:49 (yut) ase64.decode(email.attachments[0].string)
20:49 (hammer) (email.attachments[0].string)
20:50 (yut) email.attachments[0].read

てか、test かけばいい希ガス

単体テストかいたほうがいいとおもいます



21:18 (yut) rikumark on CC 挫折
21:19 (yut) きょうはなにもすすまなかた…
21:19 (fuk) すみません・・(´`)
21:19 (hammer) (´`)
21:19 (yut) なんで?
21:19 (yut) あ
21:19 (yut) いえいえ
21:20 (yut) なんかMySQL の設定とかに異様に時間がかかった
21:21 (nag) !!!
21:21 (hammer) もちつけ
21:21 (nag) すみません。CCni
21:21 (hammer) 謝るなよ…お前らしくないゼ
21:21 (nag) CC横槍で入れてしまって
21:22 (yut) あー気になってたのでいいです
21:22 (nag) 恐れ入りますm(_ _)m
21:22 (hammer) (_ _)