On Mon, Oct 19, 2020 at 02:57:27PM +0800, Luan Shengde wrote:
mail robot for email application
monitor mailbox check new added email file in new check new mail's subject return if unmatched subject call answerback-email check to apply uuid/account
Signed-off-by: Luan Shengde luanshengde2@huawei.com
container/mail-robot/mail-robot.rb | 43 ++++++++++++++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100755 container/mail-robot/mail-robot.rb
diff --git a/container/mail-robot/mail-robot.rb b/container/mail-robot/mail-robot.rb new file mode 100755 index 0000000..70b8b25 --- /dev/null +++ b/container/mail-robot/mail-robot.rb @@ -0,0 +1,43 @@ +#!/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 'yaml' +require 'listen' +require 'mail' +require 'fileutils' +require_relative 'answerback-email.rb'
+mail_inbox = '/srv/cci/Maildir/.compass-ci/new/' +mail_drafts = '/srv/cci/Maildir/.compass-ci/cur/'
Constant names should all use capital letters.
Thanks, Zhang Yuhang
+def monitor_dir(mail_inbox, mail_drafts)
- listener = Listen.to(mail_inbox) do |_modified, added, _removed|
- unless added.empty?
added.each do |mail_file|
begin
check_to_send_account(mail_file, mail_drafts)
rescue StandardError => e
puts e.message
puts e.backtrace
end
end
- end
- end
- listener.start
- sleep
+end
+def check_to_send_account(mail_file, mail_drafts)
- mail_content = Mail.read(mail_file)
- subject = mail_content.subject
- return unless subject =~ /apply account/i
- assign_uuid = AssignUuid.new(mail_content)
- assign_uuid.send_account
- FileUtils.mv(mail_file, mail_drafts)
+end
+monitor_dir(mail_inbox, mail_drafts)
2.23.0