From ab16705f9b2e8b1d3b97d2878557063b00dca271 Mon Sep 17 00:00:00 2001 From: Eddie Prislac Date: Fri, 12 May 2023 17:26:03 -0500 Subject: [PATCH] hotfix(attachments):PAUB-3205 strict_encode, not encode --- lib/paubox/format_helper.rb | 4 ++-- lib/paubox/mail_to_message.rb | 3 ++- lib/paubox/message.rb | 4 ++-- lib/paubox/version.rb | 2 +- spec/helpers/mail_helper.rb | 2 +- spec/helpers/message_helper.rb | 4 ++-- 6 files changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/paubox/format_helper.rb b/lib/paubox/format_helper.rb index ea28126..243c89a 100644 --- a/lib/paubox/format_helper.rb +++ b/lib/paubox/format_helper.rb @@ -9,13 +9,13 @@ module FormatHelper def base64_encoded?(value) return false unless value.is_a?(String) - !value.strip.match(BASE64_REGEX).nil? + Base64.strict_encode64(Base64.decode64(value)) == value end def base64_encode_if_needed(str) return str if base64_encoded?(str.to_s) - Base64.encode64(str.to_s) + Base64.strict_encode64(str.to_s) end # Converts hash keys to strings and maps them to expected JSON key. diff --git a/lib/paubox/mail_to_message.rb b/lib/paubox/mail_to_message.rb index 25d48f5..81e796b 100644 --- a/lib/paubox/mail_to_message.rb +++ b/lib/paubox/mail_to_message.rb @@ -21,6 +21,7 @@ def send_message_payload private def build_attachments + puts 'MailToMessage build_attachments' attachments = mail.attachments return [] if attachments.empty? @@ -88,7 +89,7 @@ def convert_binary_to_base64(f) file = Tempfile.new(encoding: 'ascii-8bit') file.write(f) file.rewind - Base64.encode64(file.read) + Base64.strict_encode64(file.read.delete("\n")) end end end diff --git a/lib/paubox/message.rb b/lib/paubox/message.rb index 5f54c33..f62770a 100644 --- a/lib/paubox/message.rb +++ b/lib/paubox/message.rb @@ -29,7 +29,7 @@ def send_message_payload def add_attachment(file_path) @packaged_attachments << { filename: file_path.split('/').last, content_type: `file --b --mime-type #{file_path}`.chomp, - content: Base64.encode64(File.read(file_path)) } + content: Base64.strict_encode64(File.read(file_path)) } end def attachments @@ -46,7 +46,7 @@ def build_attachments(args) return (@packaged_attachments = []) if args.to_a.empty? args.each do |a| - a[:content] = base64_encode_if_needed(a[:content]) + a[:content] = base64_encode_if_needed(("#{a[:content]}").delete("\n")) @packaged_attachments << a end @packaged_attachments diff --git a/lib/paubox/version.rb b/lib/paubox/version.rb index 3a24ac5..2be4de6 100644 --- a/lib/paubox/version.rb +++ b/lib/paubox/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Paubox - VERSION = '0.3.2' + VERSION = '0.4.6' end diff --git a/spec/helpers/mail_helper.rb b/spec/helpers/mail_helper.rb index 79d925a..0187dcc 100644 --- a/spec/helpers/mail_helper.rb +++ b/spec/helpers/mail_helper.rb @@ -63,7 +63,7 @@ def message_with_attachments(args = {}) def base64_encode_if_needed(str) return str if base64_encoded?(str.to_s) - Base64.encode64(str.to_s) + Base64.strict_encode64(str.to_s) end end end diff --git a/spec/helpers/message_helper.rb b/spec/helpers/message_helper.rb index bd25a26..77989ed 100644 --- a/spec/helpers/message_helper.rb +++ b/spec/helpers/message_helper.rb @@ -55,13 +55,13 @@ def message_with_template_args(args = {}) def base64_encoded?(value) return false unless value.is_a?(String) - !value.strip.match(BASE64_REGEX).nil? + Base64.strict_encode64(Base64.decode64(value)) == value end def base64_encode_if_needed(str) return str if base64_encoded?(str.to_s) - Base64.encode64(str.to_s) + Base64.strict_encode64(str.to_s) end end end