fjddlZddlZddlZddlZddlmZmZddlmZddl m Z ddl m Z ddl mZddlmZmZdd lmZhd ZGd d ZdS) N) ConfigParser SectionProxy) EmailMessage) gethostname)Optional)gettext)mail_template_locationmail_scripts_location)XRayMailerError>PleskcPanel DirectAdminceZdZdZdZedefdZedefdZ defdZ de efdZ de efdZ edd edefd Zd edd fdZd edd fdZdedd fdZ ddededd fdZd S)Mailerz0 Class contains X-Ray e-mail send logic cFtjd|_d|_dS)Nmailer)logging getLoggerlogger_senderselfs M/opt/cloudlinux/venv/lib64/python3.11/site-packages/xray/continuous/mailer.py__init__zMailer.__init__s'11  returncdS)z+ Local mail server address ) localhostrs r mail_serverzMailer.mail_server!s rcP|j||_|jS)zG Retrieve 'From' mail address if it is not already set )rretrieve_mail_senderrs rsenderz Mailer.sender(s' < 4466DL|rcXdt}|}||n|S)zC 'From' address (control panel admin or dummy one) zxray.continuous@)r admin_email)r dummy_mail admin_mails rr#zMailer.retrieve_mail_sender1s58 77 %%'' '3zzCrc|}|td|d} tj|gddd}|jS#tj$r4}|jd|t|Yd}~dSd}~wtttj f$r4}|jd|t|Yd}~dSd}~wwxYwdS)z< Try to retrieve control panel admin e-mail N/_emailT)capture_outputtextcheckz% script failed with: %sz Failed to run script %s with: %s) get_control_panelr subprocessrunstdoutstripCalledProcessErrorrerrorstrOSError ValueErrorSubprocessError)rpanelget_email_scriptpes rr&zMailer.admin_email9sE&&((  "7GG%GGG  <N$4#526TOOOx~~'''0 < < < !!"<"2CFF<<<<<<<<<Z)CD < < < !!"D"2CFF<<<<<<<<< <  s#1AC(&)BC(4)C##C(c tjddgdddj}|tvr|jd|dS|S#tjtf$r3}|jdt|Yd}~dSd}~wtttj f$r3}|jdt|Yd}~dSd}~wwxYw) z( Get control panel name cldetectz--detect-cp-nameT)r.r-r,zUnknown control panel name: %sNzcldetect utility failed with %sz&Failed to run cldetect utility with %s) r0r1r2r3 KNOWN_PANELSrr5r4AttributeErrorr6r7r8r9)rr:r=s rr/zMailer.get_control_panelKs= &N/0#%%%&,EEGG L(( !!"BEJJJtL-~> & & & K  ?!!ff & & & & & & & & &Z%?@ & & & K  F!!ff & & & & & & & & & &s*AAAC11(BC1>(C,,C1greetingnamectd|d}tj|r-t d}|||dSt td|t)zF Get preformatted data for e-mail by name of template r*z.iniN) interpolationdataz Failed to find template {} in {}) r ospathexistsrreadr _format)rCtmplconfigs r read_templatezMailer.read_template_s )554555 7>>$   "!555F KK   &> !a B I I$Pf g ghhiiirmessageNc|jd tj|j5}||}|jd|ddddS#1swxYwYdS#tj$r$}tdt|d}~wttf$r1}ttdt|zd}~wwxYw)z= Send preformatted e-mail via localhost SMTP zTry to send via smtpzSend result: %sNzsmtp mailing failed: zsmtp connection failed: %s) rinfosmtplibSMTPr! send_message SMTPExceptionr r6ConnectionErrorr7rK)rrPserverresultr=s r _smtp_sendzMailer._smtp_sendksC /000 Lt/0 %s) rOrr$ set_contentadd_alternativerrRr]rd)rrerfkwargsrFmsgs r send_mailzMailer.send_mails!!(++nniIkF D  V v-... DL616BBB 0#--//BBB 3r)rB)__name__ __module__ __qualname____doc__rpropertytupler!r6r$r#rr&r/ staticmethodrrOrrZr_rdrqr rrrrsUX XDcDDDDrs 33333333&&&&&&NNNNNNNN111111211 NNNNNNNNNNr