Class: Sisimai::Mail::Maildir
- Inherits:
-
Object
- Object
- Sisimai::Mail::Maildir
- Defined in:
- lib/sisimai/mail/maildir.rb
Overview
Sisimai::Mail::Maildir is a reader for getting contents of each email in the Maildir/ directory.
Instance Attribute Summary collapse
-
#dir ⇒ Object
readonly
:dir [String] Path to Maildir/ :size [Integer] The number of files/directories in the Maildir/ :path [String] Path to each file :file, [String] Each file name of a mail in the Maildir/ :offset [Integer] The number of email files in the Maildir/ :handle [IO::Dir] Directory handle.
-
#file ⇒ Object
Returns the value of attribute file.
-
#handle ⇒ Object
Returns the value of attribute handle.
-
#offset ⇒ Object
Returns the value of attribute offset.
-
#path ⇒ Object
Returns the value of attribute path.
-
#size ⇒ Object
Returns the value of attribute size.
Instance Method Summary collapse
-
#initialize(argv1) ⇒ Sisimai::Mail::Maildir
constructor
Constructor of Sisimai::Mail::Maildir.
-
#read ⇒ String
Maildir reader, works as an iterator.
Constructor Details
#initialize(argv1) ⇒ Sisimai::Mail::Maildir
Constructor of Sisimai::Mail::Maildir
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/sisimai/mail/maildir.rb', line 18 def initialize(argv1) raise Errno::ENOENT if File.exist?(argv1) == false raise Errno::ENOTDIR if File.ftype(argv1) != 'directory' @path = nil @size = Dir.entries(argv1).size @dir = argv1 @file = nil @offset = 0 @handle = Dir.open(argv1) end |
Instance Attribute Details
#dir ⇒ Object (readonly)
:dir [String] Path to Maildir/ :size [Integer] The number of files/directories in the Maildir/ :path [String] Path to each file :file, [String] Each file name of a mail in the Maildir/ :offset [Integer] The number of email files in the Maildir/ :handle [IO::Dir] Directory handle
11 12 13 |
# File 'lib/sisimai/mail/maildir.rb', line 11 def dir @dir end |
#file ⇒ Object
Returns the value of attribute file.
12 13 14 |
# File 'lib/sisimai/mail/maildir.rb', line 12 def file @file end |
#handle ⇒ Object
Returns the value of attribute handle.
12 13 14 |
# File 'lib/sisimai/mail/maildir.rb', line 12 def handle @handle end |
#offset ⇒ Object
Returns the value of attribute offset.
12 13 14 |
# File 'lib/sisimai/mail/maildir.rb', line 12 def offset @offset end |
#path ⇒ Object
Returns the value of attribute path.
12 13 14 |
# File 'lib/sisimai/mail/maildir.rb', line 12 def path @path end |
#size ⇒ Object
Returns the value of attribute size.
12 13 14 |
# File 'lib/sisimai/mail/maildir.rb', line 12 def size @size end |
Instance Method Details
#read ⇒ String
Maildir reader, works as an iterator.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/sisimai/mail/maildir.rb', line 32 def read return nil if self.offset >= self.size seekhandle = self.handle readbuffer = '' begin while r = seekhandle.read do # Read each file in the directory if r == '.' || r == '..' # Is a directory self.offset += 1 next end emailindir = (self.dir + '/' + r).squeeze('/') if File.ftype(emailindir) != 'file' || File.size(emailindir) == 0 || File.readable?(emailindir) == false # The file is not a file, is empty, is not readable self.offset += 1 next end File.open(emailindir, 'r:UTF-8') do |f| readbuffer = f.read end self.offset += 1 self.path = emailindir self.file = r break end seekhandle.close if self.offset >= self.size end return readbuffer end |