class DocomoWebMailer::Builder

SMTPサーバに送信するためのメールテキストを作成する。 他のメールソフト・メールライブラリで扱うための中間形式としても。

Public Class Methods

new(mailer) click to toggle source
# File lib/docomo_web_mailer.rb, line 130
def initialize(mailer)
  @mailer = mailer
end

Public Instance Methods

build(uid) click to toggle source

uid からメールテキストを作成する 引数 uid には to_uid が適用される。

# File lib/docomo_web_mailer.rb, line 135
def build(uid)
  build_from @mailer.mail_get_headers(uid), @mailer.mail_get_parts(uid) 
end
build_from(headers,parts) click to toggle source

header と parts からメールテキストを作成する

# File lib/docomo_web_mailer.rb, line 139
def build_from(headers,parts)
  headers.multipart? ? make_mail_to_smtp_multipart( headers, parts ) : make_mail_to_smtp_singlepart( headers, parts.parts[0] )
end
make_mail_to_smtp_multipart(headers,parts) click to toggle source

AllMailHeadersMailparts からメールのSMTP送信用テキストを作る(マルチパート)

# File lib/docomo_web_mailer.rb, line 148
def make_mail_to_smtp_multipart(headers,parts)
  raise "unknown type header #{text}" unless headers.content_type =~ /boundary=(.*)$/
  boundary = $1.dup.strip.gsub(/^"(.*)"$/,'\1').gsub(/^'(.*)'$/,'\1')
  
  headers.to_s +
  "\n\n--#{boundary}\n" +
  parts.parts.map{|part| part_to_mail(part).join("\n")}.join("\n--#{boundary}\n") +
  "\n--#{boundary}--\n"
end
make_mail_to_smtp_singlepart(headers,part) click to toggle source

AllMailHeadersMimepart からメールのSMTP送信用テキストを作る(シングル)

# File lib/docomo_web_mailer.rb, line 144
def make_mail_to_smtp_singlepart(headers,part)
  headers.to_s + "\n\n" + @mailer.attachment( part )
end
part_to_mail(part) click to toggle source

Mimepart をsmtp bodyに

# File lib/docomo_web_mailer.rb, line 158
def part_to_mail(part)
  body = @mailer.attachment( part )
  content_type = part.content_type
  is_text = content_type =~ /^text\//
  mail = []
  mail << "Content-Type: #{content_type}"
  mail << "Content-Transfer-Encoding: #{is_text ? '8bit' : 'base64' }"
  mail << "Content-ID: #{part.contentid}" if part.contentid
  mail << "Content-Disposition: #{part.disposition_with_filename}" if part.disposition
  mail << ""
  mail << ( is_text ? body : Base64.encode64(body) )
  mail
end