Class: SMail

Inherits:
Object
  • Object
show all
Defined in:
lib/smail/smail.rb,
lib/smail/header.rb,
lib/smail/parser.rb,
lib/smail/version.rb

Overview

SMail

A very simple library for parsing email messages.

Based on Email::Simple from CPAN

No decoding of any fields or the body is attempted, see SMail::MIME.

Defined Under Namespace

Modules: VERSION Classes: Header

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text = '') ⇒ SMail

Returns a new instance of SMail.



15
16
17
18
19
# File 'lib/smail/smail.rb', line 15

def initialize(text = '')
  head, @body, @crlf = split_head_from_body(text)

  @head = read_header(head)
end

Instance Attribute Details

#bodyObject

The body text of the email.



13
14
15
# File 'lib/smail/smail.rb', line 13

def body
  @body
end

#crlfObject (readonly)

The line ending found in this email.



11
12
13
# File 'lib/smail/smail.rb', line 11

def crlf
  @crlf
end

Instance Method Details

#header(field) ⇒ Object

Returns the first value for the named header



22
23
24
# File 'lib/smail/smail.rb', line 22

def header(field)
  @head.header(field)
end

#header=(header) ⇒ Object

:nodoc:



44
45
46
# File 'lib/smail/smail.rb', line 44

def header=(header) #:nodoc:
  # FIXME: takes a string and splits it??
end

#header_namesObject

Returns the list of header names currently in the message. The order is not significant.



49
50
51
# File 'lib/smail/smail.rb', line 49

def header_names
  @head.header_names
end

#header_pairsObject

Returns a list of pairs describing the contents of the header.



54
55
56
# File 'lib/smail/smail.rb', line 54

def header_pairs
  @head.header_pairs
end

#header_set(field, line) ⇒ Object

Sets the header to contain the given data, if there is more than one existing header the extra headers are removed.



34
35
36
# File 'lib/smail/smail.rb', line 34

def header_set(field, line)
  headers_set(field, line).first
end

#headers(field) ⇒ Object

Returns an array containing every value for the named header, for the first instance see header



28
29
30
# File 'lib/smail/smail.rb', line 28

def headers(field)
  @head.headers(field)
end

#headers_set(field, *lines) ⇒ Object

Sets the headers to contain the given data, passing in multiple lines results in multiple headers and order is retained.



40
41
42
# File 'lib/smail/smail.rb', line 40

def headers_set(field, *lines)
  @head.header_set(field, lines)
end

#to_sObject

:nodoc:



58
59
60
# File 'lib/smail/smail.rb', line 58

def to_s #:nodoc:
  @head.to_s + @crlf + @body
end