Class: Mbox::Mail
- Inherits:
-
Object
show all
- Defined in:
- lib/mbox/mail.rb,
lib/mbox/mail/file.rb,
lib/mbox/mail/content.rb,
lib/mbox/mail/headers.rb,
lib/mbox/mail/metadata.rb,
lib/mbox/mail/headers/status.rb,
lib/mbox/mail/headers/content_type.rb
Defined Under Namespace
Classes: Content, File, Headers, Metadata
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(metadata, headers, content) ⇒ Mail
Returns a new instance of Mail.
75
76
77
78
79
|
# File 'lib/mbox/mail.rb', line 75
def initialize (metadata, , content)
@metadata = metadata
@headers =
@content = content
end
|
Instance Attribute Details
#content ⇒ Object
Returns the value of attribute content.
73
74
75
|
# File 'lib/mbox/mail.rb', line 73
def content
@content
end
|
Returns the value of attribute headers.
73
74
75
|
# File 'lib/mbox/mail.rb', line 73
def
@headers
end
|
Returns the value of attribute metadata.
73
74
75
|
# File 'lib/mbox/mail.rb', line 73
def metadata
@metadata
end
|
Class Method Details
.parse(input, options = {}) ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
# File 'lib/mbox/mail.rb', line 27
def self.parse (input, options = {})
metadata = Mbox::Mail::Metadata.new
= Mbox::Mail::Headers.new
content = Mbox::Mail::Content.new()
next until input.eof? || (line = input.readline).match(options[:separator])
return if !line || line.empty?
metadata.parse_from line
until input.eof? || (line = input.readline).match(options[:separator])
break unless line.match(/^>+/)
metadata.parse_from line
end
current = ''
begin
break if line.strip.empty?
current << line
end until input.eof? || (line = input.readline).match(options[:separator])
.parse(current)
current = ''
until input.eof? || (line = input.readline).match(options[:separator])
next if options[:headers_only]
current << line
end
unless options[:headers_only]
content.parse(current.chomp)
end
if !input.eof? && line
input.seek(-line.length, IO::SEEK_CUR)
end
Mail.new(metadata, , content)
end
|
Instance Method Details
#from ⇒ Object
81
82
83
|
# File 'lib/mbox/mail.rb', line 81
def from
metadata.from.first.name
end
|
#inspect ⇒ Object
99
100
101
|
# File 'lib/mbox/mail.rb', line 99
def inspect
"#<Mail:#{from}>"
end
|
#save_to(path) ⇒ Object
85
86
87
88
89
|
# File 'lib/mbox/mail.rb', line 85
def save_to (path)
File.open(path, 'w') {|f|
f.write to_s
}
end
|
#to_s ⇒ Object
95
96
97
|
# File 'lib/mbox/mail.rb', line 95
def to_s
"#{}\n#{content}"
end
|
#unread? ⇒ Boolean
91
92
93
|
# File 'lib/mbox/mail.rb', line 91
def unread?
![:status].read? rescue true
end
|