File: //opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/__pycache__/mail_helper.cpython-311.pyc
�
K�f� � � � d dl mZmZmZ d dlZd dlZd dlZd dlZd dl Z d dl
mZm
Z
d dlmZ d dlmZ d dlmZ dZ G d� d e� � Z G d
� d� � ZdS )� )�absolute_import�division�print_functionN)�base� multipart)�
SysLogHandler)�Optional)�errorzAleksandr Shyshatskyc � � e Zd ZdS )�MailSendFailedN)�__name__�
__module__�__qualname__� � ��/builddir/build/BUILDROOT/alt-python27-cllib-3.4.8-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/mail_helper.pyr r s � � � � � ��Dr r c � � e Zd ZdZd� Zddej dee fd�Z ddee fd�Z
dedej fd �Z
ddee fd
�ZdS )�
MailHelperz6Common class to send emails via local smtp or sendmailc �� � t j j s�t j � d� � r�t
dt j �� � }t j � |� � t j d�� � }|�
|� � |� t j � � nt j
� � t j � � | _ d S )Nz/dev/log)�address�facilityz3mail_helper: (%(name)s) [%(levelname)s] %(message)s)�fmt)�logging�root�handlers�os�path�existsr �
LOG_DAEMON�
addHandler� Formatter�setFormatter�setLevel�ERROR�basicConfig� getLogger�_log)�self�SYS_LOG�
formatter_syss r �__init__zMailHelper.__init__! s� � ��|�$� &��w�~�~�j�)�)�
&�'�
�]�E]�^�^�^����'�'��0�0�0� '� 1�6k� l� l� l�
��$�$�]�3�3�3�� � ���/�/�/�/��#�%�%�%��%�'�'�� � � r N�msg�
encoding_namec �� � |r(|� � � � |� � }n|� � � }g d�}t j |t j t j t j d�� � }|� |� � d }|j dk rt j |j ||� � �dS # t t j f$ r!}t t |� � � � �d}~ww xY w)z�
Alternative function that should be called
when we cannot send email via smtp
:type msg: email.mime.base.MIMEBase
:type encoding_name: encoding name to encode message text
)z/usr/sbin/sendmailz-tz-oiT)�stdin�stdout�stderr�textr N)� as_string�encode�
subprocess�Popen�PIPE�communicate�
returncode�CalledProcessError�OSErrorr �str)r( r, r- � s_message�cmd�pr0 �exs r �_sendmail_consolezMailHelper._sendmail_console- s� � � *��
,��M�M�O�O�2�2�=�A�A� � ��M�M�O�O� �5�5�5�C�� ��J�O�(2��(2��&*�,� ,� ,�A� �]�]�9�-�-�a�0�F��|�q� � � �3�A�L�#�v�N�N�N� !� �� ��6�7� *� *� *� ��R���)�)�)����� *���s �B:B>