Class: CircularMail::Header

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

Overview

Description: Basically holds an array of HeaderField objects.

You can add, modify, remove fields, then get the whole header as a string by calling to_s (alias: get)

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#fieldsObject (readonly)

Returns the value of attribute fields.



553
554
555
# File 'lib/circular-mail.rb', line 553

def fields
  @fields
end

Instance Method Details

#add_field(name, body) ⇒ Object



555
556
557
558
559
# File 'lib/circular-mail.rb', line 555

def add_field(name, body)
  CircularMail.die("Although RFC-2822 allows multiple header fields of the same type, it *should* be avoided!") if duplicate_header?(name) && CircularMail::config('strictness')
  field = CircularMail::HeaderField.new(name, body)
  @fields.push(field)
end

#duplicate_header?(name) ⇒ Boolean Also known as: present?

Returns:

  • (Boolean)


597
598
599
600
601
602
603
604
# File 'lib/circular-mail.rb', line 597

def duplicate_header?(name)
  if @fields.length > 0
    @fields.each { |field|
      return true if field.name == name
    }
  end
  false
end

#getObject



578
579
580
581
582
583
584
585
586
# File 'lib/circular-mail.rb', line 578

def get()
  head = ""
  if @fields.length > 0
    @fields.each { |field|
      head << field.get()
    }
  end
  return head
end

#get_field(name) ⇒ Object



588
589
590
591
592
593
594
595
# File 'lib/circular-mail.rb', line 588

def get_field(name)
  if @fields.length > 0
    @fields.each { |field|
      return field.body if field.name == name
    }
  end
  return nil
end

#modify_field(name, body) ⇒ Object



561
562
563
564
565
566
# File 'lib/circular-mail.rb', line 561

def modify_field(name, body)
  if @fields.length > 0
    index = @fields.index{ |field| field.name == name}
    @fields[index] = CircularMail::HeaderField.new(name, body) if index > -1 && index < @fields.size
  end
end

#remove_all_fieldsObject



574
575
576
# File 'lib/circular-mail.rb', line 574

def remove_all_fields()
  @fields = []
end

#remove_field(name) ⇒ Object



568
569
570
571
572
# File 'lib/circular-mail.rb', line 568

def remove_field(name)
  if @fields.length > 0
    @fields.keep_if { |field| field.name != name}
  end
end