$FidZddlZddlZddlZddlZddlmZmZddlm Z ddl m Z ddl m Z ddlmZmZmZddlmZd d lmZd d lmZd d lmZmZd ZdedefdZGddZdS)z8 This module contains SSA Mailer class and helper tools N) ConfigParser SectionProxy) EmailMessage gethostname)is_cl_solo_edition) EnvironmentFileSystemLoaderselect_autoescape get_ip_addr)mail_template_location)SSAMailerError) duration_cast format_datec$t|pdS)NUNKNOWNr )hostnames J/opt/cloudlinux/venv/lib64/python3.11/site-packages/ssa/internal/mailer.py_get_server_iprs x -I- report_datareturnc tttddtddg}t|jd<|d}||dtd }|d }t}|t|d ||t| }||fS) zJ Render an HTML table for e-mail report and a full e-mail message Thtmlxml)loader trim_blocks lstrip_blocks autoescaperzreport_table.htmldomains)skip_jwt_check)r"is_soloz mail.htmldate)r% report_tablerip_addr) r r rr rfilters get_templaterenderrrrr)renvtable_templater& mail_templatermails rrender_report_tabler/s  677$fe_55    C $1CK %%&9::N!((Y1G1C<@2B2B2B)CCL $$[11M}}H   [V1D%E%E-9)1(6x(@(@  B BD  rceZdZdZdZedefdZedefdZ e dede fdZ de dd fd Zde dd fd Zd e dd fd Z ddededd fdZdedede fdZd S)Mailerz. Class contains SSA e-mail send logic cFtjd|_d|_dS)Nmailer)logging getLoggerlogger_senderselfs r__init__zMailer.__init__?s'11  rrcdS)z+ Local mail server address ) localhostr8s r mail_serverzMailer.mail_serverCs ~rc$dtS)z% 'From' mail address zslow-site-analyzer@rr8s rsenderz Mailer.senderJs 5[]]444rnamectd|d}tj|r-t d}|||dSt d|dt)zF Get preformatted data for e-mail by name of template /z.iniN) interpolationdatazFailed to find template z in )rospathexistsrreadr)rAtmplconfigs r read_templatezMailer.read_templateQs )554555 7>>$   "!555F KK   &> ! It I I1G I IKK KrmessageNc|jd tj|j5}||}|jd|ddddS#1swxYwYdS#tj$r$}tdt|d}~wttf$r$}tdt|d}~wwxYw)z= Send preformatted e-mail via localhost SMTP zTry to send via smtpzSend result: %sNzsmtp mailing failed: zsmtp connection failed: ) r6infosmtplibSMTPr> send_message SMTPExceptionrstrConnectionErrorOSError)r9rMserverresultes r _smtp_sendzMailer._smtp_send^s> /000 Ft/0 %s)rLrr@ set_contentadd_alternativer6rOrb)r9rmrnrqrEmsgs rrpzMailer._messages!!(++nni61IkF D  V v-... DL616BBB 0#--//BBB r)rl)__name__ __module__ __qualname____doc__r:propertytupler>rTr@ staticmethodrrLrrZrfrkrrrpr=rrr1r1:sUX 5555X5  KC KL K K K\ K F, F4 F F F F K\ Kd K K K K , 4    &*6AA$'A#&A'+AAAA+rr1) r~r4rFrPr` configparserrr email.messagersocketrclcommon.lib.cleditionrjinja2r r r clcommon.lib.networkr constantsr exceptionsrutilsrrrdictrr/r1r=rrrs_ 33333333&&&&&&555555CCCCCCCCCC,,,,,,------&&&&&&--------...Te6mmmmmmmmmmr