improve edward output
[edward.git] / tests / flatten-mime
1 #! /usr/bin/env python3
2 # -*- coding: utf-8 -*-
3
4 """***********************************************************************
5 * "flatten-mime" is free software: you can redistribute it and/or modify *
6 * it under the terms of the GNU Affero Public License as published by *
7 * the Free Software Foundation, either version 3 of the License, or *
8 * (at your option) any later version. *
9 * *
10 * "flatten-mime" is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU Affero Public License for more details. *
14 * *
15 * You should have received a copy of the GNU Affero Public License *
16 * along with Edward. If not, see <http://www.gnu.org/licenses/>. *
17 * *
18 * Copyright (C) 2015 Andrew Engelbrecht (AGPLv3+) *
19 **************************************************************************
20
21 """
22
23 import sys
24 import email.parser
25
26
27 mime_text = sys.stdin.read()
28
29 email_struct = email.parser.Parser().parsestr(mime_text)
30
31 for subpart in email_struct.walk():
32 payload_b = subpart.get_payload(decode=True)
33
34 if payload_b:
35 payload = payload_b.decode("utf-8")
36
37 print(payload)
38