Method: MultiMail::Receiver::Base::ClassMethods#condense
- Defined in:
- lib/multi_mail/receiver/base.rb
#condense(message) ⇒ Mail::Message
Condenses a message's HTML parts to a single HTML part.
154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 |
# File 'lib/multi_mail/receiver/base.rb', line 154 def condense() if .multipart? && .parts.any?(&:multipart?) # Get the message parts as a flat array. result = flatten(Mail.new, .parts.dup) # Rebuild the message's parts. .parts.clear # Merge non-attachments with the same content type. (result.parts - result.).group_by(&:content_type).each do |content_type,group| body = group.map{|part| part.body.decoded}.join # Make content types match across all APIs. if content_type == 'text/plain; charset=us-ascii' # `text/plain; charset=us-ascii` is the default content type. content_type = 'text/plain' elsif content_type == 'text/html; charset=us-ascii' content_type = 'text/html; charset=UTF-8' body = body.encode('UTF-8') if body.respond_to?(:encode) end .parts << Mail::Part.new({ :content_type => content_type, :body => body, }) end # Add attachments last. result..each do |part| .parts << part end end end |