Class: TMail::Maildir

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

Constant Summary collapse

PORT_CLASS =
MaildirPort
TOO_OLD =

36 hour

60 * 60 * 36

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dir = nil) ⇒ Maildir

Returns a new instance of Maildir.

Raises:

  • (ArgumentError)


310
311
312
313
314
315
316
317
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 310

def initialize( dir = nil )
  @dirname = dir || ENV['MAILDIR']
  raise ArgumentError, "not directory: #{@dirname}"\
                          unless FileTest.directory? @dirname
  @new = "#{@dirname}/new"
  @tmp = "#{@dirname}/tmp"
  @cur = "#{@dirname}/cur"
end

Class Method Details

.unique_numberObject



303
304
305
306
307
308
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 303

def Maildir.unique_number
  synchronize {
      @seq += 1
      return @seq
  }
end

Instance Method Details

#check_tmpObject



380
381
382
383
384
385
386
387
388
389
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 380

def check_tmp
  old = Time.now.to_i - TOO_OLD
  
  each_filename(@tmp) do |full, fname|
    if FileTest.file? full and
       File.stat(full).mtime.to_i < old
      File.unlink full
    end
  end
end

#closeObject



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

def close
end

#directoryObject



319
320
321
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 319

def directory
  @dirname
end

#each_new_portObject Also known as: each_newmail



368
369
370
371
372
373
374
375
376
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 368

def each_new_port
  mail_files(@new).each do |path|
    dest = @cur + '/' + File.basename(path)
    File.rename path, dest
    yield PORT_CLASS.new(dest)
  end

  check_tmp
end

#each_portObject Also known as: each, each_mail



330
331
332
333
334
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 330

def each_port
  mail_files(@cur).each do |path|
    yield PORT_CLASS.new(path)
  end
end

#inspectObject



323
324
325
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 323

def inspect
  "#<#{self.class} #{@dirname}>"
end

#new_portObject Also known as: new_mail



346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 346

def new_port
  fname = nil
  tmpfname = nil
  newfname = nil

  begin
    fname = "#{Time.now.to_i}.#{$$}_#{Maildir.unique_number}.#{Socket.gethostname}"
    
    tmpfname = "#{@tmp}/#{fname}"
    newfname = "#{@new}/#{fname}"
  end while FileTest.exist? tmpfname

  if block_given?
    File.open(tmpfname, 'w') {|f| yield f }
    File.rename tmpfname, newfname
    PORT_CLASS.new(newfname)
  else
    File.open(tmpfname, 'w') {|f| f.write "\n\n" }
    PORT_CLASS.new(tmpfname)
  end
end

#reverse_each_portObject Also known as: reverse_each



338
339
340
341
342
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 338

def reverse_each_port
  mail_files(@cur).reverse_each do |path|
    yield PORT_CLASS.new(path)
  end
end