{"action":"created","comment":{"url":"https://api.github.com/repos/ivaldi/brimir/pulls/comments/39099095","id":39099095,"diff_hunk":"@@ -43,7 +43,44 @@ class Reply < ActiveRecord::Base\n         .where('locked_by_id IN (?) OR locked_at < ?',\n             [user.id, nil], Time.zone.now - 5.minutes)\n   }\n-\n+  \n+  def content_without_quotes\n+    # 1. Remove custom style from email.\n+    #\n+    result = content\n+      .gsub(/<style.*<\\/style>/im, \"\")\n+      .gsub(/<head.*<\\/head>/im, \"\")\n+    \n+    # 2. Detect common ways that lead in email quotes or signatures.\n+    #    http://stackoverflow.com/a/2193937/2066546\n+    #\n+    result = result\n+      .gsub(/<blockquote.*<\\/blockquote>/im, \"\")\n+      .gsub(/----.*/m, \"\")\n+      .gsub(/-----Original Message-----.*/im, \"\")\n+      .gsub(/Sent from my iPhone*/im, \"\")\n+      .gsub(/Sent from my BlackBerry*/im, \"\")\n+      .gsub(/________________________________*/im, \"\")\n+      \n+    # 3. Detect phrases that are stored in the i18n definitions\n+    #    like \"On September 09, 2015 08:24, foo@example.com wrote:\"\n+    #\n+    I18n.available_locales.each do |locale|\n+      if (regex = I18n.translate(:on_date_author_wrote_regex, locale: locale)).present?\n+        # for example: .gsub(/On .*wrote:.*/im, \"\")\n+        # The [^a-zA-Z0-9] part makes sure, the expression does not start within another word.\n+        result = result.gsub(/[^a-zA-Z0-9](#{regex})/im, \"\")\n+      end\n+    end\n+    \n+    # 4. Remove line breaks from the beginning and the end of the string.\n+    #\n+    result.gsub!(/(<br \\/>\\s*)*$/, '')\n+    result.gsub!(/^(\\s*<br \\/>)*/, '')\n+    result.strip!\n+    return result\n+  end\n+  ","path":"app/models/reply.rb","position":42,"original_position":42,"commit_id":"add9ae5aa7458547dd332eadd4d4b44aba753c73","original_commit_id":"add9ae5aa7458547dd332eadd4d4b44aba753c73","user":{"login":"houndci","id":6697940,"avatar_url":"https://avatars.githubusercontent.com/u/6697940?v=3","gravatar_id":"","url":"https://api.github.com/users/houndci","html_url":"https://github.com/houndci","followers_url":"https://api.github.com/users/houndci/followers","following_url":"https://api.github.com/users/houndci/following{/other_user}","gists_url":"https://api.github.com/users/houndci/gists{/gist_id}","starred_url":"https://api.github.com/users/houndci/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/houndci/subscriptions","organizations_url":"https://api.github.com/users/houndci/orgs","repos_url":"https://api.github.com/users/houndci/repos","events_url":"https://api.github.com/users/houndci/events{/privacy}","received_events_url":"https://api.github.com/users/houndci/received_events","type":"User","site_admin":false},"body":"Trailing whitespace detected.","created_at":"2015-09-09T21:29:59Z","updated_at":"2015-09-09T21:29:59Z","html_url":"https://github.com/ivaldi/brimir/pull/216#discussion_r39099095","pull_request_url":"https://api.github.com/repos/ivaldi/brimir/pulls/216","_links":{"self":{"href":"https://api.github.com/repos/ivaldi/brimir/pulls/comments/39099095"},"html":{"href":"https://github.com/ivaldi/brimir/pull/216#discussion_r39099095"},"pull_request":{"href":"https://api.github.com/repos/ivaldi/brimir/pulls/216"}}},"pull_request":{"url":"https://api.github.com/repos/ivaldi/brimir/pulls/216","id":44602943,"html_url":"https://github.com/ivaldi/brimir/pull/216","diff_url":"https://github.com/ivaldi/brimir/pull/216.diff","patch_url":"https://github.com/ivaldi/brimir/pull/216.patch","issue_url":"https://api.github.com/repos/ivaldi/brimir/issues/216","number":216,"state":"open","locked":false,"title":"New feature: Include conversation in reply emails","user":{"login":"fiedl","id":1679688,"avatar_url":"https://avatars.githubusercontent.com/u/1679688?v=3","gravatar_id":"","url":"https://api.github.com/users/fiedl","html_url":"https://github.com/fiedl","followers_url":"https://api.github.com/users/fiedl/followers","following_url":"https://api.github.com/users/fiedl/following{/other_user}","gists_url":"https://api.github.com/users/fiedl/gists{/gist_id}","starred_url":"https://api.github.com/users/fiedl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fiedl/subscriptions","organizations_url":"https://api.github.com/users/fiedl/orgs","repos_url":"https://api.github.com/users/fiedl/repos","events_url":"https://api.github.com/users/fiedl/events{/privacy}","received_events_url":"https://api.github.com/users/fiedl/received_events","type":"User","site_admin":false},"body":"## Overview\r\n\r\n#### When the feature is activated in the global tenant settings …\r\n\r\n![bildschirmfoto 2015-09-09 um 23 09 23](https://cloud.githubusercontent.com/assets/1679688/9774328/037b1860-5748-11e5-8a43-9276d0a3fe04.png)\r\n\r\n#### … the past conversation is included in reply emails sent to the customers:\r\n\r\n![bildschirmfoto 2015-09-09 um 23 11 43](https://cloud.githubusercontent.com/assets/1679688/9774381/6950318e-5748-11e5-88dc-d7cb2d99fc9b.png)\r\n\r\n## Why\r\n\r\nWe had several clients that did not recall several details from previous emails, including their own emails as well as emails by the support team. This conversation feature helps them to browse through the conversation quickly – hopefully reducing the workload of the support team.\r\n\r\n## Who has it\r\n\r\n* I think, *Zendesk* uses this feature.\r\n* *Uservoice* [decided against that feature](http://feedback.uservoice.com/forums/1-general-feedback/suggestions/3059343-display-message-history-on-the-emails-the-customer).\r\n\r\n## Whose replies are included in the conversation\r\n\r\n1. Do **not include internal notes** without recipient.\r\n2. Do not include internal questions to other agents.\r\n3. Do not include internal response from other agents.\r\n4. Include all replies that have the user as recipient.\r\n5. Include all external replies from the user.\r\n6. **Incldue all external replies** from other users, since\r\n   (a.) clients tend to reply from different email addresses, and\r\n   (b.) we often need confirmations from other external staff like\r\n         \"I confirm that you may grant this person admin permissions.\"","created_at":"2015-09-09T21:29:52Z","updated_at":"2015-09-09T21:29:59Z","closed_at":null,"merged_at":null,"merge_commit_sha":"845bb8d9a1339fe0966c643f26019c933501b47c","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/ivaldi/brimir/pulls/216/commits","review_comments_url":"https://api.github.com/repos/ivaldi/brimir/pulls/216/comments","review_comment_url":"https://api.github.com/repos/ivaldi/brimir/pulls/comments{/number}","comments_url":"https://api.github.com/repos/ivaldi/brimir/issues/216/comments","statuses_url":"https://api.github.com/repos/ivaldi/brimir/statuses/add9ae5aa7458547dd332eadd4d4b44aba753c73","head":{"label":"fiedl:sf/conversations_email","ref":"sf/conversations_email","sha":"add9ae5aa7458547dd332eadd4d4b44aba753c73","user":{"login":"fiedl","id":1679688,"avatar_url":"https://avatars.githubusercontent.com/u/1679688?v=3","gravatar_id":"","url":"https://api.github.com/users/fiedl","html_url":"https://github.com/fiedl","followers_url":"https://api.github.com/users/fiedl/followers","following_url":"https://api.github.com/users/fiedl/following{/other_user}","gists_url":"https://api.github.com/users/fiedl/gists{/gist_id}","starred_url":"https://api.github.com/users/fiedl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fiedl/subscriptions","organizations_url":"https://api.github.com/users/fiedl/orgs","repos_url":"https://api.github.com/users/fiedl/repos","events_url":"https://api.github.com/users/fiedl/events{/privacy}","received_events_url":"https://api.github.com/users/fiedl/received_events","type":"User","site_admin":false},"repo":{"id":34587151,"name":"brimir","full_name":"fiedl/brimir","owner":{"login":"fiedl","id":1679688,"avatar_url":"https://avatars.githubusercontent.com/u/1679688?v=3","gravatar_id":"","url":"https://api.github.com/users/fiedl","html_url":"https://github.com/fiedl","followers_url":"https://api.github.com/users/fiedl/followers","following_url":"https://api.github.com/users/fiedl/following{/other_user}","gists_url":"https://api.github.com/users/fiedl/gists{/gist_id}","starred_url":"https://api.github.com/users/fiedl/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/fiedl/subscriptions","organizations_url":"https://api.github.com/users/fiedl/orgs","repos_url":"https://api.github.com/users/fiedl/repos","events_url":"https://api.github.com/users/fiedl/events{/privacy}","received_events_url":"https://api.github.com/users/fiedl/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/fiedl/brimir","description":"Email helpdesk built using Ruby on Rails and Zurb Foundation","fork":true,"url":"https://api.github.com/repos/fiedl/brimir","forks_url":"https://api.github.com/repos/fiedl/brimir/forks","keys_url":"https://api.github.com/repos/fiedl/brimir/keys{/key_id}","collaborators_url":"https://api.github.com/repos/fiedl/brimir/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/fiedl/brimir/teams","hooks_url":"https://api.github.com/repos/fiedl/brimir/hooks","issue_events_url":"https://api.github.com/repos/fiedl/brimir/issues/events{/number}","events_url":"https://api.github.com/repos/fiedl/brimir/events","assignees_url":"https://api.github.com/repos/fiedl/brimir/assignees{/user}","branches_url":"https://api.github.com/repos/fiedl/brimir/branches{/branch}","tags_url":"https://api.github.com/repos/fiedl/brimir/tags","blobs_url":"https://api.github.com/repos/fiedl/brimir/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/fiedl/brimir/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/fiedl/brimir/git/refs{/sha}","trees_url":"https://api.github.com/repos/fiedl/brimir/git/trees{/sha}","statuses_url":"https://api.github.com/repos/fiedl/brimir/statuses/{sha}","languages_url":"https://api.github.com/repos/fiedl/brimir/languages","stargazers_url":"https://api.github.com/repos/fiedl/brimir/stargazers","contributors_url":"https://api.github.com/repos/fiedl/brimir/contributors","subscribers_url":"https://api.github.com/repos/fiedl/brimir/subscribers","subscription_url":"https://api.github.com/repos/fiedl/brimir/subscription","commits_url":"https://api.github.com/repos/fiedl/brimir/commits{/sha}","git_commits_url":"https://api.github.com/repos/fiedl/brimir/git/commits{/sha}","comments_url":"https://api.github.com/repos/fiedl/brimir/comments{/number}","issue_comment_url":"https://api.github.com/repos/fiedl/brimir/issues/comments{/number}","contents_url":"https://api.github.com/repos/fiedl/brimir/contents/{+path}","compare_url":"https://api.github.com/repos/fiedl/brimir/compare/{base}...{head}","merges_url":"https://api.github.com/repos/fiedl/brimir/merges","archive_url":"https://api.github.com/repos/fiedl/brimir/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/fiedl/brimir/downloads","issues_url":"https://api.github.com/repos/fiedl/brimir/issues{/number}","pulls_url":"https://api.github.com/repos/fiedl/brimir/pulls{/number}","milestones_url":"https://api.github.com/repos/fiedl/brimir/milestones{/number}","notifications_url":"https://api.github.com/repos/fiedl/brimir/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/fiedl/brimir/labels{/name}","releases_url":"https://api.github.com/repos/fiedl/brimir/releases{/id}","created_at":"2015-04-25T21:35:07Z","updated_at":"2015-04-25T21:35:08Z","pushed_at":"2015-09-09T20:57:04Z","git_url":"git://github.com/fiedl/brimir.git","ssh_url":"git@github.com:fiedl/brimir.git","clone_url":"https://github.com/fiedl/brimir.git","svn_url":"https://github.com/fiedl/brimir","homepage":"http://getbrimir.com","size":2570,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"ivaldi:master","ref":"master","sha":"70f7a7b32951a83aabbc36e2b9ce67c1867f8edf","user":{"login":"ivaldi","id":129135,"avatar_url":"https://avatars.githubusercontent.com/u/129135?v=3","gravatar_id":"","url":"https://api.github.com/users/ivaldi","html_url":"https://github.com/ivaldi","followers_url":"https://api.github.com/users/ivaldi/followers","following_url":"https://api.github.com/users/ivaldi/following{/other_user}","gists_url":"https://api.github.com/users/ivaldi/gists{/gist_id}","starred_url":"https://api.github.com/users/ivaldi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivaldi/subscriptions","organizations_url":"https://api.github.com/users/ivaldi/orgs","repos_url":"https://api.github.com/users/ivaldi/repos","events_url":"https://api.github.com/users/ivaldi/events{/privacy}","received_events_url":"https://api.github.com/users/ivaldi/received_events","type":"Organization","site_admin":false},"repo":{"id":6827131,"name":"brimir","full_name":"ivaldi/brimir","owner":{"login":"ivaldi","id":129135,"avatar_url":"https://avatars.githubusercontent.com/u/129135?v=3","gravatar_id":"","url":"https://api.github.com/users/ivaldi","html_url":"https://github.com/ivaldi","followers_url":"https://api.github.com/users/ivaldi/followers","following_url":"https://api.github.com/users/ivaldi/following{/other_user}","gists_url":"https://api.github.com/users/ivaldi/gists{/gist_id}","starred_url":"https://api.github.com/users/ivaldi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/ivaldi/subscriptions","organizations_url":"https://api.github.com/users/ivaldi/orgs","repos_url":"https://api.github.com/users/ivaldi/repos","events_url":"https://api.github.com/users/ivaldi/events{/privacy}","received_events_url":"https://api.github.com/users/ivaldi/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/ivaldi/brimir","description":"Email helpdesk built using Ruby on Rails and Zurb Foundation","fork":false,"url":"https://api.github.com/repos/ivaldi/brimir","forks_url":"https://api.github.com/repos/ivaldi/brimir/forks","keys_url":"https://api.github.com/repos/ivaldi/brimir/keys{/key_id}","collaborators_url":"https://api.github.com/repos/ivaldi/brimir/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/ivaldi/brimir/teams","hooks_url":"https://api.github.com/repos/ivaldi/brimir/hooks","issue_events_url":"https://api.github.com/repos/ivaldi/brimir/issues/events{/number}","events_url":"https://api.github.com/repos/ivaldi/brimir/events","assignees_url":"https://api.github.com/repos/ivaldi/brimir/assignees{/user}","branches_url":"https://api.github.com/repos/ivaldi/brimir/branches{/branch}","tags_url":"https://api.github.com/repos/ivaldi/brimir/tags","blobs_url":"https://api.github.com/repos/ivaldi/brimir/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/ivaldi/brimir/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/ivaldi/brimir/git/refs{/sha}","trees_url":"https://api.github.com/repos/ivaldi/brimir/git/trees{/sha}","statuses_url":"https://api.github.com/repos/ivaldi/brimir/statuses/{sha}","languages_url":"https://api.github.com/repos/ivaldi/brimir/languages","stargazers_url":"https://api.github.com/repos/ivaldi/brimir/stargazers","contributors_url":"https://api.github.com/repos/ivaldi/brimir/contributors","subscribers_url":"https://api.github.com/repos/ivaldi/brimir/subscribers","subscription_url":"https://api.github.com/repos/ivaldi/brimir/subscription","commits_url":"https://api.github.com/repos/ivaldi/brimir/commits{/sha}","git_commits_url":"https://api.github.com/repos/ivaldi/brimir/git/commits{/sha}","comments_url":"https://api.github.com/repos/ivaldi/brimir/comments{/number}","issue_comment_url":"https://api.github.com/repos/ivaldi/brimir/issues/comments{/number}","contents_url":"https://api.github.com/repos/ivaldi/brimir/contents/{+path}","compare_url":"https://api.github.com/repos/ivaldi/brimir/compare/{base}...{head}","merges_url":"https://api.github.com/repos/ivaldi/brimir/merges","archive_url":"https://api.github.com/repos/ivaldi/brimir/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/ivaldi/brimir/downloads","issues_url":"https://api.github.com/repos/ivaldi/brimir/issues{/number}","pulls_url":"https://api.github.com/repos/ivaldi/brimir/pulls{/number}","milestones_url":"https://api.github.com/repos/ivaldi/brimir/milestones{/number}","notifications_url":"https://api.github.com/repos/ivaldi/brimir/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/ivaldi/brimir/labels{/name}","releases_url":"https://api.github.com/repos/ivaldi/brimir/releases{/id}","created_at":"2012-11-23T12:31:36Z","updated_at":"2015-09-07T15:46:10Z","pushed_at":"2015-09-09T21:29:53Z","git_url":"git://github.com/ivaldi/brimir.git","ssh_url":"git@github.com:ivaldi/brimir.git","clone_url":"https://github.com/ivaldi/brimir.git","svn_url":"https://github.com/ivaldi/brimir","homepage":"http://getbrimir.com","size":4457,"stargazers_count":984,"watchers_count":984,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":true,"forks_count":245,"mirror_url":null,"open_issues_count":14,"forks":245,"open_issues":14,"watchers":984,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/ivaldi/brimir/pulls/216"},"html":{"href":"https://github.com/ivaldi/brimir/pull/216"},"issue":{"href":"https://api.github.com/repos/ivaldi/brimir/issues/216"},"comments":{"href":"https://api.github.com/repos/ivaldi/brimir/issues/216/comments"},"review_comments":{"href":"https://api.github.com/repos/ivaldi/brimir/pulls/216/comments"},"review_comment":{"href":"https://api.github.com/repos/ivaldi/brimir/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/ivaldi/brimir/pulls/216/commits"},"statuses":{"href":"https://api.github.com/repos/ivaldi/brimir/statuses/add9ae5aa7458547dd332eadd4d4b44aba753c73"}}}}