
+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
Can't agree with you, handle_new_email is the top logic, no need show the detail, need call the base logic.
the top is monitor_new_email, handle_new_email is just handle the new email file in the loop. the function just do: read email file execute operations mv the file there is no need to set a function for each of them Thanks, Luan Shengde
Thanks, Xueliang
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