Class: TMail::Maildir
- Inherits:
-
Object
- Object
- TMail::Maildir
- Extended by:
- Mutex_m
- Defined in:
- lib/tmail-pure/mailbox.rb,
lib/tmail-pure/obsolete.rb
Constant Summary collapse
- PORT_CLASS =
MaildirPort
- TOO_OLD =
36 hour
60 * 60 * 36
Class Method Summary collapse
Instance Method Summary collapse
- #check_tmp ⇒ Object
- #close ⇒ Object
- #directory ⇒ Object
- #each_new_port ⇒ Object (also: #each_newmail)
- #each_port ⇒ Object (also: #each, #each_mail)
-
#initialize(dir = nil) ⇒ Maildir
constructor
A new instance of Maildir.
- #inspect ⇒ Object
- #new_port(&block) ⇒ Object (also: #new_mail)
- #reverse_each_port ⇒ Object (also: #reverse_each)
Constructor Details
#initialize(dir = nil) ⇒ Maildir
Returns a new instance of Maildir.
291 292 293 294 295 296 297 298 |
# File 'lib/tmail-pure/mailbox.rb', line 291 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_number ⇒ Object
284 285 286 287 288 289 |
# File 'lib/tmail-pure/mailbox.rb', line 284 def Maildir.unique_number synchronize { @seq += 1 return @seq } end |
Instance Method Details
#check_tmp ⇒ Object
358 359 360 361 362 363 364 365 366 367 368 |
# File 'lib/tmail-pure/mailbox.rb', line 358 def check_tmp old = Time.now.to_i - TOO_OLD mail_entries(@tmp).each do |ent| begin path = "#{@tmp}/#{ent}" File.unlink path if File.mtime(path).to_i < old rescue Errno::ENOENT # maybe other process removed end end end |
#close ⇒ Object
308 309 |
# File 'lib/tmail-pure/mailbox.rb', line 308 def close end |
#directory ⇒ Object
300 301 302 |
# File 'lib/tmail-pure/mailbox.rb', line 300 def directory @dirname end |
#each_new_port ⇒ Object Also known as: each_newmail
347 348 349 350 351 352 353 354 |
# File 'lib/tmail-pure/mailbox.rb', line 347 def each_new_port sorted_mail_entries(@new).each do |ent| dest = "#{@cur}/#{ent}" File.rename "#{@new}/#{ent}", dest yield PORT_CLASS.new(dest) end check_tmp end |
#each_port ⇒ Object Also known as: each, each_mail
311 312 313 314 315 |
# File 'lib/tmail-pure/mailbox.rb', line 311 def each_port sorted_mail_entries(@cur).each do |ent| yield PORT_CLASS.new("#{@cur}/#{ent}") end end |
#inspect ⇒ Object
304 305 306 |
# File 'lib/tmail-pure/mailbox.rb', line 304 def inspect "#<#{self.class} #{@dirname}>" end |
#new_port(&block) ⇒ Object Also known as: new_mail
327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/tmail-pure/mailbox.rb', line 327 def new_port(&block) 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', &block) 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_port ⇒ Object Also known as: reverse_each
319 320 321 322 323 |
# File 'lib/tmail-pure/mailbox.rb', line 319 def reverse_each_port sorted_mail_entries(@cur).reverse_each do |ent| yield PORT_CLASS.new("#{@cur}/#{ent}") end end |