ó
é©Tc           @   sz  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 d  d l 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 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$ j% Z& d  d l' m( Z( e) Z* d j+ g  e, d d ƒ D] Z- e. e- ƒ ^ quƒ Z/ e j0 d e j1 e/ ƒ d ƒ Z2 e j0 d e j1 e/ ƒ d ƒ Z3 d e f d „  ƒ  YZ4 d d „ Z5 d d „ Z7 d d „ Z8 d „  Z9 d d d d d „ Z: d d „ Z; d d e< d d  d d e) e) d d e) e) d! d d e) d d d" „ Z= d S(#   iÿÿÿÿN(   t   Popent   STDOUTt   PIPE(   t   MIMEMultipart(   t   MIMEText(   t	   MIMEAudio(   t	   MIMEImage(   t   MIMEBase(   t   MIMEMessage(   t   Header(   t   VERSIONt   VERSION_NUMBER(   t   TempFilet   open_write_safet   tempfile_prefix(   t	   NoMessage(   t   get_email_addrt    i    i   s   [^t   ]s   \s]t   BetterMIMETextc           B   s   e  Z d  d d „ Z RS(   t   plainc         C   s<   t  j |  | | d ƒ t j | ƒ r8 |  j d | ƒ n  d  S(   Ns   us-asciit   charset(   R   t   __init__t	   notascii2t   searcht	   set_param(   t   selft   _textt   _subtypet   _charset(    (    s4   /usr/lib/python2.7/dist-packages/reportbug/submit.pyR   8   s    N(   t   __name__t
   __module__t   NoneR   (    (    (    s4   /usr/lib/python2.7/dist-packages/reportbug/submit.pyR   7   s   t   qc         C   sH   t  } t j |  ƒ r7 | d k r* d } n  t |  | ƒ St |  d ƒ Sd  S(   Ns   us-asciis   iso-8859-15(   t   Falset   notasciiR   R	   (   t   textR   t   encodingt   needed(    (    s4   /usr/lib/python2.7/dist-packages/reportbug/submit.pyt   encode_if_needed?   s    	c         C   sƒ   g  } t  j |  ƒ j } x[ | D]S \ } } | re | j t j j t t | | | ƒ ƒ | f ƒ ƒ q | j | ƒ q Wd j	 | ƒ S(   Ns   , (
   t   rfc822t   AddressListt   addresslistt   appendt   emailt   Utilst
   formataddrt   strt   rfc2047_encode_headert   join(   t   addrR   t   muat   newlistt	   addressest   realnamet   address(    (    s4   /usr/lib/python2.7/dist-packages/reportbug/submit.pyt   rfc2047_encode_addressK   s    %c         C   s   | r
 |  St  |  | ƒ S(   N(   R'   (   t   headerR   R3   (    (    s4   /usr/lib/python2.7/dist-packages/reportbug/submit.pyR0   V   s     c          G   s   t  p t j |  Œ  S(   N(   t   quietlyt   uit   log_message(   t   args(    (    s4   /usr/lib/python2.7/dist-packages/reportbug/submit.pyt   ewrite^   s    t   xt   gpgc         C   s  | s t  | ƒ d } n  t d t | d ƒ d | ƒ \ } } | j |  ƒ | j ƒ  t d t | d ƒ d | ƒ \ } }	 | j ƒ  | d k rì t j |	 ƒ d t j k r· d | }
 n
 d	 | }
 |
 d
 t j	 |	 ƒ d t j	 | ƒ 7}
 n2 d | }
 |
 d t j	 | ƒ d t j	 |	 ƒ 7}
 y t j
 |
 ƒ t |	 d ƒ } | j ƒ  } | j ƒ  t j j | ƒ rut j | ƒ n  t j j |	 ƒ r—t j |	 ƒ n  | s¦t ‚ n  | }  Wne t t t f k
 rt d t | ƒ d | ƒ \ } } | j |  ƒ | j ƒ  t d | ƒ d }  n X|  S(   s   Sign message with pgp key.i   t   prefixt   unsignedt   dirt   signedR@   t   GPG_AGENT_INFOs"   gpg --local-user '%s' --clearsign s.   gpg --local-user '%s' --use-agent --clearsign s	   --output t    s   pgp -u '%s' -fastt   <s    >t   rs!   gpg/pgp failed; input file in %s
N(   R   R   R   t   writet   closet   ost   unlinkt   environt   commandst   mkargt   systemt   filet   readt   patht   existsR   t   IOErrort   OSErrorR>   R    (   t   bodyt   fromaddrt   packaget   pgp_addrt   signt	   draftpathRB   t   file1RD   t   file2t   signcmdR?   t
   signedbodyt   fht   tmpfile2(    (    s4   /usr/lib/python2.7/dist-packages/reportbug/submit.pyt   sign_messagea   sD    $
$

+
(
	
!

c         C   sJ  t  j ƒ  t d ƒ } t |  d | p( | ƒ} | j d d ƒ d | _ d | _ | j | ƒ t } xÚ| D]Ò} y t	 | ƒ } | j
 ƒ  Wn/ t k
 r» }	 t d | |	 j ƒ t } qj n Xd  }
 | } t d d	 d
 | g d t d t ƒj ƒ  d } | rnt j d | ƒ } | rn| j ƒ  \ }
 } } t j d | ƒ } | rS| j d ƒ } n  d |
 k rkd  }
 qkqnn  |
 s’t  j | d t ƒ\ }
 } n  |
 s¡d }
 n  |
 j d d ƒ \ } } | d k rÿt	 | d ƒ } t | j ƒ  d | d | ƒ} | j
 ƒ  n| d k rBt	 | d ƒ } t t j | ƒ d | ƒ} | j
 ƒ  nË | d k r‚t	 | d ƒ } t | j ƒ  d | ƒ} | j
 ƒ  n‹ | d k rÂt	 | d ƒ } t  | j ƒ  d | ƒ} | j
 ƒ  nK t	 | d ƒ } t! | | ƒ } | j" | j ƒ  ƒ | j
 ƒ  t j# j$ | ƒ | j d d d t% j& j' | ƒ ƒ| j | ƒ qj W| | f S(   Nt   mixedR   s   Content-Dispositiont   inlines6   This is a multi-part MIME message sent by reportbug.

