
    &=dT                        d dl Z d dlZd dlZd dlZd dlmZmZmZmZ d dl	Z	d dl
Z
d dlZd dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d dlZd	d
lmZmZ d	dlmZmZmZ d	dl m!Z! d	dl"m#Z" d	dl$m%Z% dZ&d'                    d  e(dd          D                       Z) ej*        d ej+        e)          z   dz             Z, ej*        d ej+        e)          z   dz             Z-d Z.d"dZ/d Z0d#dZ1	 	 	 	 	 	 	 d$d!Z2dS )%    N)runPopenSTDOUTPIPE)MIMEMultipart)MIMEText)	MIMEAudio)	MIMEImage)MIMEBase)MIMEMessage   )VERSIONVERSION_NUMBER)TempFileopen_write_safetempfile_prefix)	NoMessage)text_ui)get_email_addrF c                 ,    g | ]}t          |          S  )chr).0ais     2/usr/lib/python3/dist-packages/reportbug/submit.py
<listcomp>r   0   s    8882s2ww888           z[^]z\s]c                  ,    t           pt          j        |  S N)quietlyuilog_message)argss    r   ewriter(   7   s    +bnd++r   xgpgc                    |st          |          d         }t          t          |d          |          \  }}|                    |            |                                 t          t          |d          |          \  }}	|                                 |dk    r`t          j        |	           dt
          j        vrd|z  }
nd|z  }
|
d	t          j	        |	          z   d
z   t          j	        |          z   z  }
n7d|z  }
|
dt          j	        |          z   dz   t          j	        |	          z   z  }
	 t          j
        |
           t          |	dd          5 }|                                }ddd           n# 1 swxY w Y   t
          j                            |          rt          j        |           t
          j                            |	          rt          j        |	           |st          |} ns# t          t           f$ r_ t          t          |          |          \  }}|                    |            |                                 t#          d|           d} Y nw xY w| 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   unsignedprefixdirsignedr*   GPG_AGENT_INFOz"gpg --local-user '%s' --clearsign z.gpg --local-user '%s' --use-agent --clearsign z	--output  zpgp -u '%s' -fast<z >rbackslashreplace)errorsNz!gpg/pgp failed; input file in %s
)r   r   r   writecloseosunlinkenvironshlexquotesystemopenreadpathexistsr   OSErrorr(   )bodyfromaddrpackagepgp_addrsign	draftpathr,   file1r0   file2signcmdr)   
signedbodyfhtmpfile2s                  r   sign_messagerP   ;   s   0  /!(++A. !(L(LR[\\\XuNN4NN ogx&H&HiXXXOVU
LLNNNu}}
	%2:--:XEGGFQG;U!3!33c9EK<N<NNN%03U+++d2U[5G5GGG
	'%%7888 	"AJ	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 	" 7>>%   	Ie7>>%   	Ie 	Ow   w'?'?YOOOH




3X>>> Ks8   7&G; E>2G; >FG; FA4G; ;A-I+*I+c                     t          |           }|                                dk    rVt          d |                                 D                       dk    r't          j                            |           |d= d|d<   |S )Nus-asciic              3   4   K   | ]}t          |          V  d S r#   )len)r   lns     r   	<genexpr>z$_MIMEText_wrapper.<locals>.<genexpr>   s(      44BB444444r   i  zContent-Transfer-Encodingzquoted-printable)r   get_content_charsetmax
splitlinesemailencodersencode_quopri)textmsgs     r   _MIMEText_wrapperr_      s    
4..C
   J..44$//"3"344444s::$$S))) +,+='(Jr   c                 R   t          j                     t          d          }t          |           }|                    dd           d|_        d|_        |                    |           d}|D ]}	 t          |          }|	                                 n/# t          $ r"}	t          d||	j                   d}Y d	}	~	Od	}	~	ww xY wd	}
t          d
ddd|gt          t                                                    d                             d          }|r5t%          j        d|          }|r|                                \  }
}}d|
vrd	}
|
st          j        |d          \  }
}|
sd}
|
                    dd          \  }}|dk    r	 t          |d          5 }t          |                                          }d	d	d	           n# 1 swxY w Y   n# t0          $ r t3          ||          }t          |d          5 }|                    |                                           d	d	d	           n# 1 swxY w Y   t6          j                            |           Y nyw xY w|dk    rMt          |d          5 }t=          t7          j        |          |          }d	d	d	           n# 1 swxY w Y   n"|dk    rLt          |d          5 }tA          |                                |          }d	d	d	           n# 1 swxY w Y   n|dk    rLt          |d          5 }tC          |                                |          }d	d	d	           n# 1 swxY w Y   n~t3          ||          }t          |d          5 }|                    |                                           d	d	d	           n# 1 swxY w Y   t6          j                            |           |                    ddtD          j#        $                    |                     |                    |           ||fS )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)
    mixedzContent-Dispositioninlinez6This is a multi-part MIME message sent by reportbug.

r   Fz"Warning: opening '%s' failed: %s.
TNfilez--mimez--briefz--dereference)stdoutstderrr   asciiz([^;, ]*)(,[^;]+)?(?:; )?(.*)/)strictzapplication/octet-streamr   r]   r4   rbmessage)_subtypeimageaudio
attachment)filename)%	mimetypesinitr   r_   
add_headerpreambleepilogueattachr?   r8   EnvironmentErrorr(   strerrorr   r   r   communicatedecoderematchgroups
guess_typesplitr@   UnicodeDecodeErrorr   set_payloadrZ   r[   encode_base64r   message_from_binary_filer
   r	   r9   rA   basename)rD   attachmentscharsetbody_charsetrj   bodypartfailedrn   fpr)   ctypeinfor{   junkextrasencodingmaintypesubtypeparts                      r   mime_attachr      s   * NG$$G &&H-x888QGGNN8F! 5 5
	j!!BHHJJJJ 	 	 	8*:  FHHHH		
 fh	?JO 1 1 11<qBBH&// 	 	!H=tDDE !&+llnn#tVe## E 	*'25* * *OE8 	/.E!KKQ//'v3*c** 8b,RWWYY77D8 8 8 8 8 8 8 8 8 8 8 8 8 8 8% 3 3 3'22*d++ 0r$$RWWYY///0 0 0 0 0 0 0 0 0 0 0 0 0 0 0,,T22222	3
 ""j$'' 52"5#A"#E#E,35 5 55 5 5 5 5 5 5 5 5 5 5 5 5 5 5   j$'' >2 W===> > > > > > > > > > > > > > >  j$'' >2 W===> > > > > > > > > > > > > > > Hg..Dj$'' ,2  +++, , , , , , , , , , , , , , ,N((...-|!#!1!1*!=!= 	 	? 	? 	?tVs   3#B
C!B>>C
G"G<GG	GG	G*I!?(H3'I!3H77I!:H7;"I! I!:$J**J.	1J.	$K==L	L	$MM	M	;(N//N3	6N3	rR   Tdebbugs	localhostc                    dx}}d}|r|rd}|r|dk    rd}d}t          |          }|r/|s-t          | ||	|          \  } }|rt          d           dx}x}}nt          |           } || d<   || d	<   |D ]
\  }!}"|"| |!<   |r|| d
<   |r|| d<   t          j                            d|          }|r|| d<   |
rPt          j        	                    d          | d<   t          | d<   t          j                            d          | d<   n|r|s|s
t          | d<   d |                     d	g           |                     d
g           z   |                     dg           z   D             }#t          j                            |#          }$d |                     dg           D             }%t          j                            |%          }&|%r| d= d                    |%          }'|'| d<   |s|s	 | d= n# t           $ r Y nw xY w|                                 } |r4|s2|s0t%          j        | d           t%          j        ddd          sdx}}d}(|s|rt*          j        })nJ|rt/          ||          \  })}(n2|rt          j                            |          }t          j                            |          r;	 t	          j        ||dz              n!# t8          $ r t          d||           Y nw xY w	 t;          |d           })n# t8          $ r- t/          ||          \  }*}+t          d!||+           |+}|*})Y nnw xY w|rt          j                            |          s|st/          ||          \  })}n1|r.t          j                            |          r|s	 t	          j                    },n$# t8          $ r t	          j        d"           Y nw xY wd# |$D             }-d$                    |-          }.t          j                             |          d%         }/|&t          j                             |          d%         }0n|/}0t          d&|           |0dk    rt	          j!        | d'|. d           })n/t	          j!        |d(tE          j#        |0          d'|.d           })d}t/          t          |          |          \  }1}2|1$                    |            |1%                                 |rWd) |$D             }3d}4d}5d*}6|4rd}4t          d+|           	 d}7|&                                dk    rtO          j(        |d,          }7n@|)                    d-          rd}tO          j*        |          }7ntO          j(        |          }7|7+                                }8d.|8d*         cxk    rd/k    sn |7,                                 |rQ|7-                                 |7+                                }8d.|8d*         cxk    rd/k    sn |7,                                 |r3|st%          j.        d0|d1|d2          }|7/                    ||           |70                    ||3|           }5|71                                 n# td          j3        tN          j4        f$ rp},tk          |,tN          j6                  r&t          d3           d}4d}|6d%z  }6|6d4k    rY d},~,d}4t%          j        d5|, d6d7d8          rd}4Y d},~,d}|2}Y d},~,nd},~,ww xY w|4|5r:|57                                D ]#\  }9}:t          d9|9|:d*         |:d%                    $|2}n	 |)$                    |            |)8                                 n&# t8          $ r d}|)%                                 Y nw xY w|s|)%                                r|rd}|2}t%          j9        d:           |rt          d;|j:                   |;                    |(|          };d*}<	 |j<        st{          |;d<          j>        }<nt%          j?        |;          }<|<d*k    rn:t          d=           d>}=d?}>d@dAdB}?t%          j@        |=|>|?          },|,dCk    rd}|2}nsn|s|s|r|rt          dD|           nt          dE|           g }@|$D ]F}9|9d%         t          j                             |          d%         k    r|@A                    |9           Gt          |@          r$t          dF           |#D ]}At          dG|A           |&r*|dHk    r$t          dI           |%D ]}At          dG|A           |(rdt          j                            |          rEt          j                            |(          r&	 t	          jC        |(           n# t           $ r Y nw xY w|2|k    r&	 t	          jC        |2           n# t           $ r Y nw xY w|r7t          j                            |          rt%          jD        dJ|            nK|sI|sG|dHk    rA|r?dK|v r;|s9|
r7t          dL           t%          jE        dM|dK         dNz  |dK         dOz             dS )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
    Fr   zreportbug.debian.orgzpackages.debian.orgzutf-8z,Error: Message creation failed, not sending
NFromToCcBccREPLYTOzReply-To	reportbugz
Message-IDzX-MailerT)	localtimeDatezX-Reportbug-Versionc                 ,    g | ]}t          |          S r   strr   r)   s     r   r   zsend_report.<locals>.<listcomp>l  s*     = = =SVV = = =r   c                 ,    g | ]}t          |          S r   r   r   s     r   r   zsend_report.<locals>.<listcomp>q  s    BBBc!ffBBBr   zX-Debbugs-Ccz, )presubjz"Does your report seem satisfactoryzYes, send it.zNo, don't send it.r-   ~z$Unable to rename existing %s as %s~
wz'Writing to %s failed; using instead %s
rg   c                 B    g | ]}t          j        |d                    S r   )r<   r=   )r   as     r   r   zsend_report.<locals>.<listcomp>  s&    333%+ad##333r   r2   r   zSending message via %s...
z
 -oi -oem z -f c                     g | ]
}|d          S r   r   r   s     r   r   zsend_report.<locals>.<listcomp>  s    '''A1Q4'''r   r   zConnecting to %s via SMTP...
iK  z:465   i+  zEnter SMTP password for @z: z/SMTP error: authentication failed.  Try again.
   zSMTP send failure: zC. You can retry, or save the report and exit. Do you want to retry?zYes, please retry.zNo, save and exit.z#Unable to send report to %s: %d %s
z>Error: send/write operation failed, bug report will be saved.
zSpawning %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?EqzEdit the message.z3Quit reportbug; will save the draft for future use.)eqr   z
Message sent to: %s
z
Bug report submitted to: %s
zCopies sent to:
z  %s
r   z)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   
a  If 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.).
nnnnnnn)Fr   r   r(   r_   r9   r;   getrZ   utils
make_msgidr   
formatdater   get_allgetaddressesjoin	Exception	as_stringr%   display_reportyes_nosysrd   r   rA   
expanduserrB   renamerC   r   getcwdchdir	parseaddrpopenr<   r=   r7   r8   lowersmtplibSMTPendswithSMTP_SSLehlohelostarttlsget_passwordloginsendmailquitsocketerrorSMTPException
isinstanceSMTPAuthenticationErroritemsflushdisplay_failure
executableget_send_commandneeds_terminalr   
returncoder>   select_optionsappendrT   r:   long_messagefinal_message)BrD   r   muarE   sendtoccaddrbccaddrheadersrF   r   mailingsysinfortypeexinforeplyto	printonlytemplateoutfilemtakudossmtptlssmtphostsmtpuser
smtppasswdparanoidrI   envelopefromr   using_sendmailmsgnamer   tfprefixrj   headervalueaddrsalistcclist
debbugs_ccaddrlistro   piperN   
newmsgnamer)   malistjalistfaddrenvfrombackupfh
backupnametoaddrstryagainrefusedretryconnresponseaddrerrsendcmdreturnvaluemtitlemopts	moptsdesc	addressesaddresssB                                                                     r   send_reportr     s   l $#F^G
 x   )333(Lw''H *3 *'k7LQQ& 	(BCCC#''C'##D)) GFOGDM"      ! jnnY00G &%
 8 % 6 6{ C C%
+0040@@	 8i 88 8)7%&= =goodB77 'b 9 9: 'r : :; = = =E K$$U++EBBgoonbAABBBF))&11J +N#99V$$"*  3 	 	 	 	D	 !!G " "Y "
'40000y=.0 0 	"!!HsH -9 -z	 +!yAAAhh	 )'$$W--7>>'"" 	))	'7S=1111 ) ) )>) ) ) ) ))
	"7C00DD 	 	 	%X9EEENB
 ()0*> > > G DDD	  rw~~c** x  i@@@gg
 "'..%% x 		AA 	 	 	HSMMMMM	 43U333&!!%%h//2#k++L99!<GGG,c222b==8s66f66<<DD8U[))))663479 9D $?7+C+CSSSHjNN7NN Lb''''' 3	)H3X>>>0) >>##'==="<#66DD&&v.. 2"G"+H55DD"<11D99;;x{1111c1111IIKKK $MMOOO#yy{{H8A;5555#5555		 5% 2%'__%XXxxx1&2 &2
 JJx444--'7CC		L'"78 ) ) )a!@AA )MNNN#H!%JQJEzz #( 9y1yyy113 3 )  $HHHHH!F(GGGGGG))?  3	)l  	!&}}  s=tSV1v    G	JJwJJLLLL 	 	 	FJJLLLLL	  	bdjjll 	b~ 	bF G`aaa
 **!3>222&&x==	% 1!'666A i00acdddPFE1SU UI!&%;;ACxx$#	&  * *8 * 	>,f55554f===	 	' 	'DAw%+//77:::  &&&y>> 	*&'''  * *x)))) 	*%9,,?@@@! * *x))))  BGNN7++ x0H0H 	Ih 	 	 	D	 W	Ij!!!! 	 	 	D	  E27>>'** E
 4*14 4 	5 	5 	5 	5  E E5I#5#5'#5gQXFXFXagFX GYt
$ W#ww'7('B	E 	E 	E Fs   &G* *
G76G71K
 
K('K(,K> >3L54L5N, ,OOE Y8 8\8[>[>5[>>\)]1 1 ^^?f 
f! f!+g   
gg)r)   Nr*   Nr#   )r)   rR   TNr   NNFFNr   FFr   NNFNN)3r   r9   rz   r<   
subprocessr   r   r   r   rZ   r   r   email.mime.multipartr   email.mime.textr   email.mime.audior	   email.mime.imager
   email.mime.baser   email.mime.messager   rp   __init__r   r   	tempfilesr   r   r   
exceptionsr   r%   r   r   r   r$   r   rangeascii_rangecompileescapenotascii	notascii2r(   rP   r_   r   r  r   r   r   <module>r)     sf  , 


 				 				  / / / / / / / / / / / /    . . . . . . $ $ $ $ $ $ & & & & & & & & & & & & $ $ $ $ $ $ * * * * * *     - - - - - - - - A A A A A A A A A A            ! ! ! ! ! !
gg88r3888992:eibi444s:;;BJuyry555>??	
, , ,B B B BJ  "T T T Tp CGFK<A(3JN!m m m m m mr   