mirror of
https://github.com/discourse/discourse.git
synced 2024-11-22 14:03:22 +08:00
Support gzipped mailbox files
This commit is contained in:
parent
68c158d592
commit
2720205f78
|
@ -24,13 +24,30 @@ class ImportScripts::Mbox < ImportScripts::Base
|
|||
SQLite3::Database.new("#{MBOX_DIR}/index.db")
|
||||
end
|
||||
|
||||
def each_line(f)
|
||||
infile = File.open(f, 'r')
|
||||
if f.ends_with?('.gz')
|
||||
gz = Zlib::GzipReader.new(infile)
|
||||
gz.each_line do |line|
|
||||
yield line
|
||||
end
|
||||
else
|
||||
infile.each_line do |line|
|
||||
yield line
|
||||
end
|
||||
end
|
||||
ensure
|
||||
infile.close
|
||||
end
|
||||
|
||||
def all_messages
|
||||
files = Dir["#{MBOX_DIR}/messages/*"]
|
||||
|
||||
files.each_with_index do |f, idx|
|
||||
if SPLIT_AT.present?
|
||||
msg = ""
|
||||
File.foreach(f).with_index do |line, line_num|
|
||||
|
||||
each_line(f) do |line|
|
||||
line = line.scrub
|
||||
if line =~ SPLIT_AT
|
||||
if !msg.empty?
|
||||
|
|
Loading…
Reference in New Issue
Block a user