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 310
310: def initialize( dir = nil )
311: @dirname = dir || ENV['MAILDIR']
312: raise ArgumentError, "not directory: #{@dirname}"\
313: unless FileTest.directory? @dirname
314: @new = "#{@dirname}/new"
315: @tmp = "#{@dirname}/tmp"
316: @cur = "#{@dirname}/cur"
317: end
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 303
303: def Maildir.unique_number
304: synchronize {
305: @seq += 1
306: return @seq
307: }
308: end
Public Instance methods
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 380
380: def check_tmp
381: old = Time.now.to_i - TOO_OLD
382:
383: each_filename(@tmp) do |full, fname|
384: if FileTest.file? full and
385: File.stat(full).mtime.to_i < old
386: File.unlink full
387: end
388: end
389: end
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 327
327: def close
328: end
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 319
319: def directory
320: @dirname
321: 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 368
368: def each_new_port
369: mail_files(@new).each do |path|
370: dest = @cur + '/' + File.basename(path)
371: File.rename path, dest
372: yield PORT_CLASS.new(dest)
373: end
374:
375: check_tmp
376: end
Alias for each_new_port
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 330
330: def each_port
331: mail_files(@cur).each do |path|
332: yield PORT_CLASS.new(path)
333: end
334: end
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 323
323: def inspect
324: "#<#{self.class} #{@dirname}>"
325: end
Alias for new_port
This method is also aliased as
new_mail
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 346
346: def new_port
347: fname = nil
348: tmpfname = nil
349: newfname = nil
350:
351: begin
352: fname = "#{Time.now.to_i}.#{$$}_#{Maildir.unique_number}.#{Socket.gethostname}"
353:
354: tmpfname = "#{@tmp}/#{fname}"
355: newfname = "#{@new}/#{fname}"
356: end while FileTest.exist? tmpfname
357:
358: if block_given?
359: File.open(tmpfname, 'w') {|f| yield f }
360: File.rename tmpfname, newfname
361: PORT_CLASS.new(newfname)
362: else
363: File.open(tmpfname, 'w') {|f| f.write "\n\n" }
364: PORT_CLASS.new(tmpfname)
365: end
366: 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 338
338: def reverse_each_port
339: mail_files(@cur).reverse_each do |path|
340: yield PORT_CLASS.new(path)
341: end
342: end
Private Instance methods
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 401
401: def each_filename( dir )
402: Dir.foreach(dir) do |fname|
403: path = "#{dir}/#{fname}"
404: if fname[0] != ?. and FileTest.file? path
405: yield path, fname
406: end
407: end
408: end
[ show source ]
# File lib/action_mailer/vendor/tmail/mailbox.rb, line 393
393: def mail_files( dir )
394: Dir.entries(dir)\
395: .select {|s| s[0] != ?. }\
396: .sort_by {|s| s.slice(/\A\d+/).to_i }\
397: .map {|s| "#{dir}/#{s}" }\
398: .select {|path| FileTest.file? path }
399: end