split off uudecode stuff
This commit is contained in:
parent
11363a35a2
commit
12dac93ea1
2 changed files with 20 additions and 182 deletions
|
|
@ -1,6 +1,6 @@
|
|||
#################################
|
||||
#
|
||||
# $Dwarf: article.rb,v 1.58 2002/11/05 09:33:41 ward Exp $
|
||||
# $Dwarf: article.rb,v 1.59 2002/11/05 10:29:51 ward Exp $
|
||||
# $Source$
|
||||
#
|
||||
# article.rb
|
||||
|
|
@ -529,177 +529,6 @@ end
|
|||
|
||||
#######################################################################
|
||||
|
||||
def uudecode(data, outfile=nil)
|
||||
case data.type.to_s
|
||||
when "Array"
|
||||
print "Calling _uudecode_array\n" if Debuglevel>0
|
||||
mode, filename, body = _uudecode_array(data)
|
||||
when "File", "Tempfile"
|
||||
unless outfile
|
||||
print "uudecode: need outfile\n"
|
||||
exit
|
||||
end
|
||||
print "Calling _uudecode_file\n" if Debuglevel>0
|
||||
mode, filename, body = _uudecode_file(data, outfile)
|
||||
else
|
||||
print "Funny stuff in uudecode. Data of type \"#{data.type.to_s}\"\n"
|
||||
end
|
||||
return mode, filename, body
|
||||
end
|
||||
|
||||
def _uudecode_file(file, outfile)
|
||||
mode = 0600
|
||||
filename = "unknown"
|
||||
c = 0
|
||||
lines = file.pos
|
||||
percent = 0
|
||||
mark = lines/100
|
||||
file.pos=0
|
||||
|
||||
while (! file.eof)
|
||||
line = file.gets
|
||||
print "line: #{line}" if Debuglevel > 0
|
||||
if line =~ /^begin(.*)/
|
||||
m = $1
|
||||
print "beginning matched; rest: #{m}\n" if Debuglevel > 0
|
||||
if m =~ /^(\s+(\d+))?(\s+(.*?\S))?\s*\Z/
|
||||
mode = $2
|
||||
filename = $4
|
||||
print "found beginning\n" if Debuglevel > 0
|
||||
else
|
||||
print "mode, file set to defaults: #{m}\n"
|
||||
end
|
||||
break
|
||||
end
|
||||
end
|
||||
|
||||
if file.eof
|
||||
print "Not UUencoded!\n"
|
||||
return false
|
||||
end
|
||||
print "c: #{c} mark: #{mark} lines: #{lines}\n" if Debuglevel > 1
|
||||
|
||||
print " UUdecoding...\n"
|
||||
|
||||
while (! file.eof)
|
||||
if Debuglevel > 1
|
||||
c = file.pos
|
||||
if c > mark
|
||||
print "#{percent}%\n"
|
||||
print "c: #{c} mark: #{mark} lines: #{lines}\n" if Debuglevel > 1
|
||||
percent += 1
|
||||
mark = (lines/100)*(percent+1)
|
||||
end
|
||||
end
|
||||
line = file.gets
|
||||
print "line: #{line}" if Debuglevel > 1
|
||||
return mode, filename if line =~ /^end/
|
||||
next if line =~ /[a-z]/
|
||||
next if line == nil
|
||||
next unless ((((line[0] - 32) & 077) + 2) / 3).to_i ==
|
||||
(line.length/4).to_i
|
||||
outfile.print line.unpack("u")
|
||||
end
|
||||
|
||||
print "No \"end\" found!!!\n"
|
||||
#return mode, file, outfile
|
||||
return false
|
||||
end
|
||||
|
||||
# gaat volgens mij niet verder als er meerdere uuencoded blocks zijn...
|
||||
# zal dan meerdere keren aangeroepen moeten worden, grmbl...
|
||||
# tis getting a mess as we speak...
|
||||
# toch maar een keer aparte class van maken...
|
||||
def _uudecode_array(data)
|
||||
decode = []
|
||||
mode = 0600
|
||||
filename = "unknown"
|
||||
c = 0
|
||||
lines = data.length
|
||||
percent = 0
|
||||
mark = lines/100
|
||||
|
||||
i = 0
|
||||
while (i < data.length)
|
||||
if data[i] =~ /^begin(.*)/
|
||||
m = $1
|
||||
print "beginning matched; rest: #{m}\n" if Debuglevel > 0
|
||||
if m =~ /^(\s+(\d+))?(\s+(.*?\S))?\s*\Z/
|
||||
mode = $2
|
||||
filename = $4
|
||||
print "found beginning\n" if Debuglevel > 0
|
||||
else
|
||||
print "mode, filename set to defaults: #{m}\n"
|
||||
end
|
||||
break
|
||||
end
|
||||
i += 1
|
||||
end
|
||||
|
||||
unless (i < data.length)
|
||||
print "Not UUencoded!\n"
|
||||
return false
|
||||
end
|
||||
|
||||
print "UUdecoding...\n"
|
||||
|
||||
while (i < data.length)
|
||||
if Debuglevel > 1
|
||||
if c > mark
|
||||
print "#{percent}%\n"
|
||||
print "c: #{c} mark: #{mark} lines: #{lines} i: #{i}\n" if Debuglevel > 1
|
||||
percent += 1
|
||||
mark = (lines/100)*(percent+1)
|
||||
end
|
||||
c += 1
|
||||
end
|
||||
line = data[i]
|
||||
i += 1
|
||||
return mode, filename, decode if line =~ /^end/
|
||||
next if line =~ /[a-z]/
|
||||
next if line == nil
|
||||
next unless ((((line[0] - 32) & 077) + 2) / 3).to_i ==
|
||||
(line.length/4).to_i
|
||||
decode.concat(line.unpack("u"))
|
||||
end
|
||||
|
||||
print "No \"end\" found!!!\n"
|
||||
return false
|
||||
end
|
||||
|
||||
#def uudecode_group(subj, file=nil, outfile=nil)
|
||||
def uudecode_group(subj, tempdir=nil)
|
||||
group_subjects unless @grouped
|
||||
|
||||
body = get_group_body_first(subj)
|
||||
if body.to_s =~ /begin/
|
||||
print "uuencoded!\n" if Debuglevel > 0
|
||||
if (tempdir != nil)
|
||||
file = Tempfile.new("#{tempdir}/riptmp")
|
||||
body.collect{|i| file.print "#{i}\n"}
|
||||
get_group_body_rest(subj, file)
|
||||
mode, filename, result = uudecode(file, outfile)
|
||||
else
|
||||
body.concat(get_group_body_rest(subj))
|
||||
mode, filename, result = uudecode(body)
|
||||
end
|
||||
return mode, filename, result
|
||||
else
|
||||
print "Not uuencoded!\n" if Debuglevel > 0
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
def is_uuencoded(data)
|
||||
if data.to_s =~ /begin\s+\d+?\s+.*?\S?\s*\Z/
|
||||
return true
|
||||
else
|
||||
return false
|
||||
end
|
||||
end
|
||||
|
||||
#######################################################################
|
||||
|
||||
def ydecode(data, outfile=nil)
|
||||
if @ymap.empty?
|
||||
(-106..255).each do |b|
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#!/usr/local/bin/ruby -w
|
||||
|
||||
# $Dwarf: ripnews.rb,v 1.44 2003/04/19 11:10:32 ward Exp $
|
||||
# $Dwarf: ripnews.rb,v 1.45 2003/04/19 12:42:12 ward Exp $
|
||||
# $Source$
|
||||
|
||||
require 'date'
|
||||
|
|
@ -8,6 +8,7 @@ require 'getoptlong'
|
|||
require 'news/article'
|
||||
require 'news/newsrc'
|
||||
require 'tempfile'
|
||||
require 'encode/uuencode'
|
||||
|
||||
|
||||
###########################################################################
|
||||
|
|
@ -224,15 +225,17 @@ end
|
|||
def get_single(subj, group)
|
||||
print "Fetching singlepart article: #{subj}\n"
|
||||
body = @articles.get_group_body(subj)
|
||||
if @articles.is_uuencoded(body)
|
||||
mode, filename, body = @articles.uudecode(body)
|
||||
if UUEncode.is_uuencoded(body)
|
||||
filename = UUEncode.get_filename(body)
|
||||
return false unless check_ext(group, filename, "s")
|
||||
mode, filename, body = UUEncode.uudecode(body)
|
||||
elsif @articles.is_yencoded(body)
|
||||
mode, filename, body = @articles.ydecode(body)
|
||||
return false unless check_ext(group, filename, "s")
|
||||
else
|
||||
print " Unknown encoding (not UU, not yEnc), skipping...\n"
|
||||
return false
|
||||
end
|
||||
return false unless check_ext(group, filename, "s")
|
||||
return mode, filename, body
|
||||
end
|
||||
|
||||
|
|
@ -240,26 +243,32 @@ def get_multi(subj, group)
|
|||
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)
|
||||
if UUEncode.is_uuencoded(body)
|
||||
filename = UUEncode.get_filename(body)
|
||||
return false unless check_ext(group, filename, "m")
|
||||
mode, filename, body = UUEncode.uudecode(body)
|
||||
elsif @articles.is_yencoded(body)
|
||||
mode, filename, body = @articles.ydecode(body)
|
||||
return false unless check_ext(group, filename, "m")
|
||||
else
|
||||
print " Unknown encoding (not UU, not yEnc), skipping...\n"
|
||||
return false
|
||||
end
|
||||
return false unless check_ext(group, filename, "m")
|
||||
return mode, filename, body
|
||||
else
|
||||
body = @articles.get_group_body_first(subj)
|
||||
if @articles.is_uuencoded(body) or @articles.is_yencoded(body)
|
||||
if UUEncode.is_uuencoded(body) or @articles.is_yencoded(body)
|
||||
if UUEncode.is_uuencoded(body)
|
||||
filename = UUEncode.get_filename(body)
|
||||
return false unless check_ext(group, filename, "m")
|
||||
end
|
||||
file = Tempfile.new("riptmp", @config[group]["TEMPDIR"])
|
||||
body.collect{|x| file.print "#{x}\n"}
|
||||
# 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)
|
||||
mode, filename, body = @articles.uudecode(file, fileout)
|
||||
if UUEncode.is_uuencoded(body)
|
||||
mode, filename, body = UUEncode.uudecode(file, fileout)
|
||||
elsif @articles.is_yencoded(body)
|
||||
mode, filename, body = @articles.ydecode(file, fileout)
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue