{"action":"created","comment":{"url":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/comments/40559077","id":40559077,"diff_hunk":"@@ -0,0 +1,118 @@\n+\n+import logging\n+import pymongo\n+import uuid\n+from collections import Mapping\n+from datetime import datetime\n+from pymongo.errors import DuplicateKeyError\n+from minimailgun.config import config\n+\n+\n+log = logging.getLogger(__name__)\n+\n+\n+class MongoStore(object):\n+\n+    def __init__(self, hosts=None, database=None, username=None, password=None):\n+        hosts = hosts or [('127.0.0.1', None)]\n+        if isinstance(hosts, Mapping):\n+            hosts = hosts.items()\n+        hosts = ','.join([\n+            '{address}:{port}'.format(address=address, port=port or '').rstrip(':')\n+            for address, port in hosts\n+        ])\n+\n+        if bool(username) != bool(password):\n+            raise ValueError('username and password are mutually required.')\n+        auth = '{username}:{password}@'.format(**locals()) if username else ''\n+        if not database:\n+            raise ValueError('database is required.')\n+\n+        self.url = 'mongodb://{auth}{hosts}/{database}'.format(**locals())\n+        self._database = database\n+        self._clear()\n+\n+    @property\n+    def client(self):\n+        if not self._client:\n+            self._client = pymongo.MongoClient(self.url)\n+            self.setup()\n+        return self._client\n+\n+    @property\n+    def db(self):\n+        if not self._db:\n+            self._db = self.client[self._database]\n+        return self._db\n+\n+    def close(self):\n+        if self._client:\n+            self._client.close()\n+            self._clear()\n+\n+    def _clear(self):\n+        self._client = None\n+        self._db = None\n+\n+    def setup(self):\n+        # TODO: setup indexing here\n+        pass\n+\n+    def add_mail(self, mail, recipient_set):\n+        mail['_created_at'] = datetime.utcnow()\n+        # create a recipient list and adjust the key, as bson docs\n+        # don't allow key with a '.' in it.","path":"minimailgun/store.py","position":63,"original_position":64,"commit_id":"3e3e69efa97419a955b7fd94c14d0dc84d87a9c0","original_commit_id":"b9f1e87685c3b31f89658123f235b5231e511b26","user":{"login":"amatai","id":609781,"avatar_url":"https://avatars.githubusercontent.com/u/609781?v=3","gravatar_id":"","url":"https://api.github.com/users/amatai","html_url":"https://github.com/amatai","followers_url":"https://api.github.com/users/amatai/followers","following_url":"https://api.github.com/users/amatai/following{/other_user}","gists_url":"https://api.github.com/users/amatai/gists{/gist_id}","starred_url":"https://api.github.com/users/amatai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amatai/subscriptions","organizations_url":"https://api.github.com/users/amatai/orgs","repos_url":"https://api.github.com/users/amatai/repos","events_url":"https://api.github.com/users/amatai/events{/privacy}","received_events_url":"https://api.github.com/users/amatai/received_events","type":"User","site_admin":false},"body":"Changed the code so that email address is no longer used as the key for dictionary. Instead using a uuid. The message is still kept as an aggregate of all the recipients, because, want to maintain a link between the main message and its recipients.\r\nWe can certainly, create an entry per recipient, though that will require - establishing a link between the recipient document and the main message document (foreign-key relationship, in SQL terminology).","created_at":"2015-09-28T14:38:15Z","updated_at":"2015-09-28T14:38:15Z","html_url":"https://github.com/amatai/mailgun-experiment/pull/1#discussion_r40559077","pull_request_url":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/1","_links":{"self":{"href":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/comments/40559077"},"html":{"href":"https://github.com/amatai/mailgun-experiment/pull/1#discussion_r40559077"},"pull_request":{"href":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/1"}}},"pull_request":{"url":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/1","id":46024073,"html_url":"https://github.com/amatai/mailgun-experiment/pull/1","diff_url":"https://github.com/amatai/mailgun-experiment/pull/1.diff","patch_url":"https://github.com/amatai/mailgun-experiment/pull/1.patch","issue_url":"https://api.github.com/repos/amatai/mailgun-experiment/issues/1","number":1,"state":"open","locked":false,"title":"Effort to create a Baby Mailgun","user":{"login":"amatai","id":609781,"avatar_url":"https://avatars.githubusercontent.com/u/609781?v=3","gravatar_id":"","url":"https://api.github.com/users/amatai","html_url":"https://github.com/amatai","followers_url":"https://api.github.com/users/amatai/followers","following_url":"https://api.github.com/users/amatai/following{/other_user}","gists_url":"https://api.github.com/users/amatai/gists{/gist_id}","starred_url":"https://api.github.com/users/amatai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amatai/subscriptions","organizations_url":"https://api.github.com/users/amatai/orgs","repos_url":"https://api.github.com/users/amatai/repos","events_url":"https://api.github.com/users/amatai/events{/privacy}","received_events_url":"https://api.github.com/users/amatai/received_events","type":"User","site_admin":false},"body":"","created_at":"2015-09-25T15:22:16Z","updated_at":"2015-09-28T14:38:15Z","closed_at":null,"merged_at":null,"merge_commit_sha":"ad253130c832f413455d38dce1d51d2199cbfb69","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/1/commits","review_comments_url":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/1/comments","review_comment_url":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/comments{/number}","comments_url":"https://api.github.com/repos/amatai/mailgun-experiment/issues/1/comments","statuses_url":"https://api.github.com/repos/amatai/mailgun-experiment/statuses/3e3e69efa97419a955b7fd94c14d0dc84d87a9c0","head":{"label":"amatai:babymailgun","ref":"babymailgun","sha":"3e3e69efa97419a955b7fd94c14d0dc84d87a9c0","user":{"login":"amatai","id":609781,"avatar_url":"https://avatars.githubusercontent.com/u/609781?v=3","gravatar_id":"","url":"https://api.github.com/users/amatai","html_url":"https://github.com/amatai","followers_url":"https://api.github.com/users/amatai/followers","following_url":"https://api.github.com/users/amatai/following{/other_user}","gists_url":"https://api.github.com/users/amatai/gists{/gist_id}","starred_url":"https://api.github.com/users/amatai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amatai/subscriptions","organizations_url":"https://api.github.com/users/amatai/orgs","repos_url":"https://api.github.com/users/amatai/repos","events_url":"https://api.github.com/users/amatai/events{/privacy}","received_events_url":"https://api.github.com/users/amatai/received_events","type":"User","site_admin":false},"repo":{"id":42910161,"name":"mailgun-experiment","full_name":"amatai/mailgun-experiment","owner":{"login":"amatai","id":609781,"avatar_url":"https://avatars.githubusercontent.com/u/609781?v=3","gravatar_id":"","url":"https://api.github.com/users/amatai","html_url":"https://github.com/amatai","followers_url":"https://api.github.com/users/amatai/followers","following_url":"https://api.github.com/users/amatai/following{/other_user}","gists_url":"https://api.github.com/users/amatai/gists{/gist_id}","starred_url":"https://api.github.com/users/amatai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amatai/subscriptions","organizations_url":"https://api.github.com/users/amatai/orgs","repos_url":"https://api.github.com/users/amatai/repos","events_url":"https://api.github.com/users/amatai/events{/privacy}","received_events_url":"https://api.github.com/users/amatai/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amatai/mailgun-experiment","description":"","fork":false,"url":"https://api.github.com/repos/amatai/mailgun-experiment","forks_url":"https://api.github.com/repos/amatai/mailgun-experiment/forks","keys_url":"https://api.github.com/repos/amatai/mailgun-experiment/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amatai/mailgun-experiment/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amatai/mailgun-experiment/teams","hooks_url":"https://api.github.com/repos/amatai/mailgun-experiment/hooks","issue_events_url":"https://api.github.com/repos/amatai/mailgun-experiment/issues/events{/number}","events_url":"https://api.github.com/repos/amatai/mailgun-experiment/events","assignees_url":"https://api.github.com/repos/amatai/mailgun-experiment/assignees{/user}","branches_url":"https://api.github.com/repos/amatai/mailgun-experiment/branches{/branch}","tags_url":"https://api.github.com/repos/amatai/mailgun-experiment/tags","blobs_url":"https://api.github.com/repos/amatai/mailgun-experiment/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amatai/mailgun-experiment/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amatai/mailgun-experiment/git/refs{/sha}","trees_url":"https://api.github.com/repos/amatai/mailgun-experiment/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amatai/mailgun-experiment/statuses/{sha}","languages_url":"https://api.github.com/repos/amatai/mailgun-experiment/languages","stargazers_url":"https://api.github.com/repos/amatai/mailgun-experiment/stargazers","contributors_url":"https://api.github.com/repos/amatai/mailgun-experiment/contributors","subscribers_url":"https://api.github.com/repos/amatai/mailgun-experiment/subscribers","subscription_url":"https://api.github.com/repos/amatai/mailgun-experiment/subscription","commits_url":"https://api.github.com/repos/amatai/mailgun-experiment/commits{/sha}","git_commits_url":"https://api.github.com/repos/amatai/mailgun-experiment/git/commits{/sha}","comments_url":"https://api.github.com/repos/amatai/mailgun-experiment/comments{/number}","issue_comment_url":"https://api.github.com/repos/amatai/mailgun-experiment/issues/comments{/number}","contents_url":"https://api.github.com/repos/amatai/mailgun-experiment/contents/{+path}","compare_url":"https://api.github.com/repos/amatai/mailgun-experiment/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amatai/mailgun-experiment/merges","archive_url":"https://api.github.com/repos/amatai/mailgun-experiment/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amatai/mailgun-experiment/downloads","issues_url":"https://api.github.com/repos/amatai/mailgun-experiment/issues{/number}","pulls_url":"https://api.github.com/repos/amatai/mailgun-experiment/pulls{/number}","milestones_url":"https://api.github.com/repos/amatai/mailgun-experiment/milestones{/number}","notifications_url":"https://api.github.com/repos/amatai/mailgun-experiment/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amatai/mailgun-experiment/labels{/name}","releases_url":"https://api.github.com/repos/amatai/mailgun-experiment/releases{/id}","created_at":"2015-09-22T03:54:44Z","updated_at":"2015-09-25T05:23:25Z","pushed_at":"2015-09-28T14:32:53Z","git_url":"git://github.com/amatai/mailgun-experiment.git","ssh_url":"git@github.com:amatai/mailgun-experiment.git","clone_url":"https://github.com/amatai/mailgun-experiment.git","svn_url":"https://github.com/amatai/mailgun-experiment","homepage":null,"size":0,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"base":{"label":"amatai:master","ref":"master","sha":"2925cb14811ba442643442e4c8f64b81850003a6","user":{"login":"amatai","id":609781,"avatar_url":"https://avatars.githubusercontent.com/u/609781?v=3","gravatar_id":"","url":"https://api.github.com/users/amatai","html_url":"https://github.com/amatai","followers_url":"https://api.github.com/users/amatai/followers","following_url":"https://api.github.com/users/amatai/following{/other_user}","gists_url":"https://api.github.com/users/amatai/gists{/gist_id}","starred_url":"https://api.github.com/users/amatai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amatai/subscriptions","organizations_url":"https://api.github.com/users/amatai/orgs","repos_url":"https://api.github.com/users/amatai/repos","events_url":"https://api.github.com/users/amatai/events{/privacy}","received_events_url":"https://api.github.com/users/amatai/received_events","type":"User","site_admin":false},"repo":{"id":42910161,"name":"mailgun-experiment","full_name":"amatai/mailgun-experiment","owner":{"login":"amatai","id":609781,"avatar_url":"https://avatars.githubusercontent.com/u/609781?v=3","gravatar_id":"","url":"https://api.github.com/users/amatai","html_url":"https://github.com/amatai","followers_url":"https://api.github.com/users/amatai/followers","following_url":"https://api.github.com/users/amatai/following{/other_user}","gists_url":"https://api.github.com/users/amatai/gists{/gist_id}","starred_url":"https://api.github.com/users/amatai/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/amatai/subscriptions","organizations_url":"https://api.github.com/users/amatai/orgs","repos_url":"https://api.github.com/users/amatai/repos","events_url":"https://api.github.com/users/amatai/events{/privacy}","received_events_url":"https://api.github.com/users/amatai/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/amatai/mailgun-experiment","description":"","fork":false,"url":"https://api.github.com/repos/amatai/mailgun-experiment","forks_url":"https://api.github.com/repos/amatai/mailgun-experiment/forks","keys_url":"https://api.github.com/repos/amatai/mailgun-experiment/keys{/key_id}","collaborators_url":"https://api.github.com/repos/amatai/mailgun-experiment/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/amatai/mailgun-experiment/teams","hooks_url":"https://api.github.com/repos/amatai/mailgun-experiment/hooks","issue_events_url":"https://api.github.com/repos/amatai/mailgun-experiment/issues/events{/number}","events_url":"https://api.github.com/repos/amatai/mailgun-experiment/events","assignees_url":"https://api.github.com/repos/amatai/mailgun-experiment/assignees{/user}","branches_url":"https://api.github.com/repos/amatai/mailgun-experiment/branches{/branch}","tags_url":"https://api.github.com/repos/amatai/mailgun-experiment/tags","blobs_url":"https://api.github.com/repos/amatai/mailgun-experiment/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/amatai/mailgun-experiment/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/amatai/mailgun-experiment/git/refs{/sha}","trees_url":"https://api.github.com/repos/amatai/mailgun-experiment/git/trees{/sha}","statuses_url":"https://api.github.com/repos/amatai/mailgun-experiment/statuses/{sha}","languages_url":"https://api.github.com/repos/amatai/mailgun-experiment/languages","stargazers_url":"https://api.github.com/repos/amatai/mailgun-experiment/stargazers","contributors_url":"https://api.github.com/repos/amatai/mailgun-experiment/contributors","subscribers_url":"https://api.github.com/repos/amatai/mailgun-experiment/subscribers","subscription_url":"https://api.github.com/repos/amatai/mailgun-experiment/subscription","commits_url":"https://api.github.com/repos/amatai/mailgun-experiment/commits{/sha}","git_commits_url":"https://api.github.com/repos/amatai/mailgun-experiment/git/commits{/sha}","comments_url":"https://api.github.com/repos/amatai/mailgun-experiment/comments{/number}","issue_comment_url":"https://api.github.com/repos/amatai/mailgun-experiment/issues/comments{/number}","contents_url":"https://api.github.com/repos/amatai/mailgun-experiment/contents/{+path}","compare_url":"https://api.github.com/repos/amatai/mailgun-experiment/compare/{base}...{head}","merges_url":"https://api.github.com/repos/amatai/mailgun-experiment/merges","archive_url":"https://api.github.com/repos/amatai/mailgun-experiment/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/amatai/mailgun-experiment/downloads","issues_url":"https://api.github.com/repos/amatai/mailgun-experiment/issues{/number}","pulls_url":"https://api.github.com/repos/amatai/mailgun-experiment/pulls{/number}","milestones_url":"https://api.github.com/repos/amatai/mailgun-experiment/milestones{/number}","notifications_url":"https://api.github.com/repos/amatai/mailgun-experiment/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/amatai/mailgun-experiment/labels{/name}","releases_url":"https://api.github.com/repos/amatai/mailgun-experiment/releases{/id}","created_at":"2015-09-22T03:54:44Z","updated_at":"2015-09-25T05:23:25Z","pushed_at":"2015-09-28T14:32:53Z","git_url":"git://github.com/amatai/mailgun-experiment.git","ssh_url":"git@github.com:amatai/mailgun-experiment.git","clone_url":"https://github.com/amatai/mailgun-experiment.git","svn_url":"https://github.com/amatai/mailgun-experiment","homepage":null,"size":0,"stargazers_count":1,"watchers_count":1,"language":null,"has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":1,"forks":0,"open_issues":1,"watchers":1,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/1"},"html":{"href":"https://github.com/amatai/mailgun-experiment/pull/1"},"issue":{"href":"https://api.github.com/repos/amatai/mailgun-experiment/issues/1"},"comments":{"href":"https://api.github.com/repos/amatai/mailgun-experiment/issues/1/comments"},"review_comments":{"href":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/1/comments"},"review_comment":{"href":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/amatai/mailgun-experiment/pulls/1/commits"},"statuses":{"href":"https://api.github.com/repos/amatai/mailgun-experiment/statuses/3e3e69efa97419a955b7fd94c14d0dc84d87a9c0"}}}}