Class: Mail::Message

Inherits:
Object
  • Object
show all
Defined in:
app/models/post.rb

Instance Method Summary collapse

Instance Method Details

#add_to_body(text_to_add) ⇒ Object

This method adds the given string to all plain text parts of the message. For multipart messages, this simply adds a part containing the text_to_add. This is used for email footers.

Attention: Multipart emails may have a tree structure, i.e. a part may contain several other parts. Therefore, this method calls itself recursively.



174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'app/models/post.rb', line 174

def add_to_body( text_to_add )
  CharlockHolmes
  require 'charlock_holmes/string'

  if self.multipart?

    # Simply add another part.
    # According to the documentation, this call will add another part 
    # rather than wiping all.
    self.body = text_to_add

  else
    
    # plain text parts
    if self.content_type == nil || self.content_type.include?('text/plain')
      self.body = self.body_in_utf8 + text_to_add.encode('UTF-8')
    end

  end

  return self
end

#body_in_utf8Object

This returns the message body in utf8 encoding.



154
155
156
157
158
159
160
161
162
163
164
# File 'app/models/post.rb', line 154

def body_in_utf8
  CharlockHolmes
  require 'charlock_holmes/string'

  body = self.body.decoded
  if body.present?
    encoding = body.detect_encoding[:encoding]
    body = body.force_encoding(encoding).encode('UTF-8')
  end
  return body
end