Skip to content

Commit

Permalink
HTML部分はBase64エンコードしないようにした
Browse files Browse the repository at this point in the history
  • Loading branch information
takuya committed Jul 15, 2011
1 parent f555356 commit 4b8ccfd
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/mht.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# encoding: utf-8
# generate mhtml file
# == uri target uri
# return mhtml file
Expand All @@ -18,6 +19,7 @@ module MHT
#mhtml = MHT::MhtmlGenerator.generate("https://rubygems.org/")
#open("output.mht", "w+"){|f| f.write mhtml }
class MhtmlGenerator
attr_accessor :conf
def MhtmlGenerator.generate(uri)
generateror = MhtmlGenerator.new
return generateror.convert(uri)
Expand All @@ -26,8 +28,9 @@ def initialize
@contents = {}
@src = StringIO.new
@boundary = "mimepart_#{Digest::MD5.hexdigest(Time.now.to_s)}"
@threads =[]
@queue = Queue.new
@threads = []
@queue = Queue.new
@conf = { :base64_except=>["html"]}
end
def convert(filename_or_uri)
f = open(filename_or_uri)
Expand Down Expand Up @@ -71,11 +74,12 @@ def convert(filename_or_uri)
@src.puts "Content-Type: #{f.meta['content-type']}"
@src.puts "Content-Id: #{Digest::MD5.hexdigest(filename_or_uri)}"
@src.puts "Content-Location: #{filename_or_uri}"
#@src.puts "Content-Transfer-Encoding: 8bit"
@src.puts "Content-Transfer-Encoding: Base64"
@src.puts "Content-Transfer-Encoding: 8bit" if @conf[:base64_except].find("html")
@src.puts "Content-Transfer-Encoding: Base64" unless @conf[:base64_except].find("html")
@src.puts ""
#@src.puts html
@src.puts "#{Base64.encode64(html)}"
@src.puts "#{html}" if @conf[:base64_except].find("html")
#@src.puts "#{Base64.encode64(html)}" unless @conf[:base64_except].find("html")
@src.puts ""
self.attach_contents
@src.puts "--#{@boundary}--"
Expand Down Expand Up @@ -106,7 +110,7 @@ def attach_contents
@contents.each{|k,v| @queue.push k}
#start download threads
self.start_download_thread
# wait
# wait until download finished.
@threads.each{|t|t.join}
@contents.each{|k,v|self.add_html_content(k)}
end
Expand Down

0 comments on commit 4b8ccfd

Please sign in to comment.