#NEWLINE# def wrap( text , width = 78 ) : #NEWLINE# #INDENT# 'Wraps text at a specified width.\n        \n    This is used on the PhorumMail feature, as to emulate completely the\n    current Phorum behavior when it sends out copies of the posted\n    articles.\n    ' #NEWLINE# i = 0 #NEWLINE# while ( i < len ( text ) ) : #NEWLINE# #INDENT# if ( ( ( i + width ) + 1 ) > len ( text ) ) : #NEWLINE# #INDENT# i = len ( text ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# findnl = text . find ( '\n' , i ) #NEWLINE# findspc = text . rfind ( ' ' , i , ( ( i + width ) + 1 ) ) #NEWLINE# if ( findspc != ( - 1 ) ) : #NEWLINE# #INDENT# if ( ( findnl != ( - 1 ) ) and ( findnl < findspc ) ) : #NEWLINE# #INDENT# i = ( findnl + 1 ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# text = ( ( text [ : findspc ] + '\n' ) + text [ ( findspc + 1 ) : ] ) #NEWLINE# i = ( findspc + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# else : #NEWLINE# #INDENT# findspc = text . find ( ' ' , i ) #NEWLINE# if ( findspc != ( - 1 ) ) : #NEWLINE# #INDENT# text = ( ( text [ : findspc ] + '\n' ) + text [ ( findspc + 1 ) : ] ) #NEWLINE# i = ( findspc + 1 ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# #UNINDENT# return text