³ò
×ýIc           @   s  d  Z  d d k Z d d k Z d d k Z d d k l Z d d k Z e i d e _ d „  Z	 e
 d j o­ e i i e i d d d	 d
 ƒ Z e i i d d d e i d ƒ e i i e i d d ƒ g Z d Z x- e D]% Z e	 e e e ƒ Z d Ge Ge GHqÙ We i e d j ƒ n d S(   sð  
#+
# NAME:
#	sync_ips_email
# PURPOSE:
#	To determine if there is new IPS data by checking for new email
# OUTPUT:
#	Returns a 1 if an IPS email was found, 0 if not
# RESTRICTIONS:
#	To be able to replace /var/spool/mail/username, the account running
#	this script needs to have write acces to the file. The mailbox is already
#	owned by 'username' but is in group 'mail'. The easiest way to provide
#	write access seems to be to make 'username' a member of group 'mail', in
#	addition to the group 'users'.
# CALLS:
#	time2time, tiny.run_cmd
# PROCEDURE:
#	Incoming email is put in /var/spool/mail/username
#	Pine moves email from /var/spool/mail/username to $HOME/mbox
#	We check both mailboxes for IPS email from Nagoya.
#
#	Both mailboxes are scanned for email with "stelab.nagoya-u.ac.jp" in the
#	message ID and "VLIST_UCSD_" in the body. All such emails are deleted,
#	and a status of 1 is returned.
#
#	Because PortableUnixMailbox library does not seem to have a function for
#	deleting we have to explicitly rewrite the mailbox to remove the IPS emails
#	once they have been detected.
#
#	If no IPS email is found in a mailbox then the mailbox remains unmodified.
#	If one or more IPS emails are found, then all non-IPS emails are accumulated
#	in a temporary mailbox file. The temporary file (which does not contain
#	the IPS emails) replaces the old mailbox file after completion.
#
#	The only kludge used is the addition of a phony From_ line to the start of
#	each email written to the temporary mail box file. There does not seem to be
#	a way to extract this line from the mailbox file itself, so we had to fake
#	one (if it is not there, pine will not recognize it as a valid mailbox).
# MODIFICATION HISTORY:
#	SEP-2003, Austin Duncan
#	OCT-2003, Paul Hick (UCSD/CASS)
#		Added check to make sure the mailbox file exists.
#		Added processing of $HOME/mbox in addition to /var/spool/mail/username
#	NOV-2003, Paul Hick (UCSD/CASS; pphick@ucsd.edu)
#		Added the email time converted from JST to UT to output log.
#-
iÿÿÿÿN(   t   run_cmdt   TUBc         C   sâ  t  i i | ƒ p d | d GH|  Sn d } d } t | d ƒ } t i | ƒ } d } x| | pt | i ƒ  } | d  j o Pn | i d d ƒ i	 ƒ  }	 | i
 i ƒ  }
 |
 i | ƒ d	 j o |	 i | ƒ d	 j } q[ W| i ƒ  | p |  Sn t i d
 ƒ } t | d ƒ } t | d ƒ } t i | ƒ } xi| i ƒ  } | d  j o Pn | i d d ƒ i	 ƒ  } | i d d ƒ i	 ƒ  }	 | i d d ƒ i	 ƒ  } | i d d ƒ i	 ƒ  } | i
 i ƒ  }
 |
 i | ƒ d	 j o‰ |	 i | ƒ d	 j os |  d }  |
 i d d ƒ i d d ƒ d | d t d | d d ƒ } t | d ƒ } | i | ƒ | i ƒ  q/| i d ƒ | i t | ƒ ƒ | i d ƒ | i |
 ƒ q/| i ƒ  | i ƒ  t | d ƒ i t | d ƒ i ƒ  ƒ t  i | ƒ |  S(   Ns   sync_ips_email, s    does not existt   VLIST_UCSD_s   stelab.nagoya-u.ac.jpt   rbi    s
   Message-Idt    iÿÿÿÿs
   .ips_emailt   at   Subjectt   Fromt   Datei   s    is created.s   
s   	s     s   echo "s   " | time2time -emails,   From cass@ucsd.edu Tue Sep 23 15:57:01 2003
t   wt   r(   t   ost   patht   existst   opent   mailboxt   PortableUnixMailboxt   nextt   Nonet	   getheadert   stript   fpt   readt   findt   closet   tempfilet   mktempt   replaceR    t   writet   strt   remove(   t	   matchFlagt   mailFilet   logFilet
   bodySearcht   messageSearcht
   mailHandlet   mboxt   email_foundt   msgt	   messageIDt   textt   tempFilet
   tempHandlet   subjectt   sendert   dateSentt   newLinet	   logHandle(    (    s   sync_ips_email.pyt   sync_ips_email7   s\    
0
,
?

%t   __main__t   DATt   nagoyat   dailys   logmail.ipss   /vart   spoolt   mailt   USERt   HOMER%   i    t	   Processed(   t   __doc__R   R   t   syst   tinyR    R   t   environt   tempdirR1   t   __name__R   t   joinR!   t	   mailFilesR   R    t   exit(    (    (    s   sync_ips_email.pys   <module>0   s   $	o" 