Class: Eml2Html::Converter
- Inherits:
-
Object
- Object
- Eml2Html::Converter
- Defined in:
- lib/eml2html/converter.rb
Instance Method Summary collapse
- #attachment(file_name) ⇒ Object
- #attachments(include_in_doc = false) ⇒ Object
- #html_body ⇒ Object
-
#initialize(message) ⇒ Converter
constructor
A new instance of Converter.
- #save_files! ⇒ Object
- #save_html ⇒ Object
- #save_txt ⇒ Object
- #save_zip(options = {}) ⇒ Object
Constructor Details
#initialize(message) ⇒ Converter
Returns a new instance of Converter.
13 14 15 16 17 18 |
# File 'lib/eml2html/converter.rb', line 13 def initialize() @message = Mail.read() @basename = File.basename(, '.eml') @cids_in_body = [] end |
Instance Method Details
#attachment(file_name) ⇒ Object
73 74 75 76 77 78 79 80 |
# File 'lib/eml2html/converter.rb', line 73 def (file_name) do |name, content| if name == file_name return content end end nil end |
#attachments(include_in_doc = false) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/eml2html/converter.rb', line 59 def (include_in_doc=false) = [] if include_in_doc = @attachments else @attachments.each do |a| unless @cids_in_body.include?(a.cid) .push(a) end end end end |
#html_body ⇒ Object
82 83 84 |
# File 'lib/eml2html/converter.rb', line 82 def html_body replace_images_src(@message.html_part.body.to_s) end |
#save_files! ⇒ Object
20 21 22 23 24 |
# File 'lib/eml2html/converter.rb', line 20 def save_files! [:txt, :html, :zip].each do |ext| send(:"save_#{ext}") end end |
#save_html ⇒ Object
30 31 32 33 34 35 |
# File 'lib/eml2html/converter.rb', line 30 def save_html File.write(filename(:html), html_body) do |name, content| File.write(name, content) end end |
#save_txt ⇒ Object
26 27 28 |
# File 'lib/eml2html/converter.rb', line 26 def save_txt File.write(filename(:txt), text_body) end |
#save_zip(options = {}) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/eml2html/converter.rb', line 37 def save_zip( = {}) Zip::File.open(filename(:zip), Zip::File::CREATE) do |zipfile| if [:include_html] zipfile.get_output_stream(filename(:html)) do |out| out << html_body end end if [:include_text] zipfile.get_output_stream(filename(:txt)) do |out| out << text_body end end do |name, content| zipfile.get_output_stream(name) do |out| out << content end end end end |