Class: TMail::UNIXMbox

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(fname, mhdir, readonly, static) ⇒ UNIXMbox

Returns a new instance of UNIXMbox.



156
157
158
159
160
161
162
163
164
165
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 156

def initialize( fname, mhdir, readonly, static )
  @filename = fname
  @readonly = readonly
  @closed = false

  Dir.mkdir mhdir
  @real = MhMailbox.new(mhdir)
  @finalizer = UNIXMbox.mkfinal(@real, @filename, !@readonly, !static)
  ObjectSpace.define_finalizer self, @finalizer
end

Class Method Details

.create_from_line(port) ⇒ Object

make _From line



190
191
192
193
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 190

def UNIXMbox.create_from_line( port )
  sprintf 'From %s %s',
          fromaddr(), TextUtils.time2str(File.mtime(port.filename))
end

.lock(fname) ⇒ Object



132
133
134
135
136
137
138
139
140
141
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 132

def UNIXMbox.lock( fname )
  begin
    f = File.open(fname)
    f.flock File::LOCK_EX
    yield f
  ensure
    f.flock File::LOCK_UN
    f.close if f and not f.closed?
  end
end

.mkfinal(mh, mboxfile, writeback_p, cleanup_p) ⇒ Object



167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 167

def UNIXMbox.mkfinal( mh, mboxfile, writeback_p, cleanup_p )
  lambda {
      if writeback_p
        lock(mboxfile) {|f|
            mh.each_port do |port|
              f.puts create_from_line(port)
              port.ropen {|r|
                  f.puts r.read
              }
            end
        }
      end
      if cleanup_p
        Dir.foreach(mh.dirname) do |fname|
          next if /\A\.\.?\z/ === fname
          File.unlink "#{mh.dirname}/#{fname}"
        end
        Dir.rmdir mh.dirname
      end
  }
end

.new(fname, tmpdir = nil, readonly = false) ⇒ Object



147
148
149
150
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 147

def UNIXMbox.new( fname, tmpdir = nil, readonly = false )
  tmpdir = ENV['TEMP'] || ENV['TMP'] || '/tmp'
  newobj(fname, "#{tmpdir}/ruby_tmail_#{$$}_#{rand()}", readonly, false)
end

.newobjObject



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

alias newobj new

.static_new(fname, dir, readonly = false) ⇒ Object



152
153
154
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 152

def UNIXMbox.static_new( fname, dir, readonly = false )
  newobj(fname, dir, readonly, true)
end

Instance Method Details

#closeObject



203
204
205
206
207
208
209
210
211
212
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 203

def close
  return if @closed

  ObjectSpace.undefine_finalizer self
  @finalizer.call
  @finalizer = nil
  @real = nil
  @closed = true
  @updated = nil
end

#each_new_port(mtime = nil) ⇒ Object Also known as: each_newmail

old #each_mail returns Port def each_mail( &block )

each_port do |port|
  yield Mail.new(port)
end

end



237
238
239
240
241
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 237

def each_new_port( mtime = nil )
  close_check
  update
  @real.each_new_port(mtime) {|p| yield p }
end

#each_port(&block) ⇒ Object Also known as: each, each_mail



214
215
216
217
218
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 214

def each_port( &block )
  close_check
  update
  @real.each_port(&block)
end

#new_portObject Also known as: new_mail



243
244
245
246
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 243

def new_port
  close_check
  @real.new_port
end

#reverse_each_port(&block) ⇒ Object Also known as: reverse_each



222
223
224
225
226
# File 'lib/action_mailer/vendor/tmail/mailbox.rb', line 222

def reverse_each_port( &block )
  close_check
  update
  @real.reverse_each_port(&block)
end