R   s"   Warning: opening '%s' failed: %s.
RQ   s   --mimes   --brieft   stdoutt   stderri    s   ([^;, ]*)(,[^;]+)?(?:; )?(.*)s   charset=([^,]+|"[^,"]+")i   t   /t   stricts   application/octet-streamR$   t   rUR   t   messaget   rbt   imaget   audiot
   attachmentt   filename((   t	   mimetypest   initR   R   t
   add_headert   preamblet   epiloguet   attachR"   RQ   RJ   t   EnvironmentErrorR>   t   strerrort   TrueR    R    R   R   t   communicatet   ret   matcht   groupsR   t   groupt
   guess_typet   splitRR   R   R,   t   message_from_fileR   R   R   t   set_payloadt   Encoderst   encode_base64RK   RS   t   basename(   RW   t   attachmentsR   t   body_charsetRk   t   bodypartt   failedRo   t   fpR?   t   ctypet   csett   infoR|   t   junkt   extrasR%   t   maintypet   subtypet   part(    (    s4   /usr/lib/python2.7/dist-packages/reportbug/submit.pyt   mime_attach”   s~    
			
			
s   us-asciit   debbugst	   localhostc   C   	   C   s  t  } } d } | r% | r% d } n  | r@ | d k r@ d } n  |	 } t |  t ƒ rp |  j d d ƒ }  d } n  t | ƒ } | rÈ | rÈ t |  | |	 | ƒ \ }  } | rÚ t d ƒ dO } } } qÚ n t |  d | ƒ}  t	 | d | ƒ |  d <t	 | |	 | ƒ |  d	 <xO | D]G \ }! }" |! dP k r>t	 |" |	 | ƒ |  |! <qt
 |" |	 | ƒ |  |! <qW| rwt	 | |	 | ƒ |  d
 <n  | r–t	 | |	 | ƒ |  d <n  t j j d | ƒ } | rÊt	 | |	 | ƒ |  d <n  |
 rt j j d ƒ |  d <t |  d <t j j d t ƒ |  d <n  | r,| p| r,t |  d <n  g  |  j d	 g  ƒ |  j d
 g  ƒ |  j d g  ƒ D] }# t |# ƒ ^ q_}$ t j j |$ ƒ }% g  |  j d g  ƒ D] }# t |# ƒ ^ qœ}& t j j |& ƒ }' |& rû|  d =d j |& ƒ }( t	 |( |	 | ƒ |  d <n  | r!| r!y |  d =Wq!q!Xn  |  j ƒ  }  | r“| p<| r“t j j d d ƒ }) t j |) d ƒ j |  ƒ t j d d d ƒ s“dO } } q“n  dO }* | s¥| r±t j }+ ný| rÕt  d | d | ƒ \ }+ }* nÙ| sú| rót j! j" | ƒ pö| rÈt j! j# | ƒ pd  | } t j! j" | ƒ rgy t j$ | | d! ƒ Wqgt% k
 rct d" | | ƒ qgXn  y t& | d ƒ }+ Wq®t% k
 rÄt  d | d | ƒ \ }, }- t d# | |- ƒ |- } |, }+ q®Xnæ | r®| r®y t j' ƒ  }# Wn t% k
 rt j( d$ ƒ n Xg  |% D] }. t) j* |. d% ƒ ^ q}/ d& j |/ ƒ }0 t+ j, | ƒ d% }1 | rjt+ j, | ƒ d% }2 n |1 }2 t d' | ƒ t j d( | t) j* |2 ƒ |0 f d ƒ }+ t } n  | r“g  |% D] }# |# d% ^ q»}3 t- j. d) d* |  ƒ }4 t }5 dO }6 d+ }7 x|5 rt  }5 t d, | ƒ ydO }8 | j/ ƒ  d k rDt0 j1 | d- ƒ }8 n t0 j1 | ƒ }8 |8 j2 ƒ  }9 d. |9 d+ k ozd/ k n sŒ|8 j3 ƒ  n  | rØ|8 j4 ƒ  |8 j2 ƒ  }9 d. |9 d+ k oÃd/ k n sØ|8 j3 ƒ  qØn  | r| s t j5 d0 | | f ƒ } n  |8 j6 | | ƒ n  |8 j7 | |3 |4 ƒ }6 |8 j8 ƒ  Wqût9 j: t0 j; f k
 r}# t |# t0 j< ƒ ržt d1 ƒ t }5 dO } |7 d% 7}7 |7 d2 k r•qûqžt  }5 n  t j d3 |# d4 d5 ƒ rÃt }5 qûqt } t  d | d | ƒ \ }, } |, j |  ƒ |, j= ƒ  t d6 | ƒ qûXqûW|6 rK	x5 |6 j> ƒ  D]' \ }: }; t d7 |: |; d+ |; d% ƒ q#Wt  d | d | ƒ \ }, } |, j |  ƒ |, j= ƒ  t d6 | ƒ qK	n¸ y1 |+ j |  ƒ |+ j? ƒ  | rÃt d8 | ƒ n  Wn! t@ k
 rçt } |+ j= ƒ  n X| s 	|+ j= ƒ  rK	| rK	t } t  d | d | ƒ \ }, } |, j |  ƒ |, j= ƒ  t jA d9 | ƒ n  | r:
