1111import debug # pyflakes:ignore
1212
1313from ietf .message .models import Message
14+ from ietf .utils .mail import parseaddr
1415
1516class Command (BaseCommand ):
1617 help = 'Show messages, by default unsent messages'
@@ -55,16 +56,20 @@ def handle(self, *args, **options):
5556 messages = messages .filter (time__gte = options ['start' ])
5657 if options ['stop' ]:
5758 messages = messages .filter (sent__lte = options ['stop' ])
58- self .stdout .write ("\n Showimg %s messages between %s and %s:\n \n " % (options ['state' ], options ['start' ], options ['stop' ]))
59+ selection_str = "%s messages between %s and %s" % (options ['state' ], options ['start' ], options ['stop' ])
60+
5961 else :
60- self .stdout .write ("\n Showimg %s messages since %s:\n \n " % (options ['state' ], options ['start' ]))
62+ selection_str = "%s messages since %s" % (options ['state' ], options ['start' ])
63+ self .stdout .write ("\n Showimg %s:\n \n " % selection_str )
6164
6265 if options ['pk' ]:
6366 self .stdout .write (',' .join ([ str (pk ) for pk in messages .values_list ('pk' , flat = True )] ))
6467 else :
6568 for m in messages :
69+ def addr (f ):
70+ return parseaddr (f )[1 ]
6671 to = ',' .join ( a [1 ] for a in email .utils .getaddresses ([m .to ]) )
67- self .stdout .write ('%s %16s %16s %72s %s -> %s "%s"\n ' %
72+ self .stdout .write ('%s %16s %16s %56s %s -> %s "%s"\n ' %
6873 (m .pk , m .time .strftime ('%Y-%m-%d %H:%M' ), m .sent and m .sent .strftime ('%Y-%m-%d %H:%M' ) or '' ,
69- m .msgid .strip ('<>' ), m .frm , to , m .subject .strip ()))
70-
74+ m .msgid .strip ('<>' ), addr ( m .frm ) , to , m .subject .strip ()))
75+ self . stdout . write ( " \n %s messages (%s) \n " % ( messages . count (), selection_str ))
0 commit comments