Module: Maildir2Json
- Defined in:
- lib/maildir2json.rb
Overview
Maildir2Json is the main entry point of execution
Class Method Summary collapse
Class Method Details
.run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/maildir2json.rb', line 19 def self.run validate_params mail = Mail.read(@input_file) data = YAML.safe_load(mail.to_yaml, permitted_classes: [Symbol, Mail::SMTP, Mail::Body]) data = data.to_utf8 begin json = JSON.dump(data) rescue StandardError abort("\e[31mError converting maildir file #{INPUT_FILE}\e[0m") end File.write(@output_file, json) end |
.validate_params ⇒ Object
9 10 11 12 13 14 15 16 17 |
# File 'lib/maildir2json.rb', line 9 def self.validate_params abort("\e[31mYou need to provide absolute path to input file\e[0m") if ARGV.empty? abort("\e[31mYou need to provide absolute path to output file\e[0m") if ARGV.length < 2 @input_file = ARGV[0] @output_file = ARGV[1] abort("\e[31mThe input file you have specified does not exist!\e[0m") unless File.exist?(@input_file) end |