t d: | jB ƒ d+ }< t  }= x»|= s6
| jC |* ƒ }< |< d+ k r-
t d; ƒ d< }> d= }? i d> d? 6d@ dA 6}@ t jD |> |? |@ ƒ }# |# dA k r3
t } t  d | d | ƒ \ }, } |, j |  ƒ |, j= ƒ  t dB | ƒ t }= q3
qp	t }= qp	Wnñ | r+| sM
| r+| rc
t dC | ƒ n t dD | ƒ g  }A x; |% D]3 }: |: d% t+ j, | ƒ d% k r}
|A jE |: ƒ q}
q}
WtF |A ƒ rë
t dE ƒ x |$ D] }B t dF |B ƒ qÑ
Wn  |' r+| dG k r+t dH ƒ x |& D] }B t dF |B ƒ qWq+n  | p4| r‡| dG k r‡| r‡| r‡|
 r‡t dI ƒ t jA dJ | dK dL | dK dM ƒ n  |* rÏt j! j" | ƒ rÏt j! j" |* ƒ rÏy t jG |* ƒ WqÏqÏXn  |* rÿt j! j" |* ƒ rÿ| rÿt dN |* ƒ n  dO S(Q   s   Send a report.R   s   reportbug.debian.orgs   packages.debian.orgs   utf-8t   replaces,   Error: Message creation failed, not sending
