On Mon, Nov 09, 2020 at 04:34:26PM +0800, Cao Xueliang wrote:
On Mon, Nov 09, 2020 at 04:19:01PM +0800, Luan Shengde wrote:
monitor mailbox for new email handle new email file check to apply account only if email's subject match 'apply account'
Signed-off-by: Luan Shengde shdluan@163.com
lib/mail-robot.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) create mode 100755 lib/mail-robot.rb
diff --git a/lib/mail-robot.rb b/lib/mail-robot.rb new file mode 100755 index 0000000..168e64b --- /dev/null +++ b/lib/mail-robot.rb @@ -0,0 +1,44 @@ +#!/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 'send-apply-account-email' +# require_relative 'send-uuid-email' +# require_relative 'send-error-email' +# require_relative 'apply-jumper-account' +# require_relative 'parse-apply-account-email' +# require_relative 'assign-account'
+# MAILDIR = '/srv/cci/Maildir/.compass-ci'
+def monitor_new_email(mail_inbox, mail_drafts)
- listener = Listen.to(mail_inbox) do |_modified, added, _removed|
- next if added.empty?
- added.each do |mail_file|
handle_new_email(mail_file, mail_drafts)
- end
- end
- listener.start
- sleep
+end
+def handle_new_email(mail_file, mail_drafts)
- mail_content = Mail.read(mail_file)
Don't define a variable but used only once.
this function will be expanded according new demands. so do not need care it's used times
- apply_account(mail_content)
- FileUtils.mv(mail_file, mail_drafts)
This line should be a function like drop_mail.
this line is just part of the function handle_new_email, mv email file to cur after apply_account. It no need to add a new function for it
Thanks, Luan Shengde
Thanks, Xueliang
+end
+def apply_account(mail_content)
- return unless mail_content.subject == 'apply account'
- assign_uuid = AssignAccount.new(mail_content)
- assign_uuid.send_account
+end
2.23.0