&=dTddlZddlZddlZddlZddlmZmZmZmZddl Z ddl Z ddl Z ddl m Z ddlmZddlmZddlmZddlmZddlmZddlZd d lmZmZd d lmZmZmZd d l m!Z!d d l"m#Z"d dl$m%Z%dZ&d'de(ddDZ)ej*dej+e)zdzZ,ej*dej+e)zdzZ-dZ.d"dZ/dZ0d#dZ1 d$d!Z2dS)%N)runPopenSTDOUTPIPE) MIMEMultipart)MIMEText) MIMEAudio) MIMEImage)MIMEBase) MIMEMessage)VERSIONVERSION_NUMBER)TempFileopen_write_safetempfile_prefix) NoMessage)text_ui)get_email_addrFc,g|]}t|S)chr).0ais 2/usr/lib/python3/dist-packages/reportbug/submit.py r0s8882s2ww888 z[^]z\s]c,tp tj|SN)quietlyui log_message)argss rewriter(7s  +bnd++rxgpgc|st|d}tt|d|\}}|||tt|d|\}} ||dkr`t j| dt jvrd|z} nd|z} | d tj | zd ztj |zz } n7d |z} | d tj |zd ztj | zz } t j | t| dd5} | } dddn #1swxYwYt j |rt j|t j | rt j| | st| }ns#tt f$r_tt||\} }| || t#d|d}YnwxYw|S)a Sign message with pgp key Parameters ---------- body : str body of the message to be signed fromaddr : str email address of the sender. Ignored if pgp_addr is given. package : str, optional name of the package affected by the bug pgp_addr : str, optional email address identifying the ID with which to sign the message sign : str, optional if set to 'gpg', GnuPG is used for signing, otherwise PGP draftpath : str, optional directory to use for creating temporary files Returns ------- str a signed message body, or None if signing did not work. r unsignedprefixdirsignedr*GPG_AGENT_INFOz"gpg --local-user '%s' --clearsign z.gpg --local-user '%s' --use-agent --clearsign z --output  zpgp -u '%s' -fastrbackslashreplace)errorsNz!gpg/pgp failed; input file in %s )rrrwritecloseosunlinkenvironshlexquotesystemopenreadpathexistsrOSErrorr()bodyfromaddrpackagepgp_addrsign draftpathr,file1r0file2signcmdr) signedbodyfhtmpfile2s r sign_messagerP;s0 /!(++A.!(L(LR[\\\Xu NN4 NNogx&H&HiXXXOVU LLNNN u}} % 2: - -:XEGGFQG;U!3!33c9EK>%   Ie    7>>%   Ie    O w w'?'?YOOO H   3X>>>  Ks87&G;E>2 G;>FG;FA4G;;A-I+*I+ct|}|dkrVtd|Ddkr'tj||d=d|d<|S)Nus-asciic34K|]}t|VdSr#)len)rlns r z$_MIMEText_wrapper..s(44BB444444rizContent-Transfer-Encodingzquoted-printable)rget_content_charsetmax splitlinesemailencoders encode_quopri)textmsgs r_MIMEText_wrapperr_s 4..C    J.. 44$//"3"3444 4 4s : : $$S))) + ,+= '( JrcRtjtd}t|}|ddd|_d|_||d}|D]} t|}| n/#t$r"} td|| j d}Yd } ~ Od } ~ wwxYwd } td d d d |gttdd} | r5t%jd| } | r| \} } }d| vrd } | stj|d\} }| sd} | dd\}}|dkr t|d5}t|}d d d n #1swxYwYn#t0$rt3||}t|d5}||d d d n #1swxYwYt6j|YnywxYw|dkrMt|d5}t=t7j||}d d d n #1swxYwYn"|dkrLt|d5}tA||}d d d n #1swxYwYn|dkrLt|d5}tC||}d d d n #1swxYwYn~t3||}t|d5}||d d d n #1swxYwYt6j||ddtDj#$|||||fS)a Compose a Multipart MIME message from body text and attachments Parameters ---------- body : str message body text attachments : [str, ...] list of files to attach charset ignored body_charset unused Returns ------- (email.Message, bool) Tuple with MIME multipart message and a bool indicating whether an error occurred when attaching files (False means no errors) mixedzContent-Dispositioninlinez6This is a multi-part MIME message sent by reportbug. rFz"Warning: opening '%s' failed: %s. TNfilez--mimez--briefz --dereference)stdoutstderrrasciiz([^;, ]*)(,[^;]+)?(?:; )?(.*)/)strictzapplication/octet-streamr r]r4rbmessage)_subtypeimageaudio attachment)filename)% mimetypesinitrr_ add_headerpreambleepilogueattachr?r8EnvironmentErrorr(strerrorrrr communicatedecoderematchgroups guess_typesplitr@UnicodeDecodeErrorr set_payloadrZr[ encode_base64r message_from_binary_filer r r9rAbasename)rD attachmentscharset body_charsetrjbodypartfailedrnfpr)ctypeinfor{junkextrasencodingmaintypesubtypeparts r mime_attachrs*NG$$G &&H -x888QGG NN8 F!55  j!!B HHJJJJ    8*:   F HHHH   fh ?JO 1111<qBBH&//  !H=tDDE !&+llnn#tVe## E *'25***OE8 /.E!KKQ//' v   3*c**8b,RWWYY77D888888888888888% 3 3 3'22*d++0r$$RWWYY///000000000000000,,T22222  3  " "j$'' 52"5#A"#E#E,3555 5 5 5 5 5 5 5 5 5 5 5 5 5 5 5 j$'' >2 W=== > > > > > > > > > > > > > > >  j$'' >2 W=== > > > > > > > > > > > > > > >Hg..Dj$'' ,2  +++ , , , , , , , , , , , , , , , N ( ( . . . -|!#!1!1*!=!=  ? ? ?t V s3#B C!B>>C G"G< GG GG G*I!?(H3' I!3H7 7I!:H7 ;"I! I!:$J**J. 1J. $K==L L $MM M ;(N//N3 6N3 rRTdebbugs localhostcdx}}d}|r|rd}|r|dkrd}d}t|}|r/|s-t||| |\} }|rtddx}x}}nt|} || d<|| d <|D] \}!}"|"| |!< |r|| d <|r|| d <tjd |}|r|| d <| rPtj d| d<t| d<tj d| d<n|r|s |s t| d<d| d g| d gz| d gzD}#tj|#}$d| dgD}%tj|%}&|%r| d=d|%}'|'| d<|s|s | d =n#t $rYnwxYw| } |r4|s2|s0t%j| dt%jdddsdx}}d}(|s|rt*j})nJ|rt/||\})}(n2|rtj|}tj|r; t j||dzn!#t8$rtd||YnwxYw t;|d })n#t8$r-t/||\}*}+td!||+|+}|*})YnnwxYw|rtj|s|st/||\})}n1|r.tj|r|s t j},n$#t8$rt jd"YnwxYwd#|$D}-d$|-}.tj |d%}/|&tj |d%}0n|/}0td&||0dkrt j!|d'|.d })n/t j!|d(tEj#|0d'|.d })d}t/t||\}1}2|1$| |1%|rWd)|$D}3d}4d}5d*}6|4rd}4td+| d}7|&dkrtOj(|d,}7n@|)d-rd}tOj*|}7ntOj(|}7|7+}8d.|8d*cxkrd/ksn|7,|rQ|7-|7+}8d.|8d*cxkrd/ksn|7,|r3|st%j.d0|d1|d2}|7/|||70||3| }5|71n#tdj3tNj4f$rp},tk|,tNj6r&td3d}4d}|6d%z }6|6d4krYd},~,d}4t%jd5|,d6d7d8rd}4Yd},~,d}|2}Yd},~,nd},~,wwxYw|4|5r:|57D]#\}9}:td9|9|:d*|:d%$|2}n |)$| |)8n&#t8$rd}|)%YnwxYw|s|)%r|rd}|2}t%j9d:|rtd;|j:|;|(|};d*}< |j<st{|;d<j>}}=d?}>d@dAdB}?t%j@|=|>|?},|,dCkrd}|2}nsn|s|s|r|rtdD|ntdE|g}@|$D]F}9|9d%tj |d%kr|@A|9Gt|@r$tdF|#D]}AtdG|A|&r*| dHkr$tdI|%D]}AtdG|A|(rdtj|rEtj|(r& t jC|(n#t $rYnwxYw|2|kr& t jC|2n#t $rYnwxYw|r7tj|rt%jDdJ|nK| sI|sG| dHkrA| r?dK| vr;|s9| r7tdLt%jEdM| dKdNz| dKdOzdS)Pa Send a report This function handles all variants supported by reportbug of 'sending' a report, including: - passing to a local MUA (mutt, thunderbird, evolution etc.), - submitting through a remote smarthost, - passing to a local MTA (exim, sendmail etc.), - saving to a file, - piping the message to standard output. Parameters ---------- body : str message body text attachments : [str, ...] list of files to attach mua : reportbug.utils.Mua() mail user agent to use for submitting the report fromaddr : str Mail address to use in the From: header sendto : str recipient address ccaddr : str mailaddress to put in CC: header bccaddr mailaddress to put in BCC: header headers : [(str, str), ...] list of (header, value) tuples package : str, optional name of the package the report is about charset : str, optional passed to mime_attach mailing : bool, optional if True, create Message-ID, X-Mailer and Date headers sysinfo : dict, optional dictionary with system info rtype : str, optional should be 'debbugs' for best results exinfo : str or bool, optional whether the message is extra info on an existing bug (followup) or not replyto : str, optional mailaddress to put in Reply-To: header. If there is REPLYTO environment variable, the value of the variable will be used instead. printonly : bool, optional if True, do not send the report, just print it to standard output template : bool, optional if True, do not send the report, just print it to standard output (same effect as `printonly`) outfile : str, optional name of a file to which to write the message mta : str, optional path of a mail transfer agent to use kudos : bool, optional if True, indicates the message is meant as appreciation mail to the maintainer rather than bug information smtptls : bool, optional if True, try to use TLS during submission to smtp host smtphost : str, optional host name of the SMTP host smtpuser : str, optional user name to use for authentication at the SMTP host smtppasswd : str, optional password to use for authentication at the SMTP host paranoid : bool, optional if True, view the report in a pager again and ask for confirmation before finally submitting draftpath : str, optional directory where to store temporary files envelopefrom : str, optional sender address to use in envelope when using a local mta Returns ------- None Frzreportbug.debian.orgzpackages.debian.orgzutf-8z,Error: Message creation failed, not sending NFromToCcBccREPLYTOzReply-To reportbugz Message-IDzX-MailerT) localtimeDatezX-Reportbug-Versionc,g|]}t|Srstrrr)s rrzsend_report..ls* = = =SVV = = =rc,g|]}t|Srrrs rrzsend_report..qs B B Bc!ff B B Brz X-Debbugs-Ccz, )presubjz"Does your report seem satisfactoryz Yes, send it.zNo, don't send it.r-~z$Unable to rename existing %s as %s~ wz'Writing to %s failed; using instead %s rgcBg|]}tj|dSr )r<r=)ras rrzsend_report..s&333%+ad##333rr2r zSending message via %s... z -oi -oem z -f cg|] }|d Srrrs rrzsend_report..s'''A1Q4'''rrzConnecting to %s via SMTP... iKz:465i+zEnter SMTP password for @z: z/SMTP error: authentication failed. Try again. zSMTP send failure: zC. You can retry, or save the report and exit. Do you want to retry?zYes, please retry.zNo, save and exit.z#Unable to send report to %s: %d %s z>Error: send/write operation failed, bug report will be saved. zSpawning %s... )shellzMMutt users should be aware it is mandatory to edit the draft before sending. z9Report has not been sent yet; what do you want to do now?EqzEdit the message.z3Quit reportbug; will save the draft for future use.)eqrz Message sent to: %s z Bug report submitted to: %s zCopies sent to: z %s rz)Copies will be sent after processing to: z_Bug report written to a temporary file. You can resume the unsent report using: reportbug -r rZ aIf you want to provide additional information, please wait to receive the bug tracking number via email; you may then send any extra information to %s (e.g. %s), where n is the bug number. Normally you will receive an acknowledgement via email including the bug report number within an hour; if you haven't received a confirmation, then the bug reporting process failed at some point (reportbug or MTA failure, BTS maintenance, etc.). nnnnnnn)Frrr(r_r9r;getrZutils make_msgidr formatdaterget_all getaddressesjoin Exception as_stringr%display_reportyes_nosysrdrrA expanduserrBrenamerCrgetcwdchdir parseaddrpopenr<r=r7r8lowersmtplibSMTPendswithSMTP_SSLehlohelostarttls get_passwordloginsendmailquitsocketerror SMTPException isinstanceSMTPAuthenticationErroritemsflushdisplay_failure executableget_send_commandneeds_terminalr returncoder>select_optionsappendrTr: long_message final_message)BrDrmuarEsendtoccaddrbccaddrheadersrFrmailingsysinfortypeexinforeplyto printonlytemplateoutfilemtakudossmtptlssmtphostsmtpuser smtppasswdparanoidrI envelopefromrusing_sendmailmsgnamertfprefixrjheadervalueaddrsalistcclist debbugs_ccaddrlistropiperN newmsgnamer)malistjalistfaddrenvfrombackupfh backupnametoaddrstryagainrefusedretryconnresponseaddrerrsendcmd returnvaluemtitlemopts moptsdesc addressesaddresssB r send_reportrs l$#F^G x )333(Lw''H*3*'k7LQQ&  ( B C C C#' 'C '##D))GFOGDM"    ! jnnY00G&% 8 % 6 6{ C C % +0040@@ 8i888)7%& = =goodB77 'b 9 9: 'r : :; = = =E K $ $U + +E B BgoonbAA B B BF))&11J + N #99V$$"* 3     D !!G""Y" '40000y=.00 "! !HsH-9-z +!yAAAhh )'$$W-- 7>>' " " ) ) '7S=1111 ) ) )>))))) ) "7C00DD   %X9EEENB ()0* > > > GDDD rw~~c**x i@@@ gg "'..%%x  AA    HSMMMMM 43U333&!! %%h//2  #k++L99! > >0 )>>##'==="<#66DD&&v..2"G"+H55DD"<11D99;;x{1111c1111IIKKK$MMOOO#yy{{H8A;5555#5555 5%2%'__%XXxxx1&2&2 JJx444--'7CC L'"78 ) ) )a!@AA)MNNN#H!%JQJEzz #(9y1yyy1133) $HHHHH!F(GGGGGG) )?3 )l  !&}}   s=tSV1v G  JJw    JJLLLL   F JJLLLLL   bdjjll b~ bF G  ` a a a **!3>222&&x==  % 1!'666A  i00 a c d d dPFE1SUUI!&%;;ACxx$# &**8*  > ,f 5 5 5 5 4f = = =  ' 'DAw%+//77:::  &&& y>> * & ' ' '  * *x))))  *%9,, ? @ @ @! * *x))))BGNN7++x0H0H  Ih        D W  Ij ! ! ! !    D E27>>'**E 4*144 5 5 5 5 E E5I#5#5'#5gQXFXFXagFXGYt   $W  #ww'7('B E E E Fs&G** G76G71K K('K(,K>>3L54L5N,,O  O E Y88\8[>[>5[>>\)]11 ^^?f f! f!+g g  g )r)Nr*Nr#)r)rRTNrNNFFNrFFrNNFNN)3rr9rzr< subprocessrrrrrZrremail.mime.multipartremail.mime.textremail.mime.audior email.mime.imager email.mime.baser email.mime.messager rp__init__rr tempfilesrrr exceptionsrr%rrrr$rrange ascii_rangecompileescapenotascii notascii2r(rPr_rrrrrr)sf, ////////////  ......$$$$$$&&&&&&&&&&&&$$$$$$******--------AAAAAAAAAA!!!!!! gg88r388899 2:eibi 444s: ; ; BJuyry555> ? ? ,,,BBBBJ"TTTTpCGFK