    # File lib/rfilter/deliver.rb, line 63
        def deliver_mbox(filename, message)
          return filename if filename == '/dev/null'
          File.open(filename,
                    File::APPEND|File::WRONLY|File::CREAT|SYNC_IF_NO_FSYNC,
                    0600) { |f|
            max = 5
            max.times { |i|
              break if f.flock(File::LOCK_EX | File::LOCK_NB)
              raise LockingError, "Timeout locking mailbox." if i == max - 1
              sleep(1)
            }
            st = f.lstat
            unless st.file?
              raise NotAFile,
                "Can not deliver to #{filename}, not a regular file."
            end
            begin
              # Ignore SIGXFSZ, since we want to get the Errno::EFBIG
              # exception when the file is too big.
              old_handler = trap('XFSZ', 'IGNORE') || 'DEFAULT'
              write_to_mbox(f, message)
              begin
                f.fsync
              rescue NameError
                # NameError happens with older versions of Ruby that have
                # no File#fsync
                f.flush
              end
            rescue Exception => e
              begin
                begin
                  f.flush
                rescue Exception
                end
                f.truncate(st.size)
              ensure
                raise e
              end
            ensure
              if old_handler
                trap('XFSZ', old_handler)
              end
            end
            f.flock(File::LOCK_UN)
          }
          filename
        end