if user have multi email address, can set mapping to redis queue 'email_mapping' to enable to send mail to a specified address of user with any email address of user in the send address bar example: email_addr_a => email_addr email_addr_b => email_addr when you write either email_addr_a or email_addr_b in the send address bar, the email address will be converted to email_addr
Signed-off-by: Luan Shengde shdluan@163.com --- container/send-internet-mail/email_mapping.rb | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 container/send-internet-mail/email_mapping.rb
diff --git a/container/send-internet-mail/email_mapping.rb b/container/send-internet-mail/email_mapping.rb new file mode 100755 index 0000000..60ff3b8 --- /dev/null +++ b/container/send-internet-mail/email_mapping.rb @@ -0,0 +1,39 @@ +#!/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 'json' +require 'redis' + +# to check if the emails count has beyond the limit +class EmailAddrMapping + def initialize(mail_info) + @mail_info = mail_info + @redis = Redis.new('host' => REDIS_HOST, 'port' => REDIS_PORT) + end + + def check_email_mapping + email_to = @mail_info['to'].clone + email_cc = @mail_info['cc'].clone + email_bcc = @mail_info['bcc'].clone + @mail_info['to'] = email_mapping(email_to) + @mail_info['cc'] = email_mapping(email_cc) + @mail_info['bcc'] = email_mapping(email_bcc) + + return @mail_info + end + + def email_mapping(mail_list) + return if mail_list.nil? || mail_list.empty? + + mail_list.clone.each do |email| + if @redis.hexists 'email_mapping', email + mapped_email = @redis.hget 'email_mapping', 'luanshd@crystal.ci' + mail_list -= [email] + mail_list << mapped_email unless mail_list.include? mapped_email + end + end + return mail_list + end +end
pls ignore this
Thanks, Luan Shengde
On Mon, Jan 04, 2021 at 05:54:13PM +0800, Luan Shengde wrote:
if user have multi email address, can set mapping to redis queue 'email_mapping' to enable to send mail to a specified address of user with any email address of user in the send address bar example: email_addr_a => email_addr email_addr_b => email_addr when you write either email_addr_a or email_addr_b in the send address bar, the email address will be converted to email_addr
Signed-off-by: Luan Shengde shdluan@163.com
container/send-internet-mail/email_mapping.rb | 39 +++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100755 container/send-internet-mail/email_mapping.rb
diff --git a/container/send-internet-mail/email_mapping.rb b/container/send-internet-mail/email_mapping.rb new file mode 100755 index 0000000..60ff3b8 --- /dev/null +++ b/container/send-internet-mail/email_mapping.rb @@ -0,0 +1,39 @@ +#!/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 'json' +require 'redis'
+# to check if the emails count has beyond the limit +class EmailAddrMapping
- def initialize(mail_info)
- @mail_info = mail_info
- @redis = Redis.new('host' => REDIS_HOST, 'port' => REDIS_PORT)
- end
- def check_email_mapping
- email_to = @mail_info['to'].clone
- email_cc = @mail_info['cc'].clone
- email_bcc = @mail_info['bcc'].clone
- @mail_info['to'] = email_mapping(email_to)
- @mail_info['cc'] = email_mapping(email_cc)
- @mail_info['bcc'] = email_mapping(email_bcc)
- return @mail_info
- end
- def email_mapping(mail_list)
- return if mail_list.nil? || mail_list.empty?
- mail_list.clone.each do |email|
if @redis.hexists 'email_mapping', email
mapped_email = @redis.hget 'email_mapping', 'luanshd@crystal.ci'
mail_list -= [email]
mail_list << mapped_email unless mail_list.include? mapped_email
end
- end
- return mail_list
- end
+end
2.23.0