Class: MIME::Header

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

Overview

Header section for Internet and MIME messages.

Instance Method Summary collapse

Constructor Details

#initializeHeader

Returns a new instance of Header.



8
9
10
# File 'lib/mime/header.rb', line 8

def initialize
  @headers = Hash.new
end

Instance Method Details

#delete(name) ⇒ Object

Delete header associated with name.



43
44
45
# File 'lib/mime/header.rb', line 43

def delete name
  @headers.delete_if {|k,v| name.downcase == k.downcase }
end

#get(name) ⇒ Object

Get header value associated with name.



26
27
28
29
# File 'lib/mime/header.rb', line 26

def get name
  _, value = @headers.find {|k,v| name.downcase == k.downcase }
  value
end

#set(name, value) ⇒ Object

Set header name to value. If a header of the same name exists it will be overwritten. Header names are case-insensitive.



35
36
37
38
# File 'lib/mime/header.rb', line 35

def set name, value
  delete(name)
  @headers.store(name, value) unless value.nil?
end

#to_sObject

Convert all headers to their string equivalents and join them using the RFC 2822 CRLF line separator. – TODO fold lines to 78 chars. word.scan(/(.,?)1,78/) OR word.split



19
20
21
# File 'lib/mime/header.rb', line 19

def to_s
  @headers.to_a.map {|kv| kv.join(": ")}.join("\r\n")
end