|
# File lib/rmail/parser/multipart.rb, line 68
def read_chunk_low(chunk_size)
if @pushback
return standard_read_chunk(chunk_size)
end
input_gave_nil = false
loop {
return nil if @eof || @delimiter
unless @chunks.empty?
chunk, @delimiter, @delimiter_is_last = @chunks.shift
return chunk
end
chunk = standard_read_chunk(chunk_size)
if chunk.nil?
input_gave_nil = true
end
if @caryover
if chunk
@caryover << chunk
end
chunk = @caryover
@caryover = nil
end
if chunk.nil?
@eof = true
return nil
elsif @in_epilogue
return chunk
end
start = 0
found_last_delimiter = false
while !found_last_delimiter and
(start < chunk.length) and
(found = chunk.index(@delimiter_re, start))
if $~[2] == '' and !input_gave_nil
break
end
delimiter = $~[0]
# check if delimiter had the trailing --
if $~.begin(1)
found_last_delimiter = true
end
temp = if found == start
nil
else
chunk[start, found - start]
end
@chunks << [ temp, delimiter, found_last_delimiter ]
start = $~.end(0)
end
chunk = chunk[start..-1] if start > 0
# If something that looks like a delimiter exists at the end
# of this chunk, refrain from returning it.
unless found_last_delimiter or input_gave_nil
start = chunk.rindex(/\n/) || 0
if chunk.index(@might_be_delimiter_re, start)
@caryover = chunk[start..-1]
chunk[start..-1] = ''
chunk = nil if chunk.length == 0
end
end
unless chunk.nil?
@chunks << [ chunk, nil, false ]
end
chunk, @delimiter, @delimiter_is_last = @chunks.shift
if chunk
return chunk
end
}
end
|