some cleaning

This commit is contained in:
Ward Wouts 2002-05-18 23:12:59 +00:00
parent af0eb1f1c7
commit 666291155c

View file

@ -53,12 +53,14 @@ def save_file(dir, name, data)
return true
end
# meuh, dit werkt nu niet :( mag dit wel in een def staan?
def parse_options(options)
begin
opts = GetoptLong.new(
[ "-I", "--include", GetoptLong::REQUIRED_ARGUMENT ],
[ "-c", "--configfile", GetoptLong::REQUIRED_ARGUMENT ],
[ "-L", "--longname", GetoptLong::NO_ARGUMENT ],
[ "-C", "--combinedname", GetoptLong::NO_ARGUMENT ],
[ "-M", "--multipart", GetoptLong::NO_ARGUMENT ],
[ "-S", "--singlepart", GetoptLong::NO_ARGUMENT ],
[ "-T", "--test", GetoptLong::NO_ARGUMENT ],
@ -70,12 +72,13 @@ def parse_options(options)
opts.each do |opt, arg|
options[opt] = arg
end
rescue
print "#{opts.error_message}\n"
print "\nUsage:\n"
exit
end
print opts.error_message
print "Remaining args: #{ARGV.join(', ')}\n"
return options
end
@ -176,22 +179,14 @@ def check_config
print "No inclusions given for group #{i}. Won't match anything.\n"
exit
end
unless @config[i].has_key?("DATADIR")
@config[i]["DATADIR"] ="."
end
unless @config[i].has_key?("PERMISSION")
@config[i]["PERMISSION"] = "0755"
end
@config[i]["DATADIR"] ="." unless @config[i].has_key?("DATADIR")
@config[i]["PERMISSION"] = "0755" unless @config[i].has_key?("PERMISSION")
if @config[i].has_key?("EXTENSIONS")
@config[i]["-S"] = @config[i]["EXTENSIONS"]
@config[i]["-M"] = @config[i]["EXTENSIONS"]
end
if @config[i].has_key?("-S") and ! @config[i].has_key?("-M")
@config[i]["-M"] = "(?!.*)"
end
if @config[i].has_key?("-M") and ! @config[i].has_key?("-S")
@config[i]["-S"] = "(?!.*)"
end
@config[i]["-M"] = "(?!.*)" if @config[i].has_key?("-S") and ! @config[i].has_key?("-M")
@config[i]["-S"] = "(?!.*)" if @config[i].has_key?("-M") and ! @config[i].has_key?("-S")
}
end
@ -220,8 +215,7 @@ def get_multi(subj, group)
mode, filename, body = @articles.uudecode(body)
return false unless check_ext(filename, "m")
return mode, filename, body
end
if @articles.is_yencoded(body)
elsif @articles.is_yencoded(body)
mode, filename, body = @articles.ydecode(body)
return false unless check_ext(filename, "m")
return mode, filename, body
@ -231,33 +225,26 @@ def get_multi(subj, group)
else
body = @articles.get_group_body_first(subj)
return false if body == false
if @articles.is_uuencoded(body) or @articles.is_yencoded(body)
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
body.collect{|x| file.print "#{x}\n"}
return false unless @articles.get_group_body_rest(subj, file)
fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
if @articles.is_uuencoded(body)
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
body.collect{|x| file.print "#{x}\n"}
return false unless @articles.get_group_body_rest(subj, file)
fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
mode, filename, body = @articles.uudecode(file, fileout)
return false unless check_ext(filename, "m")
body = fileout.path
file.close
fileout.close
return mode, filename, body
end
if @articles.is_yencoded(body)
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
body.collect{|x| file.print "#{x}\n"}
return false unless @articles.get_group_body_rest(subj, file)
fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
elsif @articles.is_yencoded(body)
mode, filename, body = @articles.ydecode(file, fileout)
end
return false unless check_ext(filename, "m")
body = fileout.path
file.close
fileout.close
return mode, filename, body
end
else
print " Unknown encoding (not UU, not yEnc), skipping...\n"
return false
end
end
end
def output_data(subject, mode, filename="", body="")
@ -267,17 +254,18 @@ def output_data(subject, mode, filename="", body="")
print " Filename: '#{filename}'\n" if Debuglevel > 0
if @config[group].has_key?("-L") and @config[group]["-L"]
print "longname\n" if Debuglevel > 1
if save_file("#{@config[group]["DATADIR"]}/#{group}", subject, body)
@articles.group_update_newsrc(subject)
@articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"]
end
outfile = subject
elsif @config[group].has_key?("-C") and @config[group]["-C"]
print "combinedname\n" if Debuglevel > 1
outfile = "#{subject} [#{filename}]"
else
print "shortname\n" if Debuglevel > 1
if save_file("#{@config[group]["DATADIR"]}/#{group}", filename, body)
outfile = filename
end
if save_file("#{@config[group]["DATADIR"]}/#{group}", outfile, body)
@articles.group_update_newsrc(subject)
@articles.save_newsrc unless @config[group].has_key?("-T") and @config[group]["-T"]
end
end
else
return false
end
@ -287,17 +275,9 @@ end
def check_ext(filename, mode)
case mode
when "s"
if @config.has_key?("-S")
return filename =~ /\.(#{@config["-S"]})$/
else
return true
end
return @config.has_key?("-S") ? filename =~ /\.(#{@config["-S"]})$/ : true
when "m"
if @config.has_key?("-M")
return filename =~ /\.(#{@config["-M"]})$/
else
return true
end
return @config.has_key?("-M") ? filename =~ /\.(#{@config["-M"]})$/ : true
else
print "Illegal mode \"#{mode}\" in check_ext\n"
exit