class Buryspam::Spam

A class containing methods that are pertinent to a spam file. Note that while a spam file is an mbox, we don't derive from the Mbox class because almost none of the methods in Mbox are used for a spam mbox. Also, because there is only one (active) spam file, this class is a singleton.

Attributes

file[RW]

Public Class Methods

move_missed_spam_file() click to toggle source

Move the configured missed-spam mbox to the first configured spam directory.

# File buryspam.rb, line 3980
def self.move_missed_spam_file
  Logger.debug("Moving missed spam file to spam directory.")
  missed_spam_file = Config.missed_spam_file
  missed_spam_base = Config.missed_spam_base
  if missed_spam_file.nil? || missed_spam_file.empty? ||
     missed_spam_base.nil? || missed_spam_base.empty?
    Logger.debug {
      "'missed_spam_file' and/or 'missed_spam_base' parameter not set."
    }
    return
  end
  if !File.file?(missed_spam_file) || File.size(missed_spam_file).zero?
    Logger.debug("File '#{missed_spam_file}' not found or empty.")
    return
  end
  new_filename = File.join(Config.bad_dirs.first,
                           File.basename(missed_spam_base)) +
                 "-" + Time.now.strftime("%Y-%m-%d")
  FileUtils.rename_file_uniq(missed_spam_file, new_filename)
end
new() click to toggle source

The default spam mbox used to store spam retreived from the IMAP server will be the spam file specified in the ~/.procmailrc. This may be changed later by MUN_IMAP#use_procmail? if procmail is not on the system.

# File buryspam.rb, line 3955
def initialize
  @file = Procmail.spam_file rescue nil
end

Public Instance Methods

rotate(size) click to toggle source

Rotate (i.e., rename) the spam file only if we are receiving new messages and adding the given message size to the spam file would cause it to exceed the maximum configured size.

# File buryspam.rb, line 3962
def rotate(size)
  Logger.debug("Testing spam rotation...")
  unless Startup.new_messages?
    Logger.debug("Messages are not new.  No rotation.")
    return
  end

  if Mbox.is_valid?(@file)
    Mbox.rotate(@file, size, Config.spam_file_size)
  else
    # If the spam file is not valid, don't treat it as an error.
    # (it may not have been created yet).
    Logger.warn("Not a valid mbox: '#{@file}'.")
  end
end