def rearrange!
      return unless @mobile && @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/}) && 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
def rearrange!
      return unless @mobile && @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/}) && 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
-- docomo
 multipart/mixed
   |- multipart/related
   |    |- multipart/alternative
   |    |    |- text/plain
   |    |    |- text/html
   |    |- image/xxxx (インライン画像)
   |- image/xxxx (添付画像)
 -- au
 multipart/mixed
   |- multipart/alternative
   |    |- text/plain
   |    |- text/html
   |- image/xxxx (インライン画像)
   |- image/xxxx (添付画像)
 -- normal
 multipart/mixed
   |- multipart/alternative
   |    |- text/plain
   |    |- text/html
   |    |- image/xxxx (インライン画像)
   |- image/xxxx (添付画像)