1.1 --- a/tools/showmail.py Tue Dec 20 16:06:49 2016 +0100
1.2 +++ b/tools/showmail.py Tue Dec 20 16:43:44 2016 +0100
1.3 @@ -1,7 +1,27 @@
1.4 #!/usr/bin/env python
1.5
1.6 +"""
1.7 +Show a MIME-encoded e-mail message as plain text.
1.8 +
1.9 +Copyright (C) 2015, 2016 Paul Boddie <paul@boddie.org.uk>
1.10 +
1.11 +This program is free software; you can redistribute it and/or modify it under
1.12 +the terms of the GNU General Public License as published by the Free Software
1.13 +Foundation; either version 3 of the License, or (at your option) any later
1.14 +version.
1.15 +
1.16 +This program is distributed in the hope that it will be useful, but WITHOUT
1.17 +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
1.18 +FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
1.19 +details.
1.20 +
1.21 +You should have received a copy of the GNU General Public License along with
1.22 +this program. If not, see <http://www.gnu.org/licenses/>.
1.23 +"""
1.24 +
1.25 from email import message_from_string
1.26 from email.generator import Generator
1.27 +from os.path import split
1.28 import sys
1.29
1.30 try:
1.31 @@ -61,6 +81,18 @@
1.32 # Main program.
1.33
1.34 if __name__ == "__main__":
1.35 + if len(sys.argv) > 1 and sys.argv[1] == "--help":
1.36 + print >>sys.stderr, """\
1.37 +Usage: %s [ <messages to skip> ]
1.38 +
1.39 +Read MIME-encoded e-mail messages from standard input, writing the decoded
1.40 +messages to standard output.
1.41 +
1.42 +Where <messages to skip> is given, the indicated number of messages will be
1.43 +skipped in the input, with the first subsequent message being written out.
1.44 +""" % split(sys.argv[0])[1]
1.45 + sys.exit(1)
1.46 +
1.47 skip = int((sys.argv[1:] or [0])[0])
1.48 message = message_from_string(until_from(sys.stdin, skip))
1.49 decode(message)