R   t   Fromt   Tot   Cct   Bccs   X-Debbugs-CCs   Reply-Tos   Mail-Followup-Tot   REPLYTOt	   reportbugs
   Message-IDs   X-Mailert	   localtimet   Dates   X-Reportbug-Versions   X-Debbugs-Ccs   , t   PAGERs   sensible-pagert   ws"   Does your report seem satisfactorys   Yes, send it.s   No, don't send it.RA   RC   s   /var/tmp/%s.bugt   ~s$   Unable to rename existing %s as %s~
s'   Writing to %s failed; using instead %s
Rh   i   RF   s   Sending message via %s...
s   %s -f %s -oi -oem %ss   (?m)^[.]s   ..i    s   Connecting to %s via SMTP...
iK  iÈ   i+  s   Enter SMTP password for %s@%s: s/   SMTP error: authentication failed.  Try again.
i   sO   SMTP send failure: %s. Do you want to retry (or else save the report and exit)?s   Yes, please retry.s   No, save and exit.s   Wrote bug report to %s
s#   Unable to send report to %s: %d %s
s   Bug report written as %s
s;   Error: send/write operation failed, bug report saved to %s
s   Spawning %s...
sM   Mutt users should be aware it is mandatory to edit the draft before sending.
s9   Report has not been sent yet; what do you want to do now?t   Eqs   Edit the message.t   es3   Quit reportbug; will save the draft for future use.R!   s   Draft saved into %s
s   
Message sent to: %s
s   
Bug report submitted to: %s
s   Copies sent to:
s     %s
R”   s)   Copies will be sent after processing to:
s   
s´  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.).
R,   t   nt   999999s&   A copy of the report is stored as: %s
N(   R—   R˜   R™   Rš   s   X-Debbugs-CCs   Reply-Tos   Mail-Followup-To(H   R"   t
   isinstancet   unicodet   encodeR   R“   R>   R    R   R8   R0   RK   RM   t   getR,   R-   t
   make_msgidR
   t
   formatdateRy   R   t   get_allR/   t   getaddressesR1   t	   as_stringt   popenRI   R;   t   yes_not   sysRf   R   RS   RT   t
   expandusert   renameRV   R   t   getcwdt   chdirRN   RO   R(   t	   parseaddrR{   t   subt   lowert   smtplibt   SMTPt   ehlot   helot   starttlst   get_passwordt   logint   sendmailt   quitt   sockett   errort   SMTPExceptiont   SMTPAuthenticationErrorRJ   t	   iteritemst   flushRU   t   long_messaget   namet   sendt   select_optionsR+   t   lenRL   (C   RW   R†   R3   RX   t   sendtot   ccaddrt   bccaddrt   headersRY   R   t   mailingt   sysinfot   rtypet   exinfot   replytot	   printonlyt   templatet   outfilet   mtat   kudost   smtptlst   smtphostt   smtpusert
   smtppasswdt   paranoidR\   t   envelopefromR‰   t   using_sendmailt   msgnameR‡   t   tfprefixRk   R9   t   valueR?   t   addrst   alistt   cclistt
   debbugs_cct   addrlistt   pagerRp   t   pipeRa   t
   newmsgnamet   at   malistt   jalistt   faddrt   envfromt   toaddrst   smtp_messaget   tryagaint   refusedt   retryt   connt   responseR2   t   errt   returnvaluet	   succeededt   mtitlet   moptst	   moptsdescR5   R7   (    (    s4   /usr/lib/python2.7/dist-packages/reportbug/submit.pyt   send_reportÚ   s²   

			
	
)+	%
&			 
 

		



	
	





&
*(>   R±   RK   R{   RN   t
   subprocessR    R   R   R(   R¹   RÂ   R,   t   email.MIMEMultipartR   t   email.MIMETextR   t   email.MIMEAudioR   t   email.MIMEImageR   t   email.MIMEBaseR   t   email.MIMEMessageR   t   email.HeaderR	   Rq   R   R
   R   t	   tempfilesR   R   R   t
   exceptionsR   t
   ui.text_uit   text_uiR;   t   utilsR   R"   R:   R1   t   ranget   ait   chrt   ascii_ranget   compilet   escapeR#   R   R   R'   R    R8   R0   R>   Rc   R“   Ry   Rÿ   (    (    (    s4   /usr/lib/python2.7/dist-packages/reportbug/submit.pyt   <module>   sN   1  	3G	