Module to extract the locations of various files from the
.procmailrc
file. Currently the spam file and the
procmail
log file are extracted.
The FileRegex
structure is passed to the extract method to
pull a file name from the .procmailrc
file.
:filetype
field contains a human-readable name of the file to
extract from the .procmailrc
file.
:regex
stores the regular expression to apply to the contents
of the .procmailrc
file to extract the desired filename.
:filename
stores the full pathname of the file once it has
been extracted.
Extract the name of the logfile from .procmailrc
# File buryspam.rb, line 3491 def logfile extract(LOGFILE) end
Extract the name of the spamfile from .procmailrc
# File buryspam.rb, line 3486 def spam_file extract(SPAMFILE) end
Extract a filename from the .procmailrc
file. Accepts a
FileRegex
parameter.
# File buryspam.rb, line 3499 def extract(filereg) # If the filename was extracted from a previous call, # then return it now. unless filereg.filename.nil? Logger.debug("Already extracted '#{filereg.filename}' from '#{RCFILE}'") return filereg.filename end procmailrc_contents = IO.binread(RCFILE) file = procmailrc_contents[filereg.regex, 1] if file.nil? raise "Cannot determine #{filereg.filetype} from '#{RCFILE}'" end file = file.strip.gsub(/^\$HOME/, "~") if [~~, //].include?(file[0]) file = File.expand_path(file) else # Assume file is relative to MAILDIR if its not absolute. file.gsub!(%r{^\$MAILDIR/}, "") maildir = procmailrc_contents[MAILDIR, 1] if maildir.nil? raise "Cannot determine mail directory from '#{RCFILE}'" end maildir = maildir.strip.gsub(/^\$HOME/, "~") file = File.expand_path(file, maildir) end Logger.debug("Extracted #{filereg.filetype} '#{file}' from '#{RCFILE}'") # Save the filename so we won't have to re-extract it if called again. filereg.filename = file file end