mbox 0.0.4.1 → 0.0.4.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/mbox/mbox.rb +25 -7
  2. metadata +2 -2
@@ -64,30 +64,44 @@ class Mbox
64
64
  @input.close
65
65
  end
66
66
 
67
- def each (opts = {})
68
- @input.seek 0
69
-
67
+ def lock
70
68
  if @input.respond_to? :flock
71
69
  @input.flock File::LOCK_SH
72
70
  end
71
+ end
72
+
73
+ def unlock
74
+ if @input.respond_to? :flock
75
+ @input.flock File::LOCK_UN
76
+ end
77
+ end
78
+
79
+ def each (opts = {})
80
+ @input.seek 0
81
+
82
+ lock
73
83
 
74
84
  while mail = Mail.parse(@input, options.merge(opts))
75
85
  yield mail
76
86
  end
77
87
 
78
- if @input.respond_to? :flock
79
- @input.flock File::LOCK_UN
80
- end
88
+ unlock
81
89
  end
82
90
 
83
91
  def [] (index, opts = {})
92
+ lock
93
+
84
94
  seek index
85
95
 
86
96
  if @input.eof?
87
97
  raise IndexError, "#{index} is out of range"
88
98
  end
89
99
 
90
- Mail.parse(@input, options.merge(opts))
100
+ mail = Mail.parse(@input, options.merge(opts))
101
+
102
+ unlock
103
+
104
+ mail
91
105
  end
92
106
 
93
107
  def seek (to, whence = IO::SEEK_SET)
@@ -121,6 +135,8 @@ class Mbox
121
135
  last = ''
122
136
  length = 0
123
137
 
138
+ lock
139
+
124
140
  while line = @input.readline rescue nil
125
141
  if line.match(options[:separator]) && last.chomp.empty?
126
142
  length += 1
@@ -129,6 +145,8 @@ class Mbox
129
145
  last = line
130
146
  end
131
147
 
148
+ unlock
149
+
132
150
  length
133
151
  end
134
152
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mbox
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4.1
4
+ version: 0.0.4.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-08 00:00:00.000000000 Z
12
+ date: 2012-05-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: call-me