Skip to content
Snippets Groups Projects
Select Git revision
  • move-gl-dropdown
  • improve-table-pagination-spec
  • move-markdown-preview
  • winh-fix-merge-request-spec
  • master default
  • index-namespaces-lower-name
  • winh-single-karma-test
  • 10-3-stable
  • 36782-replace-team-user-role-with-add_role-user-in-specs
  • winh-modal-internal-state
  • tz-ide-file-icons
  • 38869-milestone-select
  • update-autodevops-template
  • jivl-activate-repo-cookie-preferences
  • qa-add-deploy-key
  • docs-move-article-ldap
  • 40780-choose-file
  • 22643-manual-job-page
  • refactor-cluster-show-page-conservative
  • dm-sidekiq-versioning
  • v10.4.0.pre
  • v10.3.0
  • v10.3.0-rc5
  • v10.3.0-rc4
  • v10.3.0-rc3
  • v10.3.0-rc2
  • v10.2.5
  • v10.3.0-rc1
  • v10.0.7
  • v10.1.5
  • v10.2.4
  • v10.2.3
  • v10.2.2
  • v10.2.1
  • v10.3.0.pre
  • v10.2.0
  • v10.2.0-rc4
  • v10.2.0-rc3
  • v10.1.4
  • v10.2.0-rc2
40 results

incoming_email.rb

Blame
  • Forked from GitLab.org / GitLab FOSS
    25880 commits behind the upstream repository.
    • Rémy Coutable's avatar
      9f218fc1
      Improve and finish the fallback to the In-Reply-To and References header for... · 9f218fc1
      Rémy Coutable authored
      Improve and finish the fallback to the In-Reply-To and References header for the reply-by-email feature
      
      A few things to note:
      - The IncomingEmail feature is now enabled even without a
        correctly-formatted sub-address
      - Message-ID for new thread mail are kept the same so that subsequent
        notifications to this thread are grouped in the thread by the email
        service that receives the notification
        (i.e. In-Reply-To of the answer == Message-ID of the first thread message)
      - To maximize our chance to be able to retrieve the reply key, we look
        for it in the In-Reply-To header and the References header
      - The pattern for the fallback reply message id is "reply-[key]@[gitlab_host]"
      - Improve docs thanks to Axil
      9f218fc1
      History
      Improve and finish the fallback to the In-Reply-To and References header for...
      Rémy Coutable authored
      Improve and finish the fallback to the In-Reply-To and References header for the reply-by-email feature
      
      A few things to note:
      - The IncomingEmail feature is now enabled even without a
        correctly-formatted sub-address
      - Message-ID for new thread mail are kept the same so that subsequent
        notifications to this thread are grouped in the thread by the email
        service that receives the notification
        (i.e. In-Reply-To of the answer == Message-ID of the first thread message)
      - To maximize our chance to be able to retrieve the reply key, we look
        for it in the In-Reply-To header and the References header
      - The pattern for the fallback reply message id is "reply-[key]@[gitlab_host]"
      - Improve docs thanks to Axil
    incoming_email.rb 1.01 KiB
    module Gitlab
      module IncomingEmail
        class << self
          FALLBACK_REPLY_MESSAGE_ID_REGEX = /\Areply\-(.+)@#{Gitlab.config.gitlab.host}\Z/.freeze
    
          def enabled?
            config.enabled && config.address
          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
    
          def key_from_fallback_reply_message_id(message_id)
            match = message_id.match(FALLBACK_REPLY_MESSAGE_ID_REGEX)
            return unless match
    
            match[1]
          end
    
          def config
            Gitlab.config.incoming_email
          end
    
          private
    
          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