[why] the http protocol will parse in fail if the request data has special characters. or it's hard to analysis the data if encoded or not on the send mail service. add stand alone interface for it
Signed-off-by: Luan Shengde shdluan@163.com --- lib/mail-post.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
diff --git a/lib/mail-post.rb b/lib/mail-post.rb index df4d255..ac455fa 100644 --- a/lib/mail-post.rb +++ b/lib/mail-post.rb @@ -8,6 +8,7 @@ require 'json' require 'yaml' require 'open3' require 'mail' +require 'base64'
set :bind, '0.0.0.0' set :port, ENV['SEND_MAIL_PORT'] @@ -37,6 +38,19 @@ post '/send_mail_text' do send_mail(mail_info) end
+post '/send_mail_encode' do + data_decode = Base64.decode64(request.body.read) + data = Mail.read_from_string(data_decode) + + mail_info = { + 'subject' => data.subject, + 'to' => data.to, + 'body' => data.body.decoded + } + + send_mail(mail_info) +end + def check_send_mail(mail_info) raise 'no/empty subject.' if mail_info['subject'].nil? || mail_info['subject'].empty? raise 'no/empty email_to address.' if mail_info['to'].nil? || mail_info['to'].empty?