class PostageApp::Mailer::Attachments

Wrapper for creating attachments Attachments sent to PostageApp are in the following format:

'filename.ext' => {
  content_type: 'content/type',
  content: 'base64_encoded_content'
 }

Public Class Methods

new(message) click to toggle source
# File lib/postageapp/mailer/mailer_4.rb, line 45
def initialize(message)
  @_message = message
  message.arguments['attachments'] ||= { }
end

Public Instance Methods

[]=(filename, attachment) click to toggle source
# File lib/postageapp/mailer/mailer_4.rb, line 50
def []=(filename, attachment)
  default_content_type = MIME::Types.type_for(filename).first.content_type rescue ''

  case (attachment)
  when Hash
    content_type = attachment[:content_type] || default_content_type
    content = Base64.encode64(attachment[:body])
  else
    content_type = default_content_type
    content = Base64.encode64(attachment)
  end

  @_message.arguments['attachments'][filename] = {
    'content_type' => content_type,
    'content' => content
  }
end