<s> """<STR_LIT>""" <EOL> from __future__ import absolute_import <EOL> from __future__ import print_function <EOL> from __future__ import unicode_literals <EOL> from __future__ import division <EOL> from io import StringIO <EOL> def get_differences ( msg1 , msg2 ) : <EOL> diffs = [ ] <EOL> for header in [ '<STR_LIT>' , '<STR_LIT>' , '<STR_LIT:to>' ] : <EOL> h1 = msg1 [ header ] <EOL> h2 = msg2 [ header ] <EOL> if not h1 or not h2 or h1 != h2 : <EOL> diffs . append ( ( "<STR_LIT>" % repr ( header ) , h1 , h2 ) ) <EOL> body1 = msg1 . message . get_payload ( ) <EOL> body2 = msg2 . message . get_payload ( ) <EOL> if body1 != body2 : <EOL> diffs . append ( ( "<STR_LIT>" , body1 , body2 ) ) <EOL> return diffs <EOL> class Envelope ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , mail_from = None , rcpt_to = None ) : <EOL> self . mail_from = mail_from <EOL> self . rcpt_to = rcpt_to or [ ] <EOL> self . data = None <EOL> self . message = None <EOL> def __repr__ ( self ) : <EOL> return "<STR_LIT>" % ( self . mail_from , self . rcpt_to ) <EOL> def __str__ ( self ) : <EOL> s = [ "<STR_LIT>" % ( self . mail_from , ) ] <EOL> for rcpt in self . rcpt_to : <EOL> s . append ( "<STR_LIT>" % ( rcpt ) ) <EOL> s . append ( "<STR_LIT:\n>" ) <EOL> if self . message : <EOL> s . append ( str ( self . message ) ) <EOL> elif self . data : <EOL> s . append ( self . data . getvalue ( ) ) <EOL> else : <EOL> s . append ( "<STR_LIT>" ) <EOL> return "<STR_LIT:\n>" . join ( s ) <EOL> def has_data ( self ) : <EOL> """<STR_LIT>""" <EOL> if self . data : <EOL> return self . data . tell ( ) <EOL> elif self . message : <EOL> return len ( self . message ) <EOL> else : <EOL> return <NUM_LIT:0> <EOL> def write ( self , text ) : <EOL> """<STR_LIT>""" <EOL> if self . data is None : <EOL> self . data = StringIO ( ) <EOL> self . data . write ( text ) <EOL> def writeln ( self , text ) : <EOL> """<STR_LIT>""" <EOL> self . write ( text ) <EOL> self . write ( "<STR_LIT:\n>" ) <EOL> def set_from ( self , frm ) : <EOL> """<STR_LIT>""" <EOL> self . mail_from = frm <EOL> def add_rcpt ( self , rcpt ) : <EOL> """<STR_LIT>""" <EOL> self . rcpt_to . append ( rcpt ) <EOL> def parse_data ( self , parser ) : <EOL> """<STR_LIT>""" <EOL> if self . data is not None : <EOL> self . data . seek ( <NUM_LIT:0> , <NUM_LIT:0> ) <EOL> self . message = parser . parse ( self . data ) <EOL> self . data . close ( ) <EOL> if self . message : <EOL> self . data = None <EOL> def send ( self , smtp , mail_options = [ ] , rcpt_options = [ ] ) : <EOL> """<STR_LIT>""" <EOL> if self . message : <EOL> return smtp . sendmail ( self . mail_from , self . rcpt_to , self . message . as_string ( ) , mail_options , rcpt_options ) <EOL> elif self . data : <EOL> return smtp . sendmail ( self . mail_from , self . rcpt_to , self . data . getvalue ( ) , mail_options , rcpt_options ) <EOL> else : <EOL> body = "<STR_LIT>" % ( self . mail_from , "<STR_LIT:U+002CU+0020>" . join ( self . rcpt_to ) ) <EOL> return smtp . sendmail ( self . mail_from , self . rcpt_to , body , mail_options , rcpt_options ) </s>
