ó
 ,µ[c           @   s  d  Z  d d l Z d d l m Z m Z d d l Z d d l Z d d l j Z	 d d l
 Z d „  Z e d k r	e ƒ  Z x= e j d e ƒ D]) \ Z Z Z d e e e d d	 f GHqŒ We j e d
 d ƒZ e j e e d d d d d d d d d e ƒe	 j ƒ  n  d S(   sX  
==========
Unix Email
==========

Create a directed graph, allowing multiple edges and self loops, from
a unix mailbox.  The nodes are email addresses with links
that point from the sender to the receivers.  The edge data
is a Python email.Message object which contains all of
the email message data.

This example shows the power of `DiGraph` to hold edge data
of arbitrary Python objects (in this case a list of email messages).

The sample unix email mailbox called "unix_email.mbox" may be found here:
https://raw.githubusercontent.com/networkx/networkx/master/examples/drawing/unix_email.mbox

iÿÿÿÿN(   t   getaddressest	   parseaddrc          C   s  y t  d d ƒ }  Wn t k
 r. d GH‚  n Xt j |  t j ƒ } t j ƒ  } x± | D]© } t | d ƒ \ } } | j	 d g  ƒ } | j	 d g  ƒ } | j	 d g  ƒ } | j	 d g  ƒ }	 t
 | | | |	 ƒ }
 x* |
 D]" \ } } | j | | d	 | ƒqÚ WqW W| S(
   Ns   unix_email.mboxt   rbs   unix_email.mbox not foundt   Fromt   tot   ccs	   resent-tos	   resent-cct   message(   t   opent   IOErrort   mailboxt   UnixMailboxt   emailt   message_from_filet   nxt   MultiDiGraphR   t   get_allR    t   add_edge(   t   fht   mboxt   Gt   msgt   source_namet   source_addrt   tost   ccst
   resent_tost
   resent_ccst   all_recipientst   target_namet   target_addr(    (    s:   share/doc/networkx-2.2/examples/drawing/plot_unix_email.pyt
   mbox_graph)   s"    t   __main__t   datas   From: %s To: %s Subject: %sR   t   Subjectt
   iterationsi
   t	   node_sizei    t   alphagš™™™™™Ù?t
   edge_colort   rt	   font_sizei   t   with_labels(   t   __doc__R   t   email.utilsR    R   R	   t   syst   matplotlib.pyplott   pyplott   pltt   networkxR   R   t   __name__R   t   edgest   Truet   ut   vt   dt   spring_layoutt   post   drawt   show(    (    (    s:   share/doc/networkx-2.2/examples/drawing/plot_unix_email.pyt   <module>   s   
		".