From commits-return-21631-archive-asf-public=cust-asf.ponee.io@airflow.incubator.apache.org Wed Sep 12 14:10:25 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 75C0D18077B for ; Wed, 12 Sep 2018 14:10:24 +0200 (CEST) Received: (qmail 11652 invoked by uid 500); 12 Sep 2018 12:10:23 -0000 Mailing-List: contact commits-help@airflow.incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@airflow.incubator.apache.org Delivered-To: mailing list commits@airflow.incubator.apache.org Received: (qmail 11638 invoked by uid 99); 12 Sep 2018 12:10:23 -0000 Received: from ec2-52-202-80-70.compute-1.amazonaws.com (HELO gitbox.apache.org) (52.202.80.70) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 12 Sep 2018 12:10:23 +0000 From: GitBox To: commits@airflow.apache.org Subject: [GitHub] ashb commented on a change in pull request #3661: [AIRFLOW-2780] Adds IMAP Hook to interact with a mail server Message-ID: <153675422294.10386.1227272149875336186.gitbox@gitbox.apache.org> Date: Wed, 12 Sep 2018 12:10:22 -0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit ashb commented on a change in pull request #3661: [AIRFLOW-2780] Adds IMAP Hook to interact with a mail server URL: https://github.com/apache/incubator-airflow/pull/3661#discussion_r217002543 ########## File path: airflow/contrib/hooks/imap_hook.py ########## @@ -0,0 +1,262 @@ +# -*- coding: utf-8 -*- +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import email +import imaplib +import re + +from airflow import LoggingMixin +from airflow.hooks.base_hook import BaseHook + + +class ImapHook(BaseHook): + """ + This hook connects to a mail server by using the imap protocol. + + :param imap_conn_id: The connection id that contains the information + used to authenticate the client. + The default value is 'imap_default'. + :type imap_conn_id: str + """ + + def __init__(self, imap_conn_id='imap_default'): + super(ImapHook, self).__init__(imap_conn_id) + self.conn = self.get_connection(imap_conn_id) + self.mail_client = imaplib.IMAP4_SSL(self.conn.host) + + def __enter__(self): + self.mail_client.login(self.conn.login, self.conn.password) + return self + + def __exit__(self, exc_type, exc_val, exc_tb): + self.mail_client.logout() Review comment: Does this also disconnect? If not it probably should. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: users@infra.apache.org With regards, Apache Git Services