Module: BotHelpers::Helpers
- Defined in:
- lib/mail_runner/bot_helpers/helpers.rb
Constant Summary collapse
- REGEX_POSTFIX_MESSAGE_DELIMITER =
Based on Mbox protocol. maildir not yet supported. ? in ?.?[a-zA-Z]2,4 makes compatible with local mail and internal process logging. working test case: rubular.com/r/N5iHbxk1q1
/^From\W\b[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+?\.?[a-zA-Z]{2,4}\b\W{1,}[a-zA-Z]{3}\W{1,}\w{3}\W{1,}\d{1,2}\W\d{2}:\d{2}:\d{2}\W\d{4}\n/
Class Method Summary collapse
- .convert_raw_mail_to_json(mail) ⇒ Object
- .parse_attachments(attachments) ⇒ Object
- .parse_from(from) ⇒ Object
- .parse_header(header_contents) ⇒ Object
- .print_monitoring_started_msg(bot) ⇒ Object
Class Method Details
.convert_raw_mail_to_json(mail) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/mail_runner/bot_helpers/helpers.rb', line 20 def self.convert_raw_mail_to_json(mail) mail_array = [] header = parse_header(mail.header) from = parse_from(header[:From]) = (mail.) msg = { :raw_msg => mail.to_s, :headers => header, :from_email => from[1], :from_name => from[0], :to => header[:To], :email => header[:'X-Original-To'], :subject => header[:Subject], :tags => '', :sender => header[:Sender], :spam_report => 'spam report' } msg[:text] = mail.text_part.decoded unless mail.text_part.nil? msg[:html] = mail.html_part.decoded unless mail.html_part.nil? #omitted unless attachments msg[:attachments] = [:a_array] unless [:a_array].empty? msg[:images] = [:i_array] unless [:i_array].empty? hash = { :msg => msg } mail_array << hash return mail_array.to_json end |
.parse_attachments(attachments) ⇒ Object
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/mail_runner/bot_helpers/helpers.rb', line 77 def self.() a_array = [] i_array = [] .each do |att| disposition = att.content_disposition.split(/;/)[0] item = { :name => att.filename, :type => att.content_type.split(/;/)[0], :content => Base64.encode64(att.body.decoded), :base64 => true, :attachment_id => att.content_id } if disposition == 'inline' i_array << item else a_array << item end end return {:a_array => a_array, :i_array => i_array} end |
.parse_from(from) ⇒ Object
70 71 72 73 74 75 |
# File 'lib/mail_runner/bot_helpers/helpers.rb', line 70 def self.parse_from(from) from = from.split(/</) from[0] = from[0].strip from[1] = from[1].strip.gsub(/>/,'') return from end |
.parse_header(header_contents) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mail_runner/bot_helpers/helpers.rb', line 55 def self.parse_header(header_contents) hash = {} header = header_contents.to_s.split(/\r\n/) header.each do |h| parts = h.split(/:/, 2) unless parts[0].nil? or parts[1].nil? key = parts[0].strip.to_sym next if key =~ /Return-Path/i value = parts[1].strip hash[key] = parts[1].strip end end return hash end |
.print_monitoring_started_msg(bot) ⇒ Object
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/mail_runner/bot_helpers/helpers.rb', line 7 def self.print_monitoring_started_msg(bot) $logger.info("Helpers") { "mailbox: #{bot.mailbox}" } $logger.info("Helpers") { "path: #{bot.webhook}"} unless bot.archive.nil? if bot.archive[:destination] == 'cloud' $logger.info("Helpers") {"archive: #{bot.archive[:provider]} :: #{bot.archive[:directory]}"} else $logger.info("Helpers") {"archive: #{bot.archive[:destination]} :: #{bot.archive[:local_archive]}"} end end puts "Getter Bot is on the Job!" end |