Class: ActionMailer::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/inline_attachment.rb

Instance Method Summary collapse

Instance Method Details

#create_mailObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/inline_attachment.rb', line 19

def create_mail
  # sniff out inline html parts with inline images and wrap them up in a
  # multipart/related mime part
  got_inlines = false
  related_parts = []
  for_deletion = []
  @parts.each_with_index do |p,i|
    logger.debug "Considering #{i}"
    if p.content_disposition == 'inline' && p.content_type =~ %r{^image/}i && p.headers[CID_NAME]
      logger.debug "Just adding [#{i}] to the list\n#{p.filename}"
      for_deletion << i
      related_parts << p
      got_inlines = true
    end

    if got_inlines && p.content_type =~ %r{text/html}i
      @parts[i] = ActionMailer::Part.new( :content_type => "multipart/related" )
      @parts[i].parts << p
      related_parts.each do |rp|
        @parts[i].parts << rp
      end
      got_inlines = false
      related_parts = []
    end
  end
  for_deletion.sort{|a,b|b<=>a}.each {|i|@parts.delete_at(i)}
  ia_original_create_mail
end

#ia_original_create_mailObject



18
# File 'lib/inline_attachment.rb', line 18

alias_method :ia_original_create_mail, :create_mail