match on extensions, introduces -S (OPT_S), -M (OPT_M) and EXTENSIONS options

This commit is contained in:
Ward Wouts 2002-05-07 18:34:01 +00:00
parent f16a41ce2e
commit fd2066948a

View file

@ -182,37 +182,51 @@ def check_config
unless @config[i].has_key?("PERMISSION")
@config[i]["PERMISSION"] = "0755"
end
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
}
end
def get_single(subj)
print " Singlepart!\n"
print " Fetching singlepart article: #{subj}\n"
body = @articles.get_group_body(subj)
if @articles.is_uuencoded(body)
mode, filename, body = @articles.uudecode(body)
return false unless check_ext(filename, "s")
return mode, filename, body
end
if @articles.is_yencoded(body)
mode, filename, body = @articles.ydecode(body)
return false unless check_ext(filename, "s")
return mode, filename, body
end
print "unknown encoding (not UU, not yEnc), skipping...\n"
print " Unknown encoding (not UU, not yEnc), skipping...\n"
return false
end
def get_multi(subj, group)
print " Multipart!\n"
print " Fetching multipart article: #{subj}\n"
if @config[group]["TEMPDIR"] == nil or @config[group]["TEMPDIR"] == ""
body = @articles.get_group_body(subj)
if @articles.is_uuencoded(body)
mode, filename, body = @articles.uudecode(body)
return false unless check_ext(filename, "m")
return mode, filename, body
end
if @articles.is_yencoded(body)
mode, filename, body = @articles.ydecode(body)
return false unless check_ext(filename, "m")
return mode, filename, body
end
print "unknown encoding (not UU, not yEnc), skipping...\n"
print " Unknown encoding (not UU, not yEnc), skipping...\n"
return false
else
body = @articles.get_group_body_first(subj)
@ -223,6 +237,7 @@ def get_multi(subj, group)
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
@ -234,6 +249,7 @@ def get_multi(subj, group)
return false unless @articles.get_group_body_rest(subj, file)
fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
mode, filename, body = @articles.ydecode(file, fileout)
return false unless check_ext(filename, "m")
body = fileout.path
file.close
fileout.close
@ -268,6 +284,26 @@ def output_data(subject, mode, filename="", body="")
return true
end
def check_ext(filename, mode)
case mode
when "s"
if @config.has_key?("-S")
return filename =~ /\.(#{@config["-S"]})$/
else
return true
end
when "m"
if @config.has_key?("-M")
return filename =~ /\.(#{@config["-M"]})$/
else
return true
end
else
print "Illegal mode \"#{mode}\" in check_ext\n"
exit
end
end
#############################################################################################
defaults = {'-c' => "#{ENV['HOME']}/.ripnewsrc"}
@ -300,7 +336,6 @@ for group in @config.keys.sort
i =~ /#{@config[group]["-I"]}/
print "Match: #{i}\n" if Debuglevel > 0
if @articles.group_is_complete(i)
print " Fetching: #{i}\n"
if @articles.group_is_singlepart(i)
mode, filename, body = get_single(i)
elsif @articles.group_is_multipart(i)