diff -r a47996c10579 Lib/smtpd.py --- a/Lib/smtpd.py Wed Aug 06 18:55:54 2014 +0300 +++ b/Lib/smtpd.py Wed Aug 06 23:07:29 2014 +0200 @@ -657,31 +657,43 @@ class DebuggingServer(SMTPServer): - # Do something with the gathered message - def process_message(self, peer, mailfrom, rcpttos, data): + def _print_message_content(self, peer, data): inheaders = 1 + if type(data) == bytes: + # Preserve newlines and cut off "b''": + data = str(data).replace('\\n', '\n')[2:-1] lines = data.split('\n') - print('---------- MESSAGE FOLLOWS ----------') for line in lines: # headers first if inheaders and not line: print('X-Peer:', peer[0]) inheaders = 0 print(line) + + # Do something with the gathered message + def process_message(self, peer, mailfrom, rcpttos, data): + inheaders = 1 + print('---------- MESSAGE FOLLOWS ----------') + self._print_message_content(peer, data) print('------------ END MESSAGE ------------') class PureProxy(SMTPServer): def process_message(self, peer, mailfrom, rcpttos, data): - lines = data.split('\n') + x_peer_header = 'X-Peer: %s' % peer[0] + newline = NEWLINE + if isinstance(data, bytes): + x_peer_header = x_peer_header.encode() + newline = NEWLINE.encode() + lines = data.split(newline) # Look for the last header i = 0 for line in lines: if not line: break i += 1 - lines.insert(i, 'X-Peer: %s' % peer[0]) - data = NEWLINE.join(lines) + lines.insert(i, x_peer_header) + data = newline.join(lines) refused = self._deliver(mailfrom, rcpttos, data) # TBD: what to do with refused addresses? print('we got some refusals:', refused, file=DEBUGSTREAM)