code cleaning
This commit is contained in:
parent
7c354b7ba7
commit
256e5692b3
1 changed files with 35 additions and 47 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/local/bin/ruby -w
|
||||
|
||||
# $Dwarf: ripnews.rb,v 1.41 2003/04/18 21:06:51 ward Exp $
|
||||
# $Dwarf: ripnews.rb,v 1.42 2003/04/18 21:39:29 ward Exp $
|
||||
# $Source$
|
||||
|
||||
require 'date'
|
||||
|
|
@ -17,10 +17,9 @@ Debuglevel = 0
|
|||
def save_file(dir, name, data)
|
||||
print "savename: #{name}\n" if Debuglevel > 1
|
||||
nname = name.gsub(/\//, "-")
|
||||
print "nname: #{nname}\n" if Debuglevel > 1
|
||||
nname.sub!(/\s*$/, "")
|
||||
nname.sub!(/^\s*/, "")
|
||||
nname.sub!(/^\.*/, "")
|
||||
nname.sub!(/^[\s\.]*/, "")
|
||||
print "nname: #{nname}\n" if Debuglevel > 1
|
||||
newname = nname
|
||||
count = 1
|
||||
d = Date.today
|
||||
|
|
@ -227,16 +226,14 @@ def get_single(subj, group)
|
|||
body = @articles.get_group_body(subj)
|
||||
if @articles.is_uuencoded(body)
|
||||
mode, filename, body = @articles.uudecode(body)
|
||||
return false unless check_ext(group, filename, "s")
|
||||
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(group, filename, "s")
|
||||
return mode, filename, body
|
||||
else
|
||||
print " Unknown encoding (not UU, not yEnc), skipping...\n"
|
||||
return false
|
||||
end
|
||||
print " Unknown encoding (not UU, not yEnc), skipping...\n"
|
||||
return false
|
||||
return false unless check_ext(group, filename, "s")
|
||||
return mode, filename, body
|
||||
end
|
||||
|
||||
def get_multi(subj, group)
|
||||
|
|
@ -245,23 +242,21 @@ def get_multi(subj, group)
|
|||
body = @articles.get_group_body(subj)
|
||||
if @articles.is_uuencoded(body)
|
||||
mode, filename, body = @articles.uudecode(body)
|
||||
return false unless check_ext(group, filename, "m")
|
||||
print " should have a match here else something's wrong\n"
|
||||
return mode, filename, body
|
||||
elsif @articles.is_yencoded(body)
|
||||
mode, filename, body = @articles.ydecode(body)
|
||||
return false unless check_ext(group, filename, "m")
|
||||
print " should have a match here else something's wrong\n"
|
||||
return mode, filename, body
|
||||
else
|
||||
print " Unknown encoding (not UU, not yEnc), skipping...\n"
|
||||
return false
|
||||
end
|
||||
print " Unknown encoding (not UU, not yEnc), skipping...\n"
|
||||
return false
|
||||
return false unless check_ext(group, filename, "m")
|
||||
print " should have a match here else something's wrong\n"
|
||||
return mode, filename, body
|
||||
else
|
||||
body = @articles.get_group_body_first(subj)
|
||||
if @articles.is_uuencoded(body) or @articles.is_yencoded(body)
|
||||
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
|
||||
body.collect{|x| file.print "#{x}\n"}
|
||||
# hire moet een extensie check!!!
|
||||
# hier moet een extensie check!!!
|
||||
return false unless @articles.get_group_body_rest(subj, file)
|
||||
fileout = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
|
||||
if @articles.is_uuencoded(body)
|
||||
|
|
@ -292,28 +287,23 @@ def output_data(subject, mode, filename="", body="")
|
|||
print " Filename: '#{filename}'\n" if Debuglevel > 0
|
||||
|
||||
# de-crap subject...
|
||||
subject.sub!(/\s*$/, "")
|
||||
subject.sub!(/^[\s\.!-]*/, "")
|
||||
sub = subject.sub(/\s*$/, "") # strip trailing spaces
|
||||
sub.sub!(/^[\s\.!-]*/, "") # strip leading spaces, dots, exclamation points and dashes
|
||||
|
||||
# decide on a filename
|
||||
if @config[group].has_key?("-L") and @config[group]["-L"]
|
||||
print "longname\n" if Debuglevel > 1
|
||||
outfile = subject
|
||||
outfile = outfile[0...@maxfilelength]
|
||||
outfile = sub[0...@maxfilelength]
|
||||
elsif @config[group].has_key?("-C") and @config[group]["-C"]
|
||||
print "combinedname\n" if Debuglevel > 1
|
||||
outfile = outfile[0...@maxfilelength-filename.length-3]
|
||||
outfile = "#{subject} [#{filename}]"
|
||||
outfile = sub[0...@maxfilelength-filename.length-3]
|
||||
outfile = "#{outfile} [#{filename}]"
|
||||
if outfile.length > @maxfilelength
|
||||
outfile = filename
|
||||
outfile = outfile[0...@maxfilelength]
|
||||
outfile = filename[0...@maxfilelength]
|
||||
end
|
||||
else
|
||||
print "shortname\n" if Debuglevel > 1
|
||||
outfile = filename
|
||||
while outfile.length > @maxfilelength
|
||||
outfile = outfile[0...-1]
|
||||
end
|
||||
outfile = filename[0...@maxfilelength]
|
||||
end
|
||||
|
||||
# do the actual saving
|
||||
|
|
@ -353,20 +343,18 @@ def check_ext(group, filename, mode)
|
|||
end
|
||||
|
||||
def get_max_file_length(tempdir=".")
|
||||
i = 500
|
||||
name = "a"*i
|
||||
begin
|
||||
file = File.new("#{tempdir}/#{name}", "w", "0644").close
|
||||
File.delete("#{tempdir}/#{name}")
|
||||
rescue Errno::ENAMETOOLONG
|
||||
i -= 1
|
||||
name = "a"*i
|
||||
retry
|
||||
end
|
||||
i -= 14 # this is how many characters are still likely to be appended
|
||||
# is the filename already exists '-<#{date}.#{count}>' in save_file
|
||||
# this could be brought back to 5 '-<#{count}>' ...
|
||||
return i
|
||||
name = "a"*500
|
||||
begin
|
||||
file = File.new("#{tempdir}/#{name}", "w", "0644").close
|
||||
File.delete("#{tempdir}/#{name}")
|
||||
rescue Errno::ENAMETOOLONG
|
||||
name = name[0...-1]
|
||||
retry
|
||||
end
|
||||
# this is how many characters are still likely to be appended
|
||||
# is the filename already exists '-<#{date}.#{count}>' in save_file
|
||||
# this could be brought back to 5 '-<#{count}>' ...
|
||||
return name.length - 14
|
||||
end
|
||||
|
||||
#############################################################################################
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue