Methods
- check_tmp
- close
- directory
- each
- each_filename
- each_mail
- each_new_port
- each_newmail
- each_port
- inspect
- mail_files
- new
- new_mail
- new_port
- reverse_each
- reverse_each_port
- unique_number
Constants
| PORT_CLASS | = | MaildirPort |
| TOO_OLD | = | 60 * 60 * 36 |
Public Class methods
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 329
329: def initialize( dir = nil )
330: @dirname = dir || ENV['MAILDIR']
331: raise ArgumentError, "not directory: #{@dirname}"\
332: unless FileTest.directory? @dirname
333: @new = "#{@dirname}/new"
334: @tmp = "#{@dirname}/tmp"
335: @cur = "#{@dirname}/cur"
336: end
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 322
322: def Maildir.unique_number
323: synchronize {
324: @seq += 1
325: return @seq
326: }
327: end
Public Instance methods
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 399
399: def check_tmp
400: old = Time.now.to_i - TOO_OLD
401:
402: each_filename(@tmp) do |full, fname|
403: if FileTest.file? full and
404: File.stat(full).mtime.to_i < old
405: File.unlink full
406: end
407: end
408: end
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 346
346: def close
347: end
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 338
338: def directory
339: @dirname
340: end
Alias for each_port
Alias for each_port
This method is also aliased as
each_newmail
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 387
387: def each_new_port
388: mail_files(@new).each do |path|
389: dest = @cur + '/' + File.basename(path)
390: File.rename path, dest
391: yield PORT_CLASS.new(dest)
392: end
393:
394: check_tmp
395: end
Alias for each_new_port
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 349
349: def each_port
350: mail_files(@cur).each do |path|
351: yield PORT_CLASS.new(path)
352: end
353: end
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 342
342: def inspect
343: "#<#{self.class} #{@dirname}>"
344: end
Alias for new_port
This method is also aliased as
new_mail
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 365
365: def new_port
366: fname = nil
367: tmpfname = nil
368: newfname = nil
369:
370: begin
371: fname = "#{Time.now.to_i}.#{$$}_#{Maildir.unique_number}.#{Socket.gethostname}"
372:
373: tmpfname = "#{@tmp}/#{fname}"
374: newfname = "#{@new}/#{fname}"
375: end while FileTest.exist? tmpfname
376:
377: if block_given?
378: File.open(tmpfname, 'w') {|f| yield f }
379: File.rename tmpfname, newfname
380: PORT_CLASS.new(newfname)
381: else
382: File.open(tmpfname, 'w') {|f| f.write "\n\n" }
383: PORT_CLASS.new(tmpfname)
384: end
385: end
Alias for reverse_each_port
This method is also aliased as
reverse_each
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 357
357: def reverse_each_port
358: mail_files(@cur).reverse_each do |path|
359: yield PORT_CLASS.new(path)
360: end
361: end
Private Instance methods
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 420
420: def each_filename( dir )
421: Dir.foreach(dir) do |fname|
422: path = "#{dir}/#{fname}"
423: if fname[0] != ?. and FileTest.file? path
424: yield path, fname
425: end
426: end
427: end
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 412
412: def mail_files( dir )
413: Dir.entries(dir)\
414: .select {|s| s[0] != ?. }\
415: .sort_by {|s| s.slice(/\A\d+/).to_i }\
416: .map {|s| "#{dir}/#{s}" }\
417: .select {|path| FileTest.file? path }
418: end