From 897563a309f0c823ccf4d980a6ceddde090c394b Mon Sep 17 00:00:00 2001
From: Arpit Jalan <arpit@techapj.com>
Date: Wed, 21 Oct 2015 00:00:06 +0530
Subject: [PATCH] FIX: List-ID should not contain space

---
 lib/email/sender.rb                  | 4 ++--
 spec/components/email/sender_spec.rb | 5 ++++-
 2 files changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/email/sender.rb b/lib/email/sender.rb
index d1720aedd98..5f1be20d19d 100644
--- a/lib/email/sender.rb
+++ b/lib/email/sender.rb
@@ -87,12 +87,12 @@ module Email
 
         # http://www.ietf.org/rfc/rfc2919.txt
         if topic && topic.category && !topic.category.uncategorized?
-          list_id = "<#{topic.category.name.downcase}.#{host}>"
+          list_id = "<#{topic.category.name.downcase.split(' ').join('-')}.#{host}>"
 
           # subcategory case
           if !topic.category.parent_category_id.nil?
             parent_category_name = Category.find_by(id: topic.category.parent_category_id).name
-            list_id = "<#{topic.category.name.downcase}.#{parent_category_name.downcase}.#{host}>"
+            list_id = "<#{topic.category.name.downcase.split(' ').join('-')}.#{parent_category_name.downcase.split(' ').join('-')}.#{host}>"
           end
         else
           list_id = "<#{host}>"
diff --git a/spec/components/email/sender_spec.rb b/spec/components/email/sender_spec.rb
index 55f56e4c351..06ed0bb65bc 100644
--- a/spec/components/email/sender_spec.rb
+++ b/spec/components/email/sender_spec.rb
@@ -66,11 +66,14 @@ describe Email::Sender do
 
     context "adds a List-ID header to identify the forum" do
       before do
-        message.header['X-Discourse-Topic-Id'] = 5577
+        category =  Fabricate(:category, name: 'Name With Space')
+        topic = Fabricate(:topic, category_id: category.id)
+        message.header['X-Discourse-Topic-Id'] = topic.id
       end
 
       When { email_sender.send }
       Then { expect(message.header['List-ID']).to be_present }
+      Then { expect(message.header['List-ID'].to_s).to match('name-with-space') }
     end
 
     context "adds a Message-ID header even when topic id is not present" do