send mail interface: get send mail request build email info from the request data call send-internet-mail to send email with email info
Signed-off-by: Luan Shengde luanshengde2@huawei.com --- container/send-internet-mail/mail-post.rb | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 container/send-internet-mail/mail-post.rb
diff --git a/container/send-internet-mail/mail-post.rb b/container/send-internet-mail/mail-post.rb new file mode 100755 index 0000000..3b33c7f --- /dev/null +++ b/container/send-internet-mail/mail-post.rb @@ -0,0 +1,46 @@ +#!/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 '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'] || '', + 'subject' => data['subject'] || '', + 'to' => data['to'] || '', + 'body' => data['body'] || '' + } + check_send_mail(mail_info) if data +end + +post '/send_mail_text' do + data = Mail.read_from_string(request.body.read) + + mail_info = { + 'references' => data.references || '', + 'subject' => data.subject || '', + 'to' => data.to || '', + 'body' => data.body.decoded || '' + } + check_send_mail(mail_info) if data +end + +def check_send_mail(mail_info) + raise 'No subject.' if mail_info['subject'].empty? + raise 'No email address.' if mail_info['to'].empty? + raise 'No email body.' if mail_info['body'].empty? + + send_mail(mail_info) +end
What's the different with send-mail container? You can add the code to the lib and use it in any container. Thanks, Xueliang
On Tue, Oct 13, 2020 at 02:51:12PM +0800, Luan Shengde wrote:
send mail interface: get send mail request build email info from the request data call send-internet-mail to send email with email info
Signed-off-by: Luan Shengde luanshengde2@huawei.com
container/send-internet-mail/mail-post.rb | 46 +++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100755 container/send-internet-mail/mail-post.rb
diff --git a/container/send-internet-mail/mail-post.rb b/container/send-internet-mail/mail-post.rb new file mode 100755 index 0000000..3b33c7f --- /dev/null +++ b/container/send-internet-mail/mail-post.rb @@ -0,0 +1,46 @@ +#!/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 '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'] || '',
- 'subject' => data['subject'] || '',
- 'to' => data['to'] || '',
- 'body' => data['body'] || ''
- }
- check_send_mail(mail_info) if data
+end
+post '/send_mail_text' do
- data = Mail.read_from_string(request.body.read)
- mail_info = {
- 'references' => data.references || '',
- 'subject' => data.subject || '',
- 'to' => data.to || '',
- 'body' => data.body.decoded || ''
- }
- check_send_mail(mail_info) if data
+end
+def check_send_mail(mail_info)
- raise 'No subject.' if mail_info['subject'].empty?
- raise 'No email address.' if mail_info['to'].empty?
- raise 'No email body.' if mail_info['body'].empty?
- send_mail(mail_info)
+end
2.23.0
On Wed, Oct 14, 2020 at 09:46:27AM +0800, Luan Shengde wrote:
On Tue, Oct 13, 2020 at 03:31:36PM +0800, Cao Xueliang wrote:
What's the different with send-mail container?
They will use different port and data structure
好像没啥说服力. 请回答深层原因.
Thanks, Fengguang
You can add the code to the lib and use it in any container. Thanks, Xueliang
On Tue, Oct 13, 2020 at 03:31:36PM +0800, Cao Xueliang wrote:
What's the different with send-mail container? You can add the code to the lib and use it in any container.
I will merge both send intranet mail(crystal.ci) and internet mail in to one.
Thanks Luan Shengde
Thanks, Xueliang
On Fri, Oct 16, 2020 at 11:07:05AM +0800, Luan Shengde wrote:
On Tue, Oct 13, 2020 at 03:31:36PM +0800, Cao Xueliang wrote:
What's the different with send-mail container? You can add the code to the lib and use it in any container.
I will merge both send intranet mail(crystal.ci) and internet mail in to one.
It's reasonable in code reuse POV, however may better stay split in security and permission control POV.
Thanks, Fengguang