#NEWLINE# def generateBounce( message , failedFrom , failedTo , transcript = '' ) : #NEWLINE# #INDENT# if ( not transcript ) : #NEWLINE# #INDENT# transcript = ( "I'm sorry, the following address has permanent errors: %(failedTo)s.\nI've given up, and I will not retry the message again.\n" % vars ( ) ) #NEWLINE# #UNINDENT# boundary = ( '%s_%s_%s' % ( time . time ( ) , os . getpid ( ) , 'XXXXX' ) ) #NEWLINE# failedAddress = rfc822 . AddressList ( failedTo ) [ 0 ] [ 1 ] #NEWLINE# failedDomain = failedAddress . split ( '@' , 1 ) [ 1 ] #NEWLINE# messageID = smtp . messageid ( uniq = 'bounce' ) #NEWLINE# ctime = time . ctime ( time . time ( ) ) #NEWLINE# fp = StringIO . StringIO ( ) #NEWLINE# fp . write ( ( BOUNCE_FORMAT % vars ( ) ) ) #NEWLINE# orig = message . tell ( ) #NEWLINE# message . seek ( 2 , 0 ) #NEWLINE# sz = message . tell ( ) #NEWLINE# message . seek ( 0 , orig ) #NEWLINE# if ( sz > 10000 ) : #NEWLINE# #INDENT# while 1 : #NEWLINE# #INDENT# line = message . readline ( ) #NEWLINE# if ( len ( boundary ) <= 1 ) : #NEWLINE# #INDENT# break #NEWLINE# #UNINDENT# fp . write ( line ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# fp . write ( message . read ( ) ) #NEWLINE# #UNINDENT# return ( '' , failedFrom , fp . getvalue ( ) )