# File lib/jpmobile/mail.rb, line 57 def encoded_with_jpmobile if @mobile header['subject'].mobile = @mobile if header['subject'] header['from'].mobile = @mobile if header['from'] header['to'].mobile = @mobile if header['to'] self.charset = @mobile.mail_charset(@charset) ready_to_send! self.body.charset = @charset self.body.mobile = @mobile self.header['Content-Transfer-Encoding'].value = @mobile.content_transfer_encoding(self.header) if @mobile.decorated? unless self.content_type.match(%rimage\//) self.header['Content-ID'] = nil end unless self.header['Content-Type'].sub_type == 'mixed' self.header['Date'] = nil self.header['Mime-Version'] = nil end end buffer = header.encoded buffer << "\r\n" buffer = @mobile.utf8_to_mail_encode(buffer) buffer << body.encoded(content_transfer_encoding) ascii_compatible!(buffer) else encoded_without_jpmobile end end
# File lib/jpmobile/mail.rb, line 218 def find_part_by_content_type(content_type) finded_parts = [] self.parts.each do |part| if part.multipart? finded_parts << part.find_part_by_content_type(content_type) elsif part.content_type.match(%r^#{content_type}/) finded_parts << part end end finded_parts.flatten end
# File lib/jpmobile/mail.rb, line 103 def init_with_string(string) # convert to ASCII-8BIT for ascii incompatible encodings s = Jpmobile::Util.ascii_8bit(string) self.raw_source = s set_envelope_header parse_message @separate_parts = multipart? end
# File lib/jpmobile/mail.rb, line 46 def mobile=(m) if @mobile = m @charset = m.mail_charset(@charset) if @body @body.charset = @charset @body.mobile = m end end end
# File lib/jpmobile/mail.rb, line 91 def parse_message_with_jpmobile header_part, body_part = raw_source.split(%r#{CRLF}#{WSP}*#{CRLF}/, 2) self.header = header_part @body_part_jpmobile = body_part convert_encoding_jpmobile body_part = @body_part_jpmobile self.body = body_part end
# File lib/jpmobile/mail.rb, line 112 def process_body_raw_with_jpmobile process_body_raw_without_jpmobile if @mobile @body.charset = @charset @body.mobile = @mobile if has_content_transfer_encoding? and ["base64", "quoted-printable"].include?(content_transfer_encoding) and ["text"].include?(@mobile_main_type) @body.decode_transfer_encoding end if @body.multipart? @body.parts.each do |p| p.charset = @charset p.mobile = @mobile end end end end
– normal multipart/mixed
|- multipart/alternative | |- text/plain | |- text/html | |- image/xxxx (インライン画像) |- image/xxxx (添付画像)
# File lib/jpmobile/mail.rb, line 168 def rearrange! if @mobile and @mobile.decoratable? @mobile.decorated = true text_body_part = find_part_by_content_type("text/plain").first html_body_part = find_part_by_content_type("text/html").first html_body_part.transport_encoding = 'quoted-printable' if html_body_part inline_images = [] attached_files = [] attachments.each do |p| if p.content_type.match(%r^image\//) and p.content_disposition.match(%r^inline/) if p.header['Content-Type'].parameters['filename'] p.header['Content-Type'].parameters['name'] = p.header['Content-Type'].parameters['filename'].to_s end inline_images << p elsif p.content_disposition attached_files << p end end alternative_part = Mail::Part.new{content_type 'multipart/alternative'} alternative_part.add_part(text_body_part) if text_body_part alternative_part.add_part(html_body_part) if html_body_part if @mobile.require_related_part? related_part = Mail::Part.new{content_type 'multipart/related'} related_part.add_part(alternative_part) inline_images.each do |inline_image| related_part.add_part(inline_image) end inline_images.clear else related_part = alternative_part end unless self.header['Content-Type'].sub_type == 'mixed' self.header['Content-Type'] = self.content_type.gsub(%r#{self.header['Content-Type'].sub_type}/, 'mixed') end self.parts.clear self.body = nil self.add_part(related_part) inline_images.each do |inline_image| self.add_part(inline_image) end attached_files.each do |attached_file| self.add_part(attached_file) end end end