get request for send internet mail analysis email data invoke send-internet-mail to send the mail
Signed-off-by: Luan Shengde luanshengde2@huawei.com --- lib/mail-post.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 lib/mail-post.rb
diff --git a/lib/mail-post.rb b/lib/mail-post.rb new file mode 100755 index 0000000..ea8bf56 --- /dev/null +++ b/lib/mail-post.rb @@ -0,0 +1,50 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true + +require 'sinatra' +require 'json' +require 'yaml' +require 'open3' +require_relative "#{ENV['CCI_SRC']}/container/send-internet-mail/send-internet-mail.rb" + +set :bind, '0.0.0.0' +set :port, 11312 + +post '/send_mail_yaml' do + data = YAML.safe_load request.body.read + raise TypeError, data, 'request data type error' unless data.class.eql? Hash + + mail_info = { + 'references' => data['references'], + 'from' => data['from'], + 'subject' => data['subject'] || nil, + 'to' => data['to'] || nil, + 'body' => data['body'] || nil + } + check_send_mail(mail_info) +end + +post '/send_mail_text' do + data = Mail.read_from_string(request.body.read) + + mail_info = { + 'references' => data.references, + 'from' => data.from, + 'subject' => data.subject || nil, + 'to' => data.to || nil, + 'body' => data.body.decoded || nil + } + check_send_mail(mail_info) +end + +def check_send_mail(mail_info) + raise 'empty subject.' if mail_info['subject'].nil? + raise 'empty email address.' if mail_info['to'].nil? + raise 'empty email content.' if mail_info['body'].nil? + + puts ENV['EMAIL_ADDRESS'] + puts ENV['EMAIL_PASSWORD'] + send_mail(mail_info) +end
On Tue, Oct 20, 2020 at 04:51:00PM +0800, Wu Fengguang wrote:
- puts ENV['EMAIL_ADDRESS']
- puts ENV['EMAIL_PASSWORD']
EMAIL_ADDRESS 名字还没改掉啊!
这个是放在全局配置文件里的。 在那个上下文下,谁知道EMAIL_ADDRESS是干嘛的?
你们就这么一而再的忽略review意见?!
this email address is the compass-ci@qq.com, need to change it to my_email?
Thanks Luan Shengde
On Tue, Oct 20, 2020 at 05:00:15PM +0800, Luan Shengde wrote:
On Tue, Oct 20, 2020 at 04:51:00PM +0800, Wu Fengguang wrote:
- puts ENV['EMAIL_ADDRESS']
- puts ENV['EMAIL_PASSWORD']
EMAIL_ADDRESS 名字还没改掉啊!
这个是放在全局配置文件里的。 在那个上下文下,谁知道EMAIL_ADDRESS是干嘛的?
你们就这么一而再的忽略review意见?!
this email address is the compass-ci@qq.com, need to change it to my_email?
Please rename the global EMAIL_ADDRESS to some more descriptive and un-ambiguous name.
It's not my_email.
Thanks, Fengguang
On Tue, Oct 20, 2020 at 04:39:34PM +0800, Luan Shengde wrote:
get request for send internet mail analysis email data invoke send-internet-mail to send the mail
Changelog can modify as follow style: [Why] xxx
[How] xxx
-------- Thanks Yu Chuan
Signed-off-by: Luan Shengde luanshengde2@huawei.com
lib/mail-post.rb | 50 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100755 lib/mail-post.rb
diff --git a/lib/mail-post.rb b/lib/mail-post.rb new file mode 100755 index 0000000..ea8bf56 --- /dev/null +++ b/lib/mail-post.rb @@ -0,0 +1,50 @@ +#!/usr/bin/env ruby +# SPDX-License-Identifier: MulanPSL-2.0+ +# Copyright (c) 2020 Huawei Technologies Co., Ltd. All rights reserved. +# frozen_string_literal: true
+require 'sinatra' +require 'json' +require 'yaml' +require 'open3' +require_relative "#{ENV['CCI_SRC']}/container/send-internet-mail/send-internet-mail.rb"
+set :bind, '0.0.0.0' +set :port, 11312
+post '/send_mail_yaml' do
- data = YAML.safe_load request.body.read
- raise TypeError, data, 'request data type error' unless data.class.eql? Hash
- mail_info = {
- 'references' => data['references'],
- 'from' => data['from'],
- 'subject' => data['subject'] || nil,
- 'to' => data['to'] || nil,
- 'body' => data['body'] || nil
- }
- check_send_mail(mail_info)
+end
+post '/send_mail_text' do
- data = Mail.read_from_string(request.body.read)
- mail_info = {
- 'references' => data.references,
- 'from' => data.from,
- 'subject' => data.subject || nil,
- 'to' => data.to || nil,
- 'body' => data.body.decoded || nil
- }
- check_send_mail(mail_info)
+end
+def check_send_mail(mail_info)
- raise 'empty subject.' if mail_info['subject'].nil?
- raise 'empty email address.' if mail_info['to'].nil?
- raise 'empty email content.' if mail_info['body'].nil?
- puts ENV['EMAIL_ADDRESS']
- puts ENV['EMAIL_PASSWORD']
- send_mail(mail_info)
+end
2.23.0