mailread 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/mailread.rb +62 -0
- metadata +65 -0
data/lib/mailread.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
# The Mail class represents an internet mail message (as per RFC822, RFC2822)
|
2
|
+
# with headers and a body.
|
3
|
+
class Mail
|
4
|
+
|
5
|
+
# Create a new Mail where +f+ is either a stream which responds to gets(),
|
6
|
+
# or a path to a file. If +f+ is a path it will be opened.
|
7
|
+
#
|
8
|
+
# The whole message is read so it can be made available through the #header,
|
9
|
+
# #[] and #body methods.
|
10
|
+
#
|
11
|
+
# The "From " line is ignored if the mail is in mbox format.
|
12
|
+
def initialize(f)
|
13
|
+
unless defined? f.gets
|
14
|
+
f = open(f, "r")
|
15
|
+
opened = true
|
16
|
+
end
|
17
|
+
|
18
|
+
@header = {}
|
19
|
+
@body = []
|
20
|
+
begin
|
21
|
+
while line = f.gets()
|
22
|
+
line.chop!
|
23
|
+
next if /^From /=~line # skip From-line
|
24
|
+
break if /^$/=~line # end of header
|
25
|
+
|
26
|
+
if /^(\S+?):\s*(.*)/=~line
|
27
|
+
(attr = $1).capitalize!
|
28
|
+
@header[attr] = $2
|
29
|
+
elsif attr
|
30
|
+
line.sub!(/^\s*/, '')
|
31
|
+
@header[attr] += "\n" + line
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
return unless line
|
36
|
+
|
37
|
+
while line = f.gets()
|
38
|
+
break if /^From /=~line
|
39
|
+
@body.push(line)
|
40
|
+
end
|
41
|
+
ensure
|
42
|
+
f.close if opened
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Return the headers as a Hash.
|
47
|
+
def header
|
48
|
+
return @header
|
49
|
+
end
|
50
|
+
|
51
|
+
# Return the message body as an Array of lines
|
52
|
+
def body
|
53
|
+
return @body
|
54
|
+
end
|
55
|
+
|
56
|
+
# Return the header corresponding to +field+.
|
57
|
+
#
|
58
|
+
# Matching is case-insensitive.
|
59
|
+
def [](field)
|
60
|
+
@header[field.capitalize]
|
61
|
+
end
|
62
|
+
end
|
metadata
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mailread
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 59
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 9
|
9
|
+
- 0
|
10
|
+
version: 0.9.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- pedro mg
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2013-07-01 00:00:00 Z
|
19
|
+
dependencies: []
|
20
|
+
|
21
|
+
description: The Mail class represents an internet mail message (as per RFC822, RFC2822) with headers and a body
|
22
|
+
email: pedro.mota@gmail.com
|
23
|
+
executables: []
|
24
|
+
|
25
|
+
extensions: []
|
26
|
+
|
27
|
+
extra_rdoc_files: []
|
28
|
+
|
29
|
+
files:
|
30
|
+
- lib/mailread.rb
|
31
|
+
homepage: http://rubygems.org/gems/mailread
|
32
|
+
licenses: []
|
33
|
+
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
|
37
|
+
require_paths:
|
38
|
+
- lib
|
39
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ">="
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
hash: 3
|
45
|
+
segments:
|
46
|
+
- 0
|
47
|
+
version: "0"
|
48
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ">="
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
hash: 3
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
requirements: []
|
58
|
+
|
59
|
+
rubyforge_project:
|
60
|
+
rubygems_version: 1.8.17
|
61
|
+
signing_key:
|
62
|
+
specification_version: 3
|
63
|
+
summary: Mail message class
|
64
|
+
test_files: []
|
65
|
+
|