From 7435427444ef188b63c8c4c6ad84a6ac7c3a8a50 Mon Sep 17 00:00:00 2001
From: Alex Shulgin <ash@commandprompt.com>
Date: Thu, 8 Sep 2011 20:50:03 +0300
Subject: [PATCH 13/25] Added --no-account-notice option for the mail handler script.

---
 app/models/mail_handler.rb            |    8 ++++++--
 extra/mail_handler/rdm-mailhandler.rb |    6 ++++--
 2 files changed, 10 insertions(+), 4 deletions(-)

diff --git a/app/models/mail_handler.rb b/app/models/mail_handler.rb
index 95b87da..daa5b48 100644
--- a/app/models/mail_handler.rb
+++ b/app/models/mail_handler.rb
@@ -42,7 +42,9 @@ class MailHandler < ActionMailer::Base
     # Status overridable by default
     @@handler_options[:allow_override] << 'status' unless @@handler_options[:issue].has_key?(:status)
 
-    @@handler_options[:no_permission_check] = (@@handler_options[:no_permission_check].to_s == '1' ? true : false)
+    @@handler_options[:no_permission_check] = (@@handler_options[:no_permission_check].to_s == '1')
+    @@handler_options[:no_account_notice] = (@@handler_options[:no_account_notice].to_s == '1')
+
     super email
   end
 
@@ -87,7 +89,9 @@ class MailHandler < ActionMailer::Base
         @user = create_user_from_email
         if @user
           logger.info "MailHandler: [#{@user.login}] account created"
-          Mailer.deliver_account_information(@user, @user.password)
+          unless @@handler_options[:no_account_notice]
+            Mailer.deliver_account_information(@user, @user.password)
+          end
         else
           logger.error "MailHandler: could not create account for [#{sender_email}]"
           return false
diff --git a/extra/mail_handler/rdm-mailhandler.rb b/extra/mail_handler/rdm-mailhandler.rb
index 42622e7..a04ef05 100644
--- a/extra/mail_handler/rdm-mailhandler.rb
+++ b/extra/mail_handler/rdm-mailhandler.rb
@@ -25,7 +25,7 @@ end
 class RedmineMailHandler
   VERSION = '0.2'
 
-  attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :url, :key, :no_check_certificate
+  attr_accessor :verbose, :issue_attributes, :allow_override, :unknown_user, :no_permission_check, :no_account_notice, :url, :key, :no_check_certificate
 
   def initialize
     self.issue_attributes = {}
@@ -47,6 +47,7 @@ class RedmineMailHandler
                                               "* create: create a user account") {|v| self.unknown_user = v}
       opts.on("--no-permission-check",        "disable permission checking when receiving",
                                               "the email") {self.no_permission_check = '1'}
+      opts.on("--no-account-notice",          "disable new user account notification") {self.no_account_notice = '1'}
       opts.on("--key-file FILE",              "path to a file that contains the Redmine",
                                               "API key (use this option instead of --key",
                                               "if you don't the key to appear in the",
@@ -95,7 +96,8 @@ class RedmineMailHandler
     data = { 'key' => key, 'email' => email,
                            'allow_override' => allow_override,
                            'unknown_user' => unknown_user,
-                           'no_permission_check' => no_permission_check}
+                           'no_permission_check' => no_permission_check,
+                           'no_account_notice' => no_account_notice }
     issue_attributes.each { |attr, value| data["issue[#{attr}]"] = value }
 
     debug "Posting to #{uri}..."
-- 
1.7.0.4

