{"action":"created","comment":{"url":"https://api.github.com/repos/linagora/james-project/pulls/comments/60881843","id":60881843,"diff_hunk":"@@ -0,0 +1,116 @@\n+/****************************************************************\n+ * Licensed to the Apache Software Foundation (ASF) under one   *\n+ * or more contributor license agreements.  See the NOTICE file *\n+ * distributed with this work for additional information        *\n+ * regarding copyright ownership.  The ASF licenses this file   *\n+ * to you under the Apache License, Version 2.0 (the            *\n+ * \"License\"); you may not use this file except in compliance   *\n+ * with the License.  You may obtain a copy of the License at   *\n+ *                                                              *\n+ *   http://www.apache.org/licenses/LICENSE-2.0                 *\n+ *                                                              *\n+ * Unless required by applicable law or agreed to in writing,   *\n+ * software distributed under the License is distributed on an  *\n+ * \"AS IS\" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *\n+ * KIND, either express or implied.  See the License for the    *\n+ * specific language governing permissions and limitations      *\n+ * under the License.                                           *\n+ ****************************************************************/\n+\n+package org.apache.james.jmap.mailet;\n+\n+import java.util.Optional;\n+import java.util.concurrent.CompletableFuture;\n+\n+import javax.inject.Inject;\n+import javax.mail.MessagingException;\n+\n+import org.apache.james.jmap.api.vacation.AccountId;\n+import org.apache.james.jmap.api.vacation.Vacation;\n+import org.apache.james.jmap.api.vacation.VacationRepository;\n+import org.apache.james.jmap.utils.ZonedDateTimeProvider;\n+import org.apache.mailet.Mail;\n+import org.apache.mailet.MailAddress;\n+import org.apache.mailet.base.GenericMailet;\n+import org.slf4j.Logger;\n+import org.slf4j.LoggerFactory;\n+\n+public class VacationMailet extends GenericMailet {\n+\n+    private static final Logger LOGGER = LoggerFactory.getLogger(VacationMailet.class);\n+\n+    public static class ContextualizedValue<T> {\n+        private final MailAddress recipient;\n+        private final T value;\n+\n+        public ContextualizedValue(MailAddress recipient, T value) {\n+            this.recipient = recipient;\n+            this.value = value;\n+        }\n+\n+        public MailAddress getRecipient() {\n+            return recipient;\n+        }\n+\n+        public T getValue() {\n+            return value;\n+        }\n+    }\n+\n+    private final VacationRepository vacationRepository;\n+    private final ZonedDateTimeProvider zonedDateTimeProvider;\n+\n+    @Inject\n+    public VacationMailet(VacationRepository vacationRepository, ZonedDateTimeProvider zonedDateTimeProvider) {\n+        this.vacationRepository = vacationRepository;\n+        this.zonedDateTimeProvider = zonedDateTimeProvider;\n+    }\n+\n+    @Override\n+    public void service(Mail mail) throws MessagingException {\n+        mail.getRecipients()\n+            .stream()\n+            .map(mailAddress -> new ContextualizedValue<>(mailAddress,\n+                AccountId.create(mailAddress.getLocalPart() + \"@\" + mailAddress.getDomain())))\n+            .map(accountIdWithContext -> new ContextualizedValue<>(accountIdWithContext.getRecipient(),\n+                vacationRepository.retrieveVacation(accountIdWithContext.getValue())))\n+            .map(vacationWithContext -> manageVacation(vacationWithContext, mail))\n+            .forEach(CompletableFuture::join);\n+    }\n+\n+    public CompletableFuture<Vacation> manageVacation(ContextualizedValue<CompletableFuture<Vacation>> contextualizedVacation, Mail processedMail) {\n+        return contextualizedVacation.getValue().whenCompleteAsync((vacation, exception) -> {\n+            if (vacation != null) {\n+                if (shouldSendNotification(vacation, processedMail, contextualizedVacation.getRecipient())) {\n+                    sendNotification(contextualizedVacation.getRecipient(), processedMail, vacation);\n+                }\n+            } else {\n+                LOGGER.warn(\"Can not retrieve vacation\", exception);","path":"server/protocols/jmap/src/main/java/org/apache/james/jmap/mailet/VacationMailet.java","position":88,"original_position":88,"commit_id":"9ea5de55ac062e906ed2a504858b7cefd87e04e2","original_commit_id":"72f3ddbd3ec0cd561a7a429f03a4584a1b38d888","user":{"login":"mbaechler","id":708318,"avatar_url":"https://avatars.githubusercontent.com/u/708318?v=3","gravatar_id":"","url":"https://api.github.com/users/mbaechler","html_url":"https://github.com/mbaechler","followers_url":"https://api.github.com/users/mbaechler/followers","following_url":"https://api.github.com/users/mbaechler/following{/other_user}","gists_url":"https://api.github.com/users/mbaechler/gists{/gist_id}","starred_url":"https://api.github.com/users/mbaechler/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/mbaechler/subscriptions","organizations_url":"https://api.github.com/users/mbaechler/orgs","repos_url":"https://api.github.com/users/mbaechler/repos","events_url":"https://api.github.com/users/mbaechler/events{/privacy}","received_events_url":"https://api.github.com/users/mbaechler/received_events","type":"User","site_admin":false},"body":"what does it mean ? In which case a recipient doesn't have vacation ?","created_at":"2016-04-25T09:05:37Z","updated_at":"2016-04-25T09:05:37Z","html_url":"https://github.com/linagora/james-project/pull/220#discussion_r60881843","pull_request_url":"https://api.github.com/repos/linagora/james-project/pulls/220","_links":{"self":{"href":"https://api.github.com/repos/linagora/james-project/pulls/comments/60881843"},"html":{"href":"https://github.com/linagora/james-project/pull/220#discussion_r60881843"},"pull_request":{"href":"https://api.github.com/repos/linagora/james-project/pulls/220"}}},"pull_request":{"url":"https://api.github.com/repos/linagora/james-project/pulls/220","id":67477273,"html_url":"https://github.com/linagora/james-project/pull/220","diff_url":"https://github.com/linagora/james-project/pull/220.diff","patch_url":"https://github.com/linagora/james-project/pull/220.patch","issue_url":"https://api.github.com/repos/linagora/james-project/issues/220","number":220,"state":"open","locked":false,"title":"James 1717 Introduce Vacation mailet","user":{"login":"chibenwa","id":6928740,"avatar_url":"https://avatars.githubusercontent.com/u/6928740?v=3","gravatar_id":"","url":"https://api.github.com/users/chibenwa","html_url":"https://github.com/chibenwa","followers_url":"https://api.github.com/users/chibenwa/followers","following_url":"https://api.github.com/users/chibenwa/following{/other_user}","gists_url":"https://api.github.com/users/chibenwa/gists{/gist_id}","starred_url":"https://api.github.com/users/chibenwa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chibenwa/subscriptions","organizations_url":"https://api.github.com/users/chibenwa/orgs","repos_url":"https://api.github.com/users/chibenwa/repos","events_url":"https://api.github.com/users/chibenwa/events{/privacy}","received_events_url":"https://api.github.com/users/chibenwa/received_events","type":"User","site_admin":false},"body":"This PR introduce : \r\n\r\n - Correct some minor problems found (license, wrong MIME formatting)\r\n - A Vacation mailet handling the vacation notifications\r\n - It ensure this mailet do not responds to mailing lists and automatically send mails\r\n - It introduces awesome integration tests, mixing SMTP and JMAP !","created_at":"2016-04-22T08:40:30Z","updated_at":"2016-04-25T09:05:37Z","closed_at":null,"merged_at":null,"merge_commit_sha":"41bd3b1340be208a9133d5940bc0eefe963155c1","assignee":null,"milestone":null,"commits_url":"https://api.github.com/repos/linagora/james-project/pulls/220/commits","review_comments_url":"https://api.github.com/repos/linagora/james-project/pulls/220/comments","review_comment_url":"https://api.github.com/repos/linagora/james-project/pulls/comments{/number}","comments_url":"https://api.github.com/repos/linagora/james-project/issues/220/comments","statuses_url":"https://api.github.com/repos/linagora/james-project/statuses/9ea5de55ac062e906ed2a504858b7cefd87e04e2","head":{"label":"chibenwa:JAMES-1717-1","ref":"JAMES-1717-1","sha":"9ea5de55ac062e906ed2a504858b7cefd87e04e2","user":{"login":"chibenwa","id":6928740,"avatar_url":"https://avatars.githubusercontent.com/u/6928740?v=3","gravatar_id":"","url":"https://api.github.com/users/chibenwa","html_url":"https://github.com/chibenwa","followers_url":"https://api.github.com/users/chibenwa/followers","following_url":"https://api.github.com/users/chibenwa/following{/other_user}","gists_url":"https://api.github.com/users/chibenwa/gists{/gist_id}","starred_url":"https://api.github.com/users/chibenwa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chibenwa/subscriptions","organizations_url":"https://api.github.com/users/chibenwa/orgs","repos_url":"https://api.github.com/users/chibenwa/repos","events_url":"https://api.github.com/users/chibenwa/events{/privacy}","received_events_url":"https://api.github.com/users/chibenwa/received_events","type":"User","site_admin":false},"repo":{"id":42459504,"name":"james-project","full_name":"chibenwa/james-project","owner":{"login":"chibenwa","id":6928740,"avatar_url":"https://avatars.githubusercontent.com/u/6928740?v=3","gravatar_id":"","url":"https://api.github.com/users/chibenwa","html_url":"https://github.com/chibenwa","followers_url":"https://api.github.com/users/chibenwa/followers","following_url":"https://api.github.com/users/chibenwa/following{/other_user}","gists_url":"https://api.github.com/users/chibenwa/gists{/gist_id}","starred_url":"https://api.github.com/users/chibenwa/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/chibenwa/subscriptions","organizations_url":"https://api.github.com/users/chibenwa/orgs","repos_url":"https://api.github.com/users/chibenwa/repos","events_url":"https://api.github.com/users/chibenwa/events{/privacy}","received_events_url":"https://api.github.com/users/chibenwa/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/chibenwa/james-project","description":"Mirror of Apache James Project","fork":true,"url":"https://api.github.com/repos/chibenwa/james-project","forks_url":"https://api.github.com/repos/chibenwa/james-project/forks","keys_url":"https://api.github.com/repos/chibenwa/james-project/keys{/key_id}","collaborators_url":"https://api.github.com/repos/chibenwa/james-project/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/chibenwa/james-project/teams","hooks_url":"https://api.github.com/repos/chibenwa/james-project/hooks","issue_events_url":"https://api.github.com/repos/chibenwa/james-project/issues/events{/number}","events_url":"https://api.github.com/repos/chibenwa/james-project/events","assignees_url":"https://api.github.com/repos/chibenwa/james-project/assignees{/user}","branches_url":"https://api.github.com/repos/chibenwa/james-project/branches{/branch}","tags_url":"https://api.github.com/repos/chibenwa/james-project/tags","blobs_url":"https://api.github.com/repos/chibenwa/james-project/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/chibenwa/james-project/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/chibenwa/james-project/git/refs{/sha}","trees_url":"https://api.github.com/repos/chibenwa/james-project/git/trees{/sha}","statuses_url":"https://api.github.com/repos/chibenwa/james-project/statuses/{sha}","languages_url":"https://api.github.com/repos/chibenwa/james-project/languages","stargazers_url":"https://api.github.com/repos/chibenwa/james-project/stargazers","contributors_url":"https://api.github.com/repos/chibenwa/james-project/contributors","subscribers_url":"https://api.github.com/repos/chibenwa/james-project/subscribers","subscription_url":"https://api.github.com/repos/chibenwa/james-project/subscription","commits_url":"https://api.github.com/repos/chibenwa/james-project/commits{/sha}","git_commits_url":"https://api.github.com/repos/chibenwa/james-project/git/commits{/sha}","comments_url":"https://api.github.com/repos/chibenwa/james-project/comments{/number}","issue_comment_url":"https://api.github.com/repos/chibenwa/james-project/issues/comments{/number}","contents_url":"https://api.github.com/repos/chibenwa/james-project/contents/{+path}","compare_url":"https://api.github.com/repos/chibenwa/james-project/compare/{base}...{head}","merges_url":"https://api.github.com/repos/chibenwa/james-project/merges","archive_url":"https://api.github.com/repos/chibenwa/james-project/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/chibenwa/james-project/downloads","issues_url":"https://api.github.com/repos/chibenwa/james-project/issues{/number}","pulls_url":"https://api.github.com/repos/chibenwa/james-project/pulls{/number}","milestones_url":"https://api.github.com/repos/chibenwa/james-project/milestones{/number}","notifications_url":"https://api.github.com/repos/chibenwa/james-project/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/chibenwa/james-project/labels{/name}","releases_url":"https://api.github.com/repos/chibenwa/james-project/releases{/id}","deployments_url":"https://api.github.com/repos/chibenwa/james-project/deployments","created_at":"2015-09-14T15:57:25Z","updated_at":"2016-01-24T14:16:15Z","pushed_at":"2016-04-25T07:04:28Z","git_url":"git://github.com/chibenwa/james-project.git","ssh_url":"git@github.com:chibenwa/james-project.git","clone_url":"https://github.com/chibenwa/james-project.git","svn_url":"https://github.com/chibenwa/james-project","homepage":null,"size":11550,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":1,"mirror_url":null,"open_issues_count":7,"forks":1,"open_issues":7,"watchers":0,"default_branch":"trunk"}},"base":{"label":"linagora:master","ref":"master","sha":"1f3d5c8f2128f50e698a6d5ddb2cb20e69dfb187","user":{"login":"linagora","id":1230365,"avatar_url":"https://avatars.githubusercontent.com/u/1230365?v=3","gravatar_id":"","url":"https://api.github.com/users/linagora","html_url":"https://github.com/linagora","followers_url":"https://api.github.com/users/linagora/followers","following_url":"https://api.github.com/users/linagora/following{/other_user}","gists_url":"https://api.github.com/users/linagora/gists{/gist_id}","starred_url":"https://api.github.com/users/linagora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linagora/subscriptions","organizations_url":"https://api.github.com/users/linagora/orgs","repos_url":"https://api.github.com/users/linagora/repos","events_url":"https://api.github.com/users/linagora/events{/privacy}","received_events_url":"https://api.github.com/users/linagora/received_events","type":"Organization","site_admin":false},"repo":{"id":39182136,"name":"james-project","full_name":"linagora/james-project","owner":{"login":"linagora","id":1230365,"avatar_url":"https://avatars.githubusercontent.com/u/1230365?v=3","gravatar_id":"","url":"https://api.github.com/users/linagora","html_url":"https://github.com/linagora","followers_url":"https://api.github.com/users/linagora/followers","following_url":"https://api.github.com/users/linagora/following{/other_user}","gists_url":"https://api.github.com/users/linagora/gists{/gist_id}","starred_url":"https://api.github.com/users/linagora/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/linagora/subscriptions","organizations_url":"https://api.github.com/users/linagora/orgs","repos_url":"https://api.github.com/users/linagora/repos","events_url":"https://api.github.com/users/linagora/events{/privacy}","received_events_url":"https://api.github.com/users/linagora/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/linagora/james-project","description":"Mirror of Apache James Project","fork":true,"url":"https://api.github.com/repos/linagora/james-project","forks_url":"https://api.github.com/repos/linagora/james-project/forks","keys_url":"https://api.github.com/repos/linagora/james-project/keys{/key_id}","collaborators_url":"https://api.github.com/repos/linagora/james-project/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/linagora/james-project/teams","hooks_url":"https://api.github.com/repos/linagora/james-project/hooks","issue_events_url":"https://api.github.com/repos/linagora/james-project/issues/events{/number}","events_url":"https://api.github.com/repos/linagora/james-project/events","assignees_url":"https://api.github.com/repos/linagora/james-project/assignees{/user}","branches_url":"https://api.github.com/repos/linagora/james-project/branches{/branch}","tags_url":"https://api.github.com/repos/linagora/james-project/tags","blobs_url":"https://api.github.com/repos/linagora/james-project/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/linagora/james-project/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/linagora/james-project/git/refs{/sha}","trees_url":"https://api.github.com/repos/linagora/james-project/git/trees{/sha}","statuses_url":"https://api.github.com/repos/linagora/james-project/statuses/{sha}","languages_url":"https://api.github.com/repos/linagora/james-project/languages","stargazers_url":"https://api.github.com/repos/linagora/james-project/stargazers","contributors_url":"https://api.github.com/repos/linagora/james-project/contributors","subscribers_url":"https://api.github.com/repos/linagora/james-project/subscribers","subscription_url":"https://api.github.com/repos/linagora/james-project/subscription","commits_url":"https://api.github.com/repos/linagora/james-project/commits{/sha}","git_commits_url":"https://api.github.com/repos/linagora/james-project/git/commits{/sha}","comments_url":"https://api.github.com/repos/linagora/james-project/comments{/number}","issue_comment_url":"https://api.github.com/repos/linagora/james-project/issues/comments{/number}","contents_url":"https://api.github.com/repos/linagora/james-project/contents/{+path}","compare_url":"https://api.github.com/repos/linagora/james-project/compare/{base}...{head}","merges_url":"https://api.github.com/repos/linagora/james-project/merges","archive_url":"https://api.github.com/repos/linagora/james-project/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/linagora/james-project/downloads","issues_url":"https://api.github.com/repos/linagora/james-project/issues{/number}","pulls_url":"https://api.github.com/repos/linagora/james-project/pulls{/number}","milestones_url":"https://api.github.com/repos/linagora/james-project/milestones{/number}","notifications_url":"https://api.github.com/repos/linagora/james-project/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/linagora/james-project/labels{/name}","releases_url":"https://api.github.com/repos/linagora/james-project/releases{/id}","deployments_url":"https://api.github.com/repos/linagora/james-project/deployments","created_at":"2015-07-16T07:04:59Z","updated_at":"2016-04-17T23:38:48Z","pushed_at":"2016-04-22T12:59:56Z","git_url":"git://github.com/linagora/james-project.git","ssh_url":"git@github.com:linagora/james-project.git","clone_url":"https://github.com/linagora/james-project.git","svn_url":"https://github.com/linagora/james-project","homepage":null,"size":12969,"stargazers_count":3,"watchers_count":3,"language":"Java","has_issues":true,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":7,"mirror_url":null,"open_issues_count":11,"forks":7,"open_issues":11,"watchers":3,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/linagora/james-project/pulls/220"},"html":{"href":"https://github.com/linagora/james-project/pull/220"},"issue":{"href":"https://api.github.com/repos/linagora/james-project/issues/220"},"comments":{"href":"https://api.github.com/repos/linagora/james-project/issues/220/comments"},"review_comments":{"href":"https://api.github.com/repos/linagora/james-project/pulls/220/comments"},"review_comment":{"href":"https://api.github.com/repos/linagora/james-project/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/linagora/james-project/pulls/220/commits"},"statuses":{"href":"https://api.github.com/repos/linagora/james-project/statuses/9ea5de55ac062e906ed2a504858b7cefd87e04e2"}}}}