Class: TMail::UNIXMbox

Inherits:
Object
  • Object
show all
Defined in:
lib/action_mailer/vendor/tmail/mailbox.rb,
lib/action_mailer/vendor/tmail/obsolete.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fname, mhdir, readonly, static) ⇒ UNIXMbox

Returns a new instance of UNIXMbox.



175
176
177
178
179
180
181
182
183
184
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 175

def initialize( fname, mhdir, readonly, static )
  @filename = fname
  @readonly = readonly
  @closed = false

  Dir.mkdir mhdir
  @real = MhMailbox.new(mhdir)
  @finalizer = UNIXMbox.mkfinal(@real, @filename, !@readonly, !static)
  ObjectSpace.define_finalizer self, @finalizer
end

Class Method Details

.create_from_line(port) ⇒ Object

make _From line



209
210
211
212
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 209

def UNIXMbox.create_from_line( port )
  sprintf 'From %s %s',
          fromaddr(), TextUtils.time2str(File.mtime(port.filename))
end

.lock(fname) ⇒ Object



151
152
153
154
155
156
157
158
159
160
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 151

def UNIXMbox.lock( fname )
  begin
    f = File.open(fname)
    f.flock File::LOCK_EX
    yield f
  ensure
    f.flock File::LOCK_UN
    f.close if f and not f.closed?
  end
end

.mkfinal(mh, mboxfile, writeback_p, cleanup_p) ⇒ Object



186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 186

def UNIXMbox.mkfinal( mh, mboxfile, writeback_p, cleanup_p )
  lambda {
      if writeback_p
        lock(mboxfile) {|f|
            mh.each_port do |port|
              f.puts create_from_line(port)
              port.ropen {|r|
                  f.puts r.read
              }
            end
        }
      end
      if cleanup_p
        Dir.foreach(mh.dirname) do |fname|
          next if /\A\.\.?\z/ === fname
          File.unlink "#{mh.dirname}/#{fname}"
        end
        Dir.rmdir mh.dirname
      end
  }
end

.new(fname, tmpdir = nil, readonly = false) ⇒ Object



166
167
168
169
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 166

def UNIXMbox.new( fname, tmpdir = nil, readonly = false )
  tmpdir = ENV['TEMP'] || ENV['TMP'] || '/tmp'
  newobj(fname, "#{tmpdir}/ruby_tmail_#{$$}_#{rand()}", readonly, false)
end

.newobjObject



163
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 163

alias newobj new

.static_new(fname, dir, readonly = false) ⇒ Object



171
172
173
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 171

def UNIXMbox.static_new( fname, dir, readonly = false )
  newobj(fname, dir, readonly, true)
end

Instance Method Details

#closeObject



222
223
224
225
226
227
228
229
230
231
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 222

def close
  return if @closed

  ObjectSpace.undefine_finalizer self
  @finalizer.call
  @finalizer = nil
  @real = nil
  @closed = true
  @updated = nil
end

#each_new_port(mtime = nil) ⇒ Object Also known as: each_newmail

old #each_mail returns Port def each_mail( &block )

each_port do |port|
  yield Mail.new(port)
end

end



256
257
258
259
260
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 256

def each_new_port( mtime = nil )
  close_check
  update
  @real.each_new_port(mtime) {|p| yield p }
end

#each_port(&block) ⇒ Object Also known as: each, each_mail



233
234
235
236
237
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 233

def each_port( &block )
  close_check
  update
  @real.each_port(&block)
end

#new_portObject Also known as: new_mail



262
263
264
265
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 262

def new_port
  close_check
  @real.new_port
end

#reverse_each_port(&block) ⇒ Object Also known as: reverse_each



241
242
243
244
245
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 241

def reverse_each_port( &block )
  close_check
  update
  @real.reverse_each_port(&block)
end