# File lib/jpmobile/mail.rb, line 52 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 ready_to_send! self.body.mobile = @mobile self.header['Content-Transfer-Encoding'].value = @mobile.content_transfer_encoding(self.header) if @mobile.decorated? unless self.content_type.match(/image\//) 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 237 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(/^#{content_type}/) finded_parts << part end end finded_parts.flatten end
# File lib/jpmobile/mail.rb, line 97 def init_with_hash_with_jpmobile(hash) if hash[:body_raw] @mobile = hash[:mobile] init_with_string(hash[:body_raw]) else init_with_hash_without_jpmobile(hash) end end
# File lib/jpmobile/mail.rb, line 109 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) end end
# File lib/jpmobile/mail.rb, line 85 def parse_message_with_jpmobile header_part, body_part = raw_source.lstrip.split(/#{CRLF}#{CRLF}|#{CRLF}#{WSP}*#{CRLF}(?!#{WSP})/, 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 118 def process_body_raw_with_jpmobile process_body_raw_without_jpmobile if @mobile @body.mobile = @mobile @body.content_type_with_jpmobile = self.content_type if has_content_transfer_encoding? and ["base64", "quoted-printable"].include?(self.content_transfer_encoding) and ["text"].include?(@mobile_main_type) @body.decode_transfer_encoding end if @body.multipart? @body.parts.each do |p| p.charset = @mobile.mail_charset(p.charset) p.mobile = @mobile end end end end
In jpmobile, value is already transfered correctly encodings.
# File lib/jpmobile/mail.rb, line 141 def raw_source=(value) @raw_source = value.to_crlf end
– normal multipart/mixed
|- multipart/alternative | |- text/plain | |- text/html | |- image/xxxx (インライン画像) |- image/xxxx (添付画像)
# File lib/jpmobile/mail.rb, line 187 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(/^image\//) and p.content_disposition.match(/^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(/#{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
# File lib/jpmobile/mail.rb, line 145 def separate_parts_with_jpmobile @body.mobile = @mobile separate_parts_without_jpmobile end
# File lib/jpmobile/mail.rb, line 296 def ascii_compatible!(str) Jpmobile::Util.ascii_compatible!(str) end
# File lib/jpmobile/mail.rb, line 252 def convert_encoding_jpmobile # decide mobile carrier if self.header[:from] mobile_class = Jpmobile::Email.detect_from_mail_header(self.header[:from].value) @mobile ||= mobile_class.new(nil, nil) if mobile_class end # override charset if self.header[:content_type] content_type_charset = Jpmobile::Util.extract_charset(self.header[:content_type].value) @charset = content_type_charset unless content_type_charset.blank? self.header[:content_type].parameters[:charset] = @charset @mobile_main_type = self.header[:content_type].main_type end end # convert header(s) if self.header[:subject] subject_charset = Jpmobile::Util.extract_charset(self.header[:subject].value) self.header[:subject].charset = subject_charset unless subject_charset.blank? if @mobile subject_value = Encodings.value_decode(self.header[:subject].value) subject_converting_encoding = Jpmobile::Util.detect_encoding(subject_value) v = @mobile.to_mail_internal(subject_value, subject_converting_encoding) self.header[:subject].value = Jpmobile::Util.force_encode(v, @mobile.mail_charset(subject_charset), Jpmobile::Util::UTF8) end end if @body_part_jpmobile and @mobile and !@charset.blank? if ["base64", "quoted-printable"].include?(self.content_transfer_encoding) and self.content_type.match(/text/) @body_part_jpmobile = Jpmobile::Util.decode(@body_part_jpmobile, self.content_transfer_encoding, @charset) self.content_transfer_encoding = @mobile.class::MAIL_CONTENT_TRANSFER_ENCODING end unless Jpmobile::Util.check_charset(@body_part_jpmobile, @charset) @body_part_jpmobile = Jpmobile::Util.correct_encoding(@body_part_jpmobile) @charset = @body_part_jpmobile.encoding.to_s end @body_part_jpmobile = @mobile.decode_transfer_encoding(@body_part_jpmobile, @charset) end end