From ee028d9d60522f8993a0b2429ac8a0631d59229a Mon Sep 17 00:00:00 2001 From: Douwe Maan Date: Mon, 21 Sep 2015 09:46:47 +0200 Subject: Rename reply_by_email to incoming_email to prepare for the future. --- lib/gitlab/email/receiver.rb | 5 +++-- lib/gitlab/incoming_email.rb | 43 ++++++++++++++++++++++++++++++++++++++ lib/gitlab/reply_by_email.rb | 49 -------------------------------------------- lib/tasks/gitlab/check.rake | 18 ++++++++-------- 4 files changed, 55 insertions(+), 60 deletions(-) create mode 100644 lib/gitlab/incoming_email.rb delete mode 100644 lib/gitlab/reply_by_email.rb (limited to 'lib') diff --git a/lib/gitlab/email/receiver.rb b/lib/gitlab/email/receiver.rb index 355fbd27898..2b252b32887 100644 --- a/lib/gitlab/email/receiver.rb +++ b/lib/gitlab/email/receiver.rb @@ -65,7 +65,7 @@ module Gitlab def reply_key reply_key = nil message.to.each do |address| - reply_key = Gitlab::ReplyByEmail.reply_key_from_address(address) + reply_key = Gitlab::IncomingEmail.key_from_address(address) break if reply_key end @@ -98,7 +98,8 @@ module Gitlab note: reply, noteable_type: sent_notification.noteable_type, noteable_id: sent_notification.noteable_id, - commit_id: sent_notification.commit_id + commit_id: sent_notification.commit_id, + line_code: sent_notification.line_code ).execute end end diff --git a/lib/gitlab/incoming_email.rb b/lib/gitlab/incoming_email.rb new file mode 100644 index 00000000000..856ccc71084 --- /dev/null +++ b/lib/gitlab/incoming_email.rb @@ -0,0 +1,43 @@ +module Gitlab + module IncomingEmail + class << self + def enabled? + config.enabled && address_formatted_correctly? + end + + def address_formatted_correctly? + config.address && + config.address.include?("%{key}") + end + + def reply_address(key) + config.address.gsub('%{key}', key) + end + + def key_from_address(address) + regex = address_regex + return unless regex + + match = address.match(regex) + return unless match + + match[1] + end + + private + + def config + Gitlab.config.incoming_email + end + + def address_regex + wildcard_address = config.address + return nil unless wildcard_address + + regex = Regexp.escape(wildcard_address) + regex = regex.gsub(Regexp.escape('%{key}'), "(.+)") + Regexp.new(regex).freeze + end + end + end +end diff --git a/lib/gitlab/reply_by_email.rb b/lib/gitlab/reply_by_email.rb deleted file mode 100644 index c3fe6778f06..00000000000 --- a/lib/gitlab/reply_by_email.rb +++ /dev/null @@ -1,49 +0,0 @@ -module Gitlab - module ReplyByEmail - class << self - def enabled? - config.enabled && address_formatted_correctly? - end - - def address_formatted_correctly? - config.address && - config.address.include?("%{reply_key}") - end - - def reply_key - return nil unless enabled? - - SecureRandom.hex(16) - end - - def reply_address(reply_key) - config.address.gsub('%{reply_key}', reply_key) - end - - def reply_key_from_address(address) - regex = address_regex - return unless regex - - match = address.match(regex) - return unless match - - match[1] - end - - private - - def config - Gitlab.config.reply_by_email - end - - def address_regex - wildcard_address = config.address - return nil unless wildcard_address - - regex = Regexp.escape(wildcard_address) - regex = regex.gsub(Regexp.escape('%{reply_key}'), "(.+)") - Regexp.new(regex).freeze - end - end - end -end diff --git a/lib/tasks/gitlab/check.rake b/lib/tasks/gitlab/check.rake index b8eb13a4fea..c8222f8ce11 100644 --- a/lib/tasks/gitlab/check.rake +++ b/lib/tasks/gitlab/check.rake @@ -2,7 +2,7 @@ namespace :gitlab do desc "GitLab | Check the configuration of GitLab and its environment" task check: %w{gitlab:gitlab_shell:check gitlab:sidekiq:check - gitlab:reply_by_email:check + gitlab:incoming_email:check gitlab:ldap:check gitlab:app:check} @@ -634,13 +634,13 @@ namespace :gitlab do end - namespace :reply_by_email do + namespace :incoming_email do desc "GitLab | Check the configuration of Reply by email" task check: :environment do warn_user_is_not_gitlab start_checking "Reply by email" - if Gitlab.config.reply_by_email.enabled + if Gitlab.config.incoming_email.enabled check_address_formatted_correctly check_mail_room_config_exists check_imap_authentication @@ -665,12 +665,12 @@ namespace :gitlab do def check_address_formatted_correctly print "Address formatted correctly? ... " - if Gitlab::ReplyByEmail.address_formatted_correctly? + if Gitlab::IncomingEmail.address_formatted_correctly? puts "yes".green else puts "no".red try_fixing_it( - "Make sure that the address in config/gitlab.yml includes the '%{reply_key}' placeholder." + "Make sure that the address in config/gitlab.yml includes the '%{key}' placeholder." ) fix_and_rerun end @@ -689,7 +689,7 @@ namespace :gitlab do "Enable mail_room in the init.d configuration." ) for_more_information( - "doc/reply_by_email/README.md" + "doc/incoming_email/README.md" ) fix_and_rerun end @@ -708,7 +708,7 @@ namespace :gitlab do "Enable mail_room in your Procfile." ) for_more_information( - "doc/reply_by_email/README.md" + "doc/incoming_email/README.md" ) fix_and_rerun end @@ -753,7 +753,7 @@ namespace :gitlab do "Check that the information in config/mail_room.yml is correct" ) for_more_information( - "doc/reply_by_email/README.md" + "doc/incoming_email/README.md" ) fix_and_rerun end @@ -789,7 +789,7 @@ namespace :gitlab do "Check that the information in config/mail_room.yml is correct" ) for_more_information( - "doc/reply_by_email/README.md" + "doc/incoming_email/README.md" ) fix_and_rerun end -- cgit v1.2.3