%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /opt/alt/python37/lib/python3.7/site-packages/ssa/internal/__pycache__/
Upload File :
Create Path :
Current File : //opt/alt/python37/lib/python3.7/site-packages/ssa/internal/__pycache__/mailer.cpython-37.pyc

B

r�b�@s�dZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZddlm
Z
ddlmZmZdd	lmZdd
lmZddlmZmZeed�d
d�ZGdd�d�ZdS)z8
This module contains SSA Mailer class and helper tools
�N)�ConfigParser�SectionProxy)�EmailMessage)�gethostname)�is_cl_solo_edition)�Environment�FileSystemLoader�)�mail_template_location)�SSAMailerError)�
duration_cast�format_date)�report_data�returncCsfttt�ddd�}t|jd<|�d�}|j|dtdd�d�}|�d�}|jt|d	�|d
�}||fS)zJ
    Render an HTML table for e-mail report and a full e-mail message
    T)�loaderZtrim_blocksZ
lstrip_blocksrzreport_table.html�domains)�skip_jwt_check)rZis_soloz	mail.html�date)r�report_table)	rrr
r�filtersZget_templateZrenderrr
)r�envZtable_templaterZ
mail_template�mail�r�D/opt/alt/python37/lib/python3.7/site-packages/ssa/internal/mailer.py�render_report_tables



rc@s�eZdZdZdd�Zeed�dd��Zeed�dd��Z	e
eed	�d
d��Ze
dd
�dd�Ze
dd
�dd�Ze
dd�dd�Zdeedd�dd�Zeee
d�dd�ZdS)�Mailerz.
    Class contains SSA e-mail send logic
    cCst�d�|_d|_dS)NZmailer)�logging�	getLogger�loggerZ_sender)�selfrrr�__init__6szMailer.__init__)rcCsdS)z+
        Local mail server address
        )�	localhostr)rrrr�mail_server:szMailer.mail_servercCsdt���S)z%
        'From' mail address
        zslow-site-analyzer@)r)rrrr�senderAsz
Mailer.sender)�namercCsPt�d|�d�}tj�|�r8tdd�}|�|�|dStd|�dt����dS)zF
        Get preformatted data for e-mail by name of template
        �/z.iniN)�
interpolation�datazFailed to find template z in )r
�os�path�existsr�readr)r$Ztmpl�configrrr�
read_templateHs

zMailer.read_templateN)�messagerc
Cs�|j�d�y4tj|j��}|�|�}|j�d|�WdQRXWnltjk
rv}ztdt|�����Wdd}~XYn8t	t
fk
r�}ztdt|�����Wdd}~XYnXdS)z=
        Send preformatted e-mail via localhost SMTP
        zTry to send via smtpzSend result: %sNzsmtp mailing failed: zsmtp connection failed: )r�info�smtplibZSMTPr"Zsend_messageZ
SMTPExceptionr�str�ConnectionError�OSError)rr.�server�result�errr�
_smtp_sendUs
"zMailer._smtp_sendc
Cst|j�d�dddg}ytj||��dddd�Wn<tttjfk
rn}ztdt	|�����Wdd}~XYnXdS)	z?
        Send preformatted e-mail via sendmail utility
        z Try to send via sendmail utilityz/usr/sbin/sendmailz-tz-oiT)�input�capture_output�text�checkzsendmail utility failed with N)
rr/�
subprocess�run�	as_stringr3�
ValueError�CalledProcessErrorrr1)rr.�cmdr6rrr�
_console_sendcs
zMailer._console_send)rrc
Cs�y|�|�Wn�tk
r�}zh|j�t|��y|�|�WnDtk
r�}z&|j�t|��|j�d|d�Wdd}~XYnXWdd}~XYnXdS)zm
        Try to send mail via localhost smtp server,
        if fails -- try to use sendmail utility
        z3Both smtp and sendmail failed to send message to %s�ToN)r7rr�errorr1rB�critical)rrr6rrr�_sendqszMailer._send�
ssa_report)�	recipient�templatercKs|�|j||f|��dS)z{
        Create a message from given template, including additional kwargs,
        and send it to given recipient
        N)rF�_message)rrHrI�kwargsrrr�send_simple_mail�szMailer.send_simple_mailcKsp|�|�}t�}|d||d<|j|d<||d<|�|d|�|j|d|dd�|j�d|���|S)	z 
        Form a message
        �subjectZSubjectZFromrCr:�html)�subtypezGenerated mail --> %s)r-rr#�set_content�add_alternativerr/r>)rrHrIrKr'�msgrrrrJ�s

zMailer._message)rG)�__name__�
__module__�__qualname__�__doc__r �property�tupler"r1r#�staticmethodrr-rr7rBrFrLrJrrrrr1s r)rVrr(r0r<�configparserrr�
email.messager�socketr�clcommon.lib.cleditionrZjinja2rr�	constantsr
�
exceptionsr�utilsrr
�dictrXrrrrrr�<module>
s

Zerion Mini Shell 1.0