HEX
Server: Apache
System: Linux insrv.serversdaddy.com 5.14.0-362.24.2.el9_3.x86_64 #1 SMP PREEMPT_DYNAMIC Sat Mar 30 14:11:54 EDT 2024 x86_64
User: jsaha (1066)
PHP: 8.3.6
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //opt/alt/python37/lib/python3.7/site-packages/clcommon/__pycache__/mail_helper.cpython-37.pyc
B

�䥣ݿD�@s�ddlmZmZmZddlZddlZddlZddlZddl	Z	ddl
mZm
Z
ddlmZddlmZddlmZdZGdd	�d	e�ZGd
d�d�ZdS)�)�absolute_import�division�print_functionN)�base�	multipart)�
SysLogHandler)�Optional)�errorzAleksandr Shyshatskyc@seZdZdS)�MailSendFailedN)�__name__�
__module__�__qualname__�rr��/builddir/build/BUILDROOT/alt-python27-cllib-3.4.1-1.el9.cloudlinux.x86_64/opt/alt/python37/lib/python3.7/site-packages/clcommon/mail_helper.pyr
sr
c@sjeZdZdZdd�Zdejeed�dd�Z	deed�d	d
�Z
eejd�dd
�Z
deed�dd�ZdS)�
MailHelperz6Common class to send emails via local smtp or sendmailcCshtjjsZtj�d�rRtdtjd�}tj�|�tj	dd�}|�
|�|�tj�nt�
�t��|_dS)Nz/dev/log)ZaddressZfacilityz3mail_helper: (%(name)s) [%(levelname)s] %(message)s)Zfmt)�logging�rootZhandlers�os�path�existsrZ
LOG_DAEMONZ
addHandlerZ	FormatterZsetFormatterZsetLevelZERRORZbasicConfigZ	getLogger�_log)�selfZSYS_LOGZ
formatter_sysrrr�__init__!s
zMailHelper.__init__N)�msg�
encoding_namec
Cs�yl|r|���|�}n|��}dddg}tj|tjtjtjdd�}|�|�d}|jdkrjt�|j||��Wn4ttjfk
r�}zt	t
|���Wdd}~XYnXdS)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�textrN)�	as_string�encode�
subprocess�Popen�PIPEZcommunicate�
returncodeZCalledProcessError�OSErrorr
�str)rrr�	s_message�cmd�pr�exrrr�_sendmail_console-s


zMailHelper._sendmail_console)rc
Cszy@t�d�}|r |���|�}n|��}|�|||�|��Wn4tjtfk
rt}ztt	|���Wdd}~XYnXdS)z�
        Send email using smtp protocol;
        :type from_addr: str
        :type to_addrs: List[str]
        :type msg: email.mime.base.MIMEBase
        :type encoding_name: encoding name to encode message text
        Z	localhostN)
�smtplibZSMTPrr �sendmail�quitZ
SMTPException�socketerrorr
r&)r�	from_addr�to_addrsrrZ
smtp_instancer'r*rrr�_sendmail_smtpEs
zMailHelper._sendmail_smtp)r0rcCs:|ds6tjj|�d�dd�|d<|j�d|d�dS)z{Add Message-ID to message if it is missing
        :type from_addr: str
        :type msg: multipart.MIMEMultipart
        z
Message-ID�@���)ZdomainzAdded Message-ID: %sN)�emailZutilsZ
make_msgid�splitr�debug)rr0rrrr�_add_message_idXszMailHelper._add_message_idcCs�|j�d|||�|�||�y|�||||�Wnntk
r�}zP|j�d�y|�|�Wn0tk
r�|j�d�|j�t|��YnXWdd}~XYnXdS)a0
        Try to send message using local smtp;
        If that can't be done - try to use /usr/sbin/sendmail;
        :type from_addr: str
        :type to_addrs: List[str]
        :type msg: multipart.MIMEMultipart
        :type encoding_name: Optional[str] encoding name to encode message text
        z+Trying to send mail with params: %s, %s, %sz-Smtp send failed, trying to send via sendmailzcCannot send email neither via smtp nor using sendmail; Please, check your mail server configurationN)	rr7r8r2r
r+Z	exceptionr	r&)rr0r1rrZsmtp_exceptionrrrr-as	zMailHelper.sendmail)N)N)N)rrr
�__doc__r�	mime_baseZMIMEBaserr&r+r2rZ
MIMEMultipartr8r-rrrrrs	r)Z
__future__rrrZemail.utilsr5rrr,r!Z
email.mimerr:rZlogging.handlersr�typingrZ_socketr	r/�
__author__�	Exceptionr
rrrrr�<module>
s