{"action":"created","comment":{"url":"https://api.github.com/repos/livebg/bounce_email/pulls/comments/27645689","id":27645689,"diff_hunk":"@@ -237,5 +239,38 @@ def extract_original_message_after_delimiter(mail, delimiter_index)\n       message = mail.body.to_s.split(delimiter).last\n       message.split(INLINE_MESSAGE_END_DELIMITER).first.strip if message.match(INLINE_MESSAGE_END_DELIMITER)\n     end\n+\n+    def extract_and_assign_fields_from_original_mail(mail)\n+      extract_and_assign_message_id(mail) if mail.message_id.nil?\n+      extract_and_assign_from(mail) if mail.from.nil?\n+      extract_and_assign_to(mail) if mail.to.nil?\n+      extract_and_assign_subject(mail) if mail.subject.nil?\n+      mail\n+    end\n+\n+    def extract_and_assign_message_id(mail)\n+      value = extract_field(mail, 'Message-ID:')\n+      mail.add_message_id(value)\n+    end\n+\n+    def extract_and_assign_to(mail)\n+      value = extract_field(mail, 'To:')\n+      mail.to = value\n+    end\n+\n+    def extract_and_assign_from(mail)\n+      value = extract_field(mail, 'From:')\n+      mail.from = value\n+    end\n+\n+    def extract_and_assign_subject(mail)\n+      value = extract_field(mail, 'Subject:')\n+      mail.subject = value\n+    end\n+\n+    def extract_field(mail, field_name)\n+      field = mail.body.to_s.split(/[\\n|\\r\\n]+/).detect { |line| line.match field_name }\n+      field.split(':').last.strip if field","path":"lib/bounce_email.rb","position":49,"original_position":49,"commit_id":"4699248be46c5112d623fc032c64248628d85b09","original_commit_id":"4699248be46c5112d623fc032c64248628d85b09","user":{"login":"mitio","id":129307,"avatar_url":"https://avatars.githubusercontent.com/u/129307?v=3","gravatar_id":"","url":"https://api.github.com/users/mitio","html_url":"https://github.com/mitio","followers_url":"https://api.github.com/users/mitio/followers","following_url":"https://api.github.com/users/mitio/following{/other_user}","gists_url":"https://api.github.com/users/mitio/gists{/gist_id}","starred_url":"https://api.github.com/users/mitio/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mitio/subscriptions","organizations_url":"https://api.github.com/users/mitio/orgs","repos_url":"https://api.github.com/users/mitio/repos","events_url":"https://api.github.com/users/mitio/events{/privacy}","received_events_url":"https://api.github.com/users/mitio/received_events","type":"User","site_admin":false},"body":"This `split` here will fail if we have more than two colons on a line. [`String#split` has a second optional argument](http://ruby-doc.org/core-2.2.1/String.html#method-i-split) - limit. Maybe it'd be better to use `split(':', 2)` here.","created_at":"2015-04-02T10:17:35Z","updated_at":"2015-04-02T10:17:35Z","html_url":"https://github.com/livebg/bounce_email/pull/5#discussion_r27645689","pull_request_url":"https://api.github.com/repos/livebg/bounce_email/pulls/5","_links":{"self":{"href":"https://api.github.com/repos/livebg/bounce_email/pulls/comments/27645689"},"html":{"href":"https://github.com/livebg/bounce_email/pull/5#discussion_r27645689"},"pull_request":{"href":"https://api.github.com/repos/livebg/bounce_email/pulls/5"}}},"pull_request":{"url":"https://api.github.com/repos/livebg/bounce_email/pulls/5","id":32469387,"html_url":"https://github.com/livebg/bounce_email/pull/5","diff_url":"https://github.com/livebg/bounce_email/pull/5.diff","patch_url":"https://github.com/livebg/bounce_email/pull/5.patch","issue_url":"https://api.github.com/repos/livebg/bounce_email/issues/5","number":5,"state":"open","locked":false,"title":"Parse and reassign message-ID, to, from, and subject from original mail","user":{"login":"saghaulor","id":273862,"avatar_url":"https://avatars.githubusercontent.com/u/273862?v=3","gravatar_id":"","url":"https://api.github.com/users/saghaulor","html_url":"https://github.com/saghaulor","followers_url":"https://api.github.com/users/saghaulor/followers","following_url":"https://api.github.com/users/saghaulor/following{/other_user}","gists_url":"https://api.github.com/users/saghaulor/gists{/gist_id}","starred_url":"https://api.github.com/users/saghaulor/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/saghaulor/subscriptions","organizations_url":"https://api.github.com/users/saghaulor/orgs","repos_url":"https://api.github.com/users/saghaulor/repos","events_url":"https://api.github.com/users/saghaulor/events{/privacy}","received_events_url":"https://api.github.com/users/saghaulor/received_events","type":"User","site_admin":false},"body":"Sometimes it may be useful to access fields from the original mail in order to track/update the state of sent mail. These methods work to rebuild the original mail to the Mail object format as much as possible.","created_at":"2015-04-01T23:00:15Z","updated_at":"2015-04-02T10:17:35Z","closed_at":null,"merged_at":null,"merge_commit_sha":"e7b9e5b2b3ae1978d6c6f2523d9f185b1b60d995","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/livebg/bounce_email/pulls/5/commits","review_comments_url":"https://api.github.com/repos/livebg/bounce_email/pulls/5/comments","review_comment_url":"https://api.github.com/repos/livebg/bounce_email/pulls/comments{/number}","comments_url":"https://api.github.com/repos/livebg/bounce_email/issues/5/comments","statuses_url":"https://api.github.com/repos/livebg/bounce_email/statuses/4699248be46c5112d623fc032c64248628d85b09","head":{"label":"coupa:parse_message-id_from_original_mail","ref":"parse_message-id_from_original_mail","sha":"4699248be46c5112d623fc032c64248628d85b09","user":{"login":"coupa","id":58638,"avatar_url":"https://avatars.githubusercontent.com/u/58638?v=3","gravatar_id":"","url":"https://api.github.com/users/coupa","html_url":"https://github.com/coupa","followers_url":"https://api.github.com/users/coupa/followers","following_url":"https://api.github.com/users/coupa/following{/other_user}","gists_url":"https://api.github.com/users/coupa/gists{/gist_id}","starred_url":"https://api.github.com/users/coupa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coupa/subscriptions","organizations_url":"https://api.github.com/users/coupa/orgs","repos_url":"https://api.github.com/users/coupa/repos","events_url":"https://api.github.com/users/coupa/events{/privacy}","received_events_url":"https://api.github.com/users/coupa/received_events","type":"Organization","site_admin":false},"repo":{"id":33002652,"name":"bounce_email","full_name":"coupa/bounce_email","owner":{"login":"coupa","id":58638,"avatar_url":"https://avatars.githubusercontent.com/u/58638?v=3","gravatar_id":"","url":"https://api.github.com/users/coupa","html_url":"https://github.com/coupa","followers_url":"https://api.github.com/users/coupa/followers","following_url":"https://api.github.com/users/coupa/following{/other_user}","gists_url":"https://api.github.com/users/coupa/gists{/gist_id}","starred_url":"https://api.github.com/users/coupa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/coupa/subscriptions","organizations_url":"https://api.github.com/users/coupa/orgs","repos_url":"https://api.github.com/users/coupa/repos","events_url":"https://api.github.com/users/coupa/events{/privacy}","received_events_url":"https://api.github.com/users/coupa/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/coupa/bounce_email","description":"Fork of Agris Ameriks' bounce-email","fork":true,"url":"https://api.github.com/repos/coupa/bounce_email","forks_url":"https://api.github.com/repos/coupa/bounce_email/forks","keys_url":"https://api.github.com/repos/coupa/bounce_email/keys{/key_id}","collaborators_url":"https://api.github.com/repos/coupa/bounce_email/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/coupa/bounce_email/teams","hooks_url":"https://api.github.com/repos/coupa/bounce_email/hooks","issue_events_url":"https://api.github.com/repos/coupa/bounce_email/issues/events{/number}","events_url":"https://api.github.com/repos/coupa/bounce_email/events","assignees_url":"https://api.github.com/repos/coupa/bounce_email/assignees{/user}","branches_url":"https://api.github.com/repos/coupa/bounce_email/branches{/branch}","tags_url":"https://api.github.com/repos/coupa/bounce_email/tags","blobs_url":"https://api.github.com/repos/coupa/bounce_email/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/coupa/bounce_email/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/coupa/bounce_email/git/refs{/sha}","trees_url":"https://api.github.com/repos/coupa/bounce_email/git/trees{/sha}","statuses_url":"https://api.github.com/repos/coupa/bounce_email/statuses/{sha}","languages_url":"https://api.github.com/repos/coupa/bounce_email/languages","stargazers_url":"https://api.github.com/repos/coupa/bounce_email/stargazers","contributors_url":"https://api.github.com/repos/coupa/bounce_email/contributors","subscribers_url":"https://api.github.com/repos/coupa/bounce_email/subscribers","subscription_url":"https://api.github.com/repos/coupa/bounce_email/subscription","commits_url":"https://api.github.com/repos/coupa/bounce_email/commits{/sha}","git_commits_url":"https://api.github.com/repos/coupa/bounce_email/git/commits{/sha}","comments_url":"https://api.github.com/repos/coupa/bounce_email/comments{/number}","issue_comment_url":"https://api.github.com/repos/coupa/bounce_email/issues/comments{/number}","contents_url":"https://api.github.com/repos/coupa/bounce_email/contents/{+path}","compare_url":"https://api.github.com/repos/coupa/bounce_email/compare/{base}...{head}","merges_url":"https://api.github.com/repos/coupa/bounce_email/merges","archive_url":"https://api.github.com/repos/coupa/bounce_email/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/coupa/bounce_email/downloads","issues_url":"https://api.github.com/repos/coupa/bounce_email/issues{/number}","pulls_url":"https://api.github.com/repos/coupa/bounce_email/pulls{/number}","milestones_url":"https://api.github.com/repos/coupa/bounce_email/milestones{/number}","notifications_url":"https://api.github.com/repos/coupa/bounce_email/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/coupa/bounce_email/labels{/name}","releases_url":"https://api.github.com/repos/coupa/bounce_email/releases{/id}","created_at":"2015-03-27T18:31:35Z","updated_at":"2015-03-27T18:31:36Z","pushed_at":"2015-04-01T21:42:53Z","git_url":"git://github.com/coupa/bounce_email.git","ssh_url":"git@github.com:coupa/bounce_email.git","clone_url":"https://github.com/coupa/bounce_email.git","svn_url":"https://github.com/coupa/bounce_email","homepage":"","size":2114,"stargazers_count":0,"watchers_count":0,"language":"Ruby","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"master"}},"base":{"label":"livebg:master","ref":"master","sha":"ecc20386f01d8bf30775cdb764c919e5d53c9cdc","user":{"login":"livebg","id":1055899,"avatar_url":"https://avatars.githubusercontent.com/u/1055899?v=3","gravatar_id":"","url":"https://api.github.com/users/livebg","html_url":"https://github.com/livebg","followers_url":"https://api.github.com/users/livebg/followers","following_url":"https://api.github.com/users/livebg/following{/other_user}","gists_url":"https://api.github.com/users/livebg/gists{/gist_id}","starred_url":"https://api.github.com/users/livebg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/livebg/subscriptions","organizations_url":"https://api.github.com/users/livebg/orgs","repos_url":"https://api.github.com/users/livebg/repos","events_url":"https://api.github.com/users/livebg/events{/privacy}","received_events_url":"https://api.github.com/users/livebg/received_events","type":"Organization","site_admin":false},"repo":{"id":2636797,"name":"bounce_email","full_name":"livebg/bounce_email","owner":{"login":"livebg","id":1055899,"avatar_url":"https://avatars.githubusercontent.com/u/1055899?v=3","gravatar_id":"","url":"https://api.github.com/users/livebg","html_url":"https://github.com/livebg","followers_url":"https://api.github.com/users/livebg/followers","following_url":"https://api.github.com/users/livebg/following{/other_user}","gists_url":"https://api.github.com/users/livebg/gists{/gist_id}","starred_url":"https://api.github.com/users/livebg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/livebg/subscriptions","organizations_url":"https://api.github.com/users/livebg/orgs","repos_url":"https://api.github.com/users/livebg/repos","events_url":"https://api.github.com/users/livebg/events{/privacy}","received_events_url":"https://api.github.com/users/livebg/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/livebg/bounce_email","description":"Fork of Agris Ameriks' bounce-email","fork":true,"url":"https://api.github.com/repos/livebg/bounce_email","forks_url":"https://api.github.com/repos/livebg/bounce_email/forks","keys_url":"https://api.github.com/repos/livebg/bounce_email/keys{/key_id}","collaborators_url":"https://api.github.com/repos/livebg/bounce_email/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/livebg/bounce_email/teams","hooks_url":"https://api.github.com/repos/livebg/bounce_email/hooks","issue_events_url":"https://api.github.com/repos/livebg/bounce_email/issues/events{/number}","events_url":"https://api.github.com/repos/livebg/bounce_email/events","assignees_url":"https://api.github.com/repos/livebg/bounce_email/assignees{/user}","branches_url":"https://api.github.com/repos/livebg/bounce_email/branches{/branch}","tags_url":"https://api.github.com/repos/livebg/bounce_email/tags","blobs_url":"https://api.github.com/repos/livebg/bounce_email/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/livebg/bounce_email/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/livebg/bounce_email/git/refs{/sha}","trees_url":"https://api.github.com/repos/livebg/bounce_email/git/trees{/sha}","statuses_url":"https://api.github.com/repos/livebg/bounce_email/statuses/{sha}","languages_url":"https://api.github.com/repos/livebg/bounce_email/languages","stargazers_url":"https://api.github.com/repos/livebg/bounce_email/stargazers","contributors_url":"https://api.github.com/repos/livebg/bounce_email/contributors","subscribers_url":"https://api.github.com/repos/livebg/bounce_email/subscribers","subscription_url":"https://api.github.com/repos/livebg/bounce_email/subscription","commits_url":"https://api.github.com/repos/livebg/bounce_email/commits{/sha}","git_commits_url":"https://api.github.com/repos/livebg/bounce_email/git/commits{/sha}","comments_url":"https://api.github.com/repos/livebg/bounce_email/comments{/number}","issue_comment_url":"https://api.github.com/repos/livebg/bounce_email/issues/comments{/number}","contents_url":"https://api.github.com/repos/livebg/bounce_email/contents/{+path}","compare_url":"https://api.github.com/repos/livebg/bounce_email/compare/{base}...{head}","merges_url":"https://api.github.com/repos/livebg/bounce_email/merges","archive_url":"https://api.github.com/repos/livebg/bounce_email/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/livebg/bounce_email/downloads","issues_url":"https://api.github.com/repos/livebg/bounce_email/issues{/number}","pulls_url":"https://api.github.com/repos/livebg/bounce_email/pulls{/number}","milestones_url":"https://api.github.com/repos/livebg/bounce_email/milestones{/number}","notifications_url":"https://api.github.com/repos/livebg/bounce_email/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/livebg/bounce_email/labels{/name}","releases_url":"https://api.github.com/repos/livebg/bounce_email/releases{/id}","created_at":"2011-10-24T14:49:48Z","updated_at":"2015-04-01T07:36:20Z","pushed_at":"2015-04-01T23:00:17Z","git_url":"git://github.com/livebg/bounce_email.git","ssh_url":"git@github.com:livebg/bounce_email.git","clone_url":"https://github.com/livebg/bounce_email.git","svn_url":"https://github.com/livebg/bounce_email","homepage":"","size":2186,"stargazers_count":12,"watchers_count":12,"language":"Ruby","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":6,"mirror_url":null,"open_issues_count":1,"forks":6,"open_issues":1,"watchers":12,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/livebg/bounce_email/pulls/5"},"html":{"href":"https://github.com/livebg/bounce_email/pull/5"},"issue":{"href":"https://api.github.com/repos/livebg/bounce_email/issues/5"},"comments":{"href":"https://api.github.com/repos/livebg/bounce_email/issues/5/comments"},"review_comments":{"href":"https://api.github.com/repos/livebg/bounce_email/pulls/5/comments"},"review_comment":{"href":"https://api.github.com/repos/livebg/bounce_email/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/livebg/bounce_email/pulls/5/commits"},"statuses":{"href":"https://api.github.com/repos/livebg/bounce_email/statuses/4699248be46c5112d623fc032c64248628d85b09"}}}}