{"action":"created","comment":{"url":"https://api.github.com/repos/apache/nifi/pulls/comments/70612776","id":70612776,"diff_hunk":"@@ -0,0 +1,147 @@\n+/*\n+ * Licensed to the Apache Software Foundation (ASF) under one or more\n+ * contributor license agreements.  See the NOTICE file distributed with\n+ * this work for additional information regarding copyright ownership.\n+ * The ASF licenses this file to You under the Apache License, Version 2.0\n+ * (the \"License\"); you may not use this file except in compliance with\n+ * 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, software\n+ * distributed under the License is distributed on an \"AS IS\" BASIS,\n+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n+ * See the License for the specific language governing permissions and\n+ * limitations under the License.\n+ */\n+\n+package org.apache.nifi.processors.email.smtp.handler;\n+\n+import java.io.IOException;\n+import java.io.InputStream;\n+import java.security.cert.X509Certificate;\n+import java.util.concurrent.LinkedBlockingQueue;\n+import java.util.concurrent.TimeUnit;\n+\n+import org.apache.nifi.logging.ComponentLog;\n+import org.apache.nifi.stream.io.ByteArrayOutputStream;\n+import org.apache.nifi.util.StopWatch;\n+import org.subethamail.smtp.DropConnectionException;\n+import org.subethamail.smtp.MessageContext;\n+import org.subethamail.smtp.MessageHandler;\n+import org.subethamail.smtp.MessageHandlerFactory;\n+import org.subethamail.smtp.RejectException;\n+import org.subethamail.smtp.TooMuchDataException;\n+import org.subethamail.smtp.server.SMTPServer;\n+\n+import org.apache.nifi.processors.email.smtp.event.SmtpEvent;\n+\n+\n+public class SMTPMessageHandlerFactory implements MessageHandlerFactory {\n+    final LinkedBlockingQueue<SmtpEvent> incomingMessages;\n+    final ComponentLog logger;\n+\n+    public SMTPMessageHandlerFactory(LinkedBlockingQueue<SmtpEvent> incomingMessages, ComponentLog logger) {\n+        this.incomingMessages = incomingMessages;\n+        this.logger = logger;\n+    }\n+\n+    @Override\n+    public MessageHandler create(MessageContext messageContext) {\n+        return new Handler(messageContext, incomingMessages, logger);\n+    }\n+\n+    class Handler implements MessageHandler {\n+        final MessageContext messageContext;\n+        String from;\n+        String recipient;\n+        byte [] messageBody;\n+\n+\n+        public Handler(MessageContext messageContext, LinkedBlockingQueue<SmtpEvent> incomingMessages, ComponentLog logger){\n+            this.messageContext = messageContext;\n+        }\n+\n+        @Override\n+        public void from(String from) throws RejectException {\n+            // TODO: possibly whitelist senders?\n+            this.from = from;\n+        }\n+\n+        @Override\n+        public void recipient(String recipient) throws RejectException {\n+            // TODO: possibly whitelist receivers?\n+            this.recipient = recipient;\n+        }\n+\n+        @Override\n+        public void data(InputStream inputStream) throws RejectException, TooMuchDataException, IOException {\n+            // Start counting the timer...\n+\n+            StopWatch watch = new StopWatch(false);\n+\n+            SMTPServer server = messageContext.getSMTPServer();\n+\n+            ByteArrayOutputStream baos = new ByteArrayOutputStream();\n+\n+            byte [] buffer = new byte[1024];\n+            int rd;\n+\n+            while ((rd = inputStream.read(buffer, 0, buffer.length)) != -1) {\n+                baos.write(buffer, 0, rd);\n+            }\n+            if (baos.getBufferLength() > server.getMaxMessageSize()) {\n+                throw new TooMuchDataException(\"Data exceeds the amount allowed.\");\n+            }\n+\n+            baos.flush();\n+            this.messageBody = baos.toByteArray();\n+\n+\n+            X509Certificate[] certificates = new X509Certificate[]{};\n+\n+            String remoteIP = messageContext.getRemoteAddress().toString();\n+            String helo = messageContext.getHelo();\n+            if (messageContext.getTlsPeerCertificates() != null ){\n+                certificates = (X509Certificate[]) messageContext.getTlsPeerCertificates().clone();\n+            }\n+\n+            SmtpEvent message = new SmtpEvent(remoteIP, helo, from, recipient, certificates, messageBody);\n+            try {\n+                    // Try to queue the message back to the NiFi session\n+                    incomingMessages.put(message);\n+            } catch (InterruptedException e) {\n+                // Throws an error to the  incoming server alerting about issues queuing the message in NiFi\n+                logger.error(\"Hit an error sending message back to NiFi main thread {}. Sending and error back to SMTP client and discarding message\", new Object [] {e});\n+                throw new DropConnectionException(451, \"NiFi something went wrong while processing you message, please retry again later\");\n+            }\n+\n+            // Once message has been sent to the queue, it should be processed by NiFi onTrigger,\n+            // a flowfile created and its processed status updated before an acknowledgment is\n+            // given back to the SMTP client\n+            try {\n+                synchronized(message) {\n+                    while(! message.getProcessed()) {\n+                        // Check to see if it is too late...\n+                        final long serverTimeout = TimeUnit.NANOSECONDS.convert(messageContext.getSMTPServer().getConnectionTimeout(), TimeUnit.MILLISECONDS);","path":"nifi-nar-bundles/nifi-email-bundle/nifi-email-processors/src/main/java/org/apache/nifi/processors/email/smtp/handler/SMTPMessageHandlerFactory.java","position":null,"original_position":126,"commit_id":"80fd9e61defc93adff7d29fa3d6bbd65342303a2","original_commit_id":"1e60eb64412522126ac8aa36ca9d4ba89f1e415d","user":{"login":"trixpan","id":3108527,"avatar_url":"https://avatars.githubusercontent.com/u/3108527?v=3","gravatar_id":"","url":"https://api.github.com/users/trixpan","html_url":"https://github.com/trixpan","followers_url":"https://api.github.com/users/trixpan/followers","following_url":"https://api.github.com/users/trixpan/following{/other_user}","gists_url":"https://api.github.com/users/trixpan/gists{/gist_id}","starred_url":"https://api.github.com/users/trixpan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trixpan/subscriptions","organizations_url":"https://api.github.com/users/trixpan/orgs","repos_url":"https://api.github.com/users/trixpan/repos","events_url":"https://api.github.com/users/trixpan/events{/privacy}","received_events_url":"https://api.github.com/users/trixpan/received_events","type":"User","site_admin":false},"body":"addressed","created_at":"2016-07-13T12:08:11Z","updated_at":"2016-07-13T12:08:11Z","html_url":"https://github.com/apache/nifi/pull/483#discussion_r70612776","pull_request_url":"https://api.github.com/repos/apache/nifi/pulls/483","_links":{"self":{"href":"https://api.github.com/repos/apache/nifi/pulls/comments/70612776"},"html":{"href":"https://github.com/apache/nifi/pull/483#discussion_r70612776"},"pull_request":{"href":"https://api.github.com/repos/apache/nifi/pulls/483"}}},"pull_request":{"url":"https://api.github.com/repos/apache/nifi/pulls/483","id":72172549,"html_url":"https://github.com/apache/nifi/pull/483","diff_url":"https://github.com/apache/nifi/pull/483.diff","patch_url":"https://github.com/apache/nifi/pull/483.patch","issue_url":"https://api.github.com/repos/apache/nifi/issues/483","number":483,"state":"open","locked":false,"title":"NIFI-1899 - Introduce ExtractEmailAttachments and ExtractEmailHeaders processors","user":{"login":"trixpan","id":3108527,"avatar_url":"https://avatars.githubusercontent.com/u/3108527?v=3","gravatar_id":"","url":"https://api.github.com/users/trixpan","html_url":"https://github.com/trixpan","followers_url":"https://api.github.com/users/trixpan/followers","following_url":"https://api.github.com/users/trixpan/following{/other_user}","gists_url":"https://api.github.com/users/trixpan/gists{/gist_id}","starred_url":"https://api.github.com/users/trixpan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trixpan/subscriptions","organizations_url":"https://api.github.com/users/trixpan/orgs","repos_url":"https://api.github.com/users/trixpan/repos","events_url":"https://api.github.com/users/trixpan/events{/privacy}","received_events_url":"https://api.github.com/users/trixpan/received_events","type":"User","site_admin":false},"body":"~~Note: Still missing jUnit~~","created_at":"2016-06-01T12:35:04Z","updated_at":"2016-07-13T12:08:11Z","closed_at":null,"merged_at":null,"merge_commit_sha":"578b26933bfa3b856e1e4bf18b3254dc835036f9","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/apache/nifi/pulls/483/commits","review_comments_url":"https://api.github.com/repos/apache/nifi/pulls/483/comments","review_comment_url":"https://api.github.com/repos/apache/nifi/pulls/comments{/number}","comments_url":"https://api.github.com/repos/apache/nifi/issues/483/comments","statuses_url":"https://api.github.com/repos/apache/nifi/statuses/80fd9e61defc93adff7d29fa3d6bbd65342303a2","head":{"label":"trixpan:NIFI-1899","ref":"NIFI-1899","sha":"80fd9e61defc93adff7d29fa3d6bbd65342303a2","user":{"login":"trixpan","id":3108527,"avatar_url":"https://avatars.githubusercontent.com/u/3108527?v=3","gravatar_id":"","url":"https://api.github.com/users/trixpan","html_url":"https://github.com/trixpan","followers_url":"https://api.github.com/users/trixpan/followers","following_url":"https://api.github.com/users/trixpan/following{/other_user}","gists_url":"https://api.github.com/users/trixpan/gists{/gist_id}","starred_url":"https://api.github.com/users/trixpan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trixpan/subscriptions","organizations_url":"https://api.github.com/users/trixpan/orgs","repos_url":"https://api.github.com/users/trixpan/repos","events_url":"https://api.github.com/users/trixpan/events{/privacy}","received_events_url":"https://api.github.com/users/trixpan/received_events","type":"User","site_admin":false},"repo":{"id":54212012,"name":"nifi","full_name":"trixpan/nifi","owner":{"login":"trixpan","id":3108527,"avatar_url":"https://avatars.githubusercontent.com/u/3108527?v=3","gravatar_id":"","url":"https://api.github.com/users/trixpan","html_url":"https://github.com/trixpan","followers_url":"https://api.github.com/users/trixpan/followers","following_url":"https://api.github.com/users/trixpan/following{/other_user}","gists_url":"https://api.github.com/users/trixpan/gists{/gist_id}","starred_url":"https://api.github.com/users/trixpan/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/trixpan/subscriptions","organizations_url":"https://api.github.com/users/trixpan/orgs","repos_url":"https://api.github.com/users/trixpan/repos","events_url":"https://api.github.com/users/trixpan/events{/privacy}","received_events_url":"https://api.github.com/users/trixpan/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/trixpan/nifi","description":"Mirror of Apache NiFi","fork":true,"url":"https://api.github.com/repos/trixpan/nifi","forks_url":"https://api.github.com/repos/trixpan/nifi/forks","keys_url":"https://api.github.com/repos/trixpan/nifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/trixpan/nifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/trixpan/nifi/teams","hooks_url":"https://api.github.com/repos/trixpan/nifi/hooks","issue_events_url":"https://api.github.com/repos/trixpan/nifi/issues/events{/number}","events_url":"https://api.github.com/repos/trixpan/nifi/events","assignees_url":"https://api.github.com/repos/trixpan/nifi/assignees{/user}","branches_url":"https://api.github.com/repos/trixpan/nifi/branches{/branch}","tags_url":"https://api.github.com/repos/trixpan/nifi/tags","blobs_url":"https://api.github.com/repos/trixpan/nifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/trixpan/nifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/trixpan/nifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/trixpan/nifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/trixpan/nifi/statuses/{sha}","languages_url":"https://api.github.com/repos/trixpan/nifi/languages","stargazers_url":"https://api.github.com/repos/trixpan/nifi/stargazers","contributors_url":"https://api.github.com/repos/trixpan/nifi/contributors","subscribers_url":"https://api.github.com/repos/trixpan/nifi/subscribers","subscription_url":"https://api.github.com/repos/trixpan/nifi/subscription","commits_url":"https://api.github.com/repos/trixpan/nifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/trixpan/nifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/trixpan/nifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/trixpan/nifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/trixpan/nifi/contents/{+path}","compare_url":"https://api.github.com/repos/trixpan/nifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/trixpan/nifi/merges","archive_url":"https://api.github.com/repos/trixpan/nifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/trixpan/nifi/downloads","issues_url":"https://api.github.com/repos/trixpan/nifi/issues{/number}","pulls_url":"https://api.github.com/repos/trixpan/nifi/pulls{/number}","milestones_url":"https://api.github.com/repos/trixpan/nifi/milestones{/number}","notifications_url":"https://api.github.com/repos/trixpan/nifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/trixpan/nifi/labels{/name}","releases_url":"https://api.github.com/repos/trixpan/nifi/releases{/id}","deployments_url":"https://api.github.com/repos/trixpan/nifi/deployments","created_at":"2016-03-18T15:31:04Z","updated_at":"2016-03-18T15:31:18Z","pushed_at":"2016-07-12T15:01:51Z","git_url":"git://github.com/trixpan/nifi.git","ssh_url":"git@github.com:trixpan/nifi.git","clone_url":"https://github.com/trixpan/nifi.git","svn_url":"https://github.com/trixpan/nifi","homepage":"","size":48447,"stargazers_count":0,"watchers_count":0,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"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":"apache:master","ref":"master","sha":"4b9df7d1e24c8a8fa32ece2ee5d4118ebe5ffe18","user":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"repo":{"id":27911088,"name":"nifi","full_name":"apache/nifi","owner":{"login":"apache","id":47359,"avatar_url":"https://avatars.githubusercontent.com/u/47359?v=3","gravatar_id":"","url":"https://api.github.com/users/apache","html_url":"https://github.com/apache","followers_url":"https://api.github.com/users/apache/followers","following_url":"https://api.github.com/users/apache/following{/other_user}","gists_url":"https://api.github.com/users/apache/gists{/gist_id}","starred_url":"https://api.github.com/users/apache/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/apache/subscriptions","organizations_url":"https://api.github.com/users/apache/orgs","repos_url":"https://api.github.com/users/apache/repos","events_url":"https://api.github.com/users/apache/events{/privacy}","received_events_url":"https://api.github.com/users/apache/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/apache/nifi","description":"Mirror of Apache NiFi","fork":false,"url":"https://api.github.com/repos/apache/nifi","forks_url":"https://api.github.com/repos/apache/nifi/forks","keys_url":"https://api.github.com/repos/apache/nifi/keys{/key_id}","collaborators_url":"https://api.github.com/repos/apache/nifi/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/apache/nifi/teams","hooks_url":"https://api.github.com/repos/apache/nifi/hooks","issue_events_url":"https://api.github.com/repos/apache/nifi/issues/events{/number}","events_url":"https://api.github.com/repos/apache/nifi/events","assignees_url":"https://api.github.com/repos/apache/nifi/assignees{/user}","branches_url":"https://api.github.com/repos/apache/nifi/branches{/branch}","tags_url":"https://api.github.com/repos/apache/nifi/tags","blobs_url":"https://api.github.com/repos/apache/nifi/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/apache/nifi/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/apache/nifi/git/refs{/sha}","trees_url":"https://api.github.com/repos/apache/nifi/git/trees{/sha}","statuses_url":"https://api.github.com/repos/apache/nifi/statuses/{sha}","languages_url":"https://api.github.com/repos/apache/nifi/languages","stargazers_url":"https://api.github.com/repos/apache/nifi/stargazers","contributors_url":"https://api.github.com/repos/apache/nifi/contributors","subscribers_url":"https://api.github.com/repos/apache/nifi/subscribers","subscription_url":"https://api.github.com/repos/apache/nifi/subscription","commits_url":"https://api.github.com/repos/apache/nifi/commits{/sha}","git_commits_url":"https://api.github.com/repos/apache/nifi/git/commits{/sha}","comments_url":"https://api.github.com/repos/apache/nifi/comments{/number}","issue_comment_url":"https://api.github.com/repos/apache/nifi/issues/comments{/number}","contents_url":"https://api.github.com/repos/apache/nifi/contents/{+path}","compare_url":"https://api.github.com/repos/apache/nifi/compare/{base}...{head}","merges_url":"https://api.github.com/repos/apache/nifi/merges","archive_url":"https://api.github.com/repos/apache/nifi/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/apache/nifi/downloads","issues_url":"https://api.github.com/repos/apache/nifi/issues{/number}","pulls_url":"https://api.github.com/repos/apache/nifi/pulls{/number}","milestones_url":"https://api.github.com/repos/apache/nifi/milestones{/number}","notifications_url":"https://api.github.com/repos/apache/nifi/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/apache/nifi/labels{/name}","releases_url":"https://api.github.com/repos/apache/nifi/releases{/id}","deployments_url":"https://api.github.com/repos/apache/nifi/deployments","created_at":"2014-12-12T08:00:05Z","updated_at":"2016-07-12T22:08:56Z","pushed_at":"2016-07-13T09:01:44Z","git_url":"git://github.com/apache/nifi.git","ssh_url":"git@github.com:apache/nifi.git","clone_url":"https://github.com/apache/nifi.git","svn_url":"https://github.com/apache/nifi","homepage":"","size":71696,"stargazers_count":314,"watchers_count":314,"language":"Java","has_issues":false,"has_downloads":true,"has_wiki":false,"has_pages":false,"forks_count":275,"mirror_url":"git://git.apache.org/nifi.git","open_issues_count":59,"forks":275,"open_issues":59,"watchers":314,"default_branch":"master"}},"_links":{"self":{"href":"https://api.github.com/repos/apache/nifi/pulls/483"},"html":{"href":"https://github.com/apache/nifi/pull/483"},"issue":{"href":"https://api.github.com/repos/apache/nifi/issues/483"},"comments":{"href":"https://api.github.com/repos/apache/nifi/issues/483/comments"},"review_comments":{"href":"https://api.github.com/repos/apache/nifi/pulls/483/comments"},"review_comment":{"href":"https://api.github.com/repos/apache/nifi/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/apache/nifi/pulls/483/commits"},"statuses":{"href":"https://api.github.com/repos/apache/nifi/statuses/80fd9e61defc93adff7d29fa3d6bbd65342303a2"}}}}
{"actor":{"display_login":"trixpan"}}