mirror of
https://github.com/discourse/discourse.git
synced 2025-05-22 22:43:33 +08:00
Support gzipped mailbox files
This commit is contained in:
@ -24,13 +24,30 @@ class ImportScripts::Mbox < ImportScripts::Base
|
|||||||
SQLite3::Database.new("#{MBOX_DIR}/index.db")
|
SQLite3::Database.new("#{MBOX_DIR}/index.db")
|
||||||
end
|
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
|
def all_messages
|
||||||
files = Dir["#{MBOX_DIR}/messages/*"]
|
files = Dir["#{MBOX_DIR}/messages/*"]
|
||||||
|
|
||||||
files.each_with_index do |f, idx|
|
files.each_with_index do |f, idx|
|
||||||
if SPLIT_AT.present?
|
if SPLIT_AT.present?
|
||||||
msg = ""
|
msg = ""
|
||||||
File.foreach(f).with_index do |line, line_num|
|
|
||||||
|
each_line(f) do |line|
|
||||||
line = line.scrub
|
line = line.scrub
|
||||||
if line =~ SPLIT_AT
|
if line =~ SPLIT_AT
|
||||||
if !msg.empty?
|
if !msg.empty?
|
||||||
|
Reference in New Issue
Block a user