Class: CircularMail::Message

Inherits:
Object
  • Object
show all
Defined in:
lib/circular-mail.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attachmentsObject

Returns the value of attribute attachments.



356
357
358
# File 'lib/circular-mail.rb', line 356

def attachments
  @attachments
end

#bodyObject

Returns the value of attribute body.



353
354
355
# File 'lib/circular-mail.rb', line 353

def body
  @body
end

#character_setObject

Returns the value of attribute character_set.



355
356
357
# File 'lib/circular-mail.rb', line 355

def character_set
  @character_set
end

#formatObject

Returns the value of attribute format.



354
355
356
# File 'lib/circular-mail.rb', line 354

def format
  @format
end

#headerObject

Returns the value of attribute header.



352
353
354
# File 'lib/circular-mail.rb', line 352

def header
  @header
end

Instance Method Details

#getObject



398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
# File 'lib/circular-mail.rb', line 398

def get()
  if @header.fields.length > 0
    CircularMail::die("Date and From header fields must be present in the message as per RFC-2822!") if !@header.present?('Date') || !@header.present?('From')
    @header.add_field('Content-Transfer-Encoding', 'base64') unless header.present?('Content-Transfer-Encoding')
    message_body = CircularMail::encode(@body, @header.get_field('Content-Transfer-Encoding'))

    if @format == 'text'
      content_type = 'text/plain'
    else
      content_type = 'text/html'
    end

    if @attachments.length == 0
      @header.add_field('Content-Type', "#{content_type};charset=#{@character_set}")
      return "#{@header.get()}\r\n#{message_body}"
    else
      @header.add_field('MIME-Version', '1.0')
      @header.add_field('Content-Type', "multipart/mixed; boundary=#{$message_id}")
      message_body = "Content-Type:#{content_type}\r\nContent-Transfer-Encoding:base64\r\n\r\n#{message_body}--#{$message_id}"
      return "#{@header.get()}\r\n--#{$message_id}\r\n#{message_body}\r\n#{attachments_body()}"
    end
  else
    CircularMail::die("Cannot generate message, because lack of header fields!") if CircularMail::config('strictness')
    return nil
  end
end