#! /usr/bin/env python3 # -*- coding: utf-8 -*- """*********************************************************************** * "flatten-mime" is free software: you can redistribute it and/or modify * * it under the terms of the GNU Affero Public License as published by * * the Free Software Foundation, either version 3 of the License, or * * (at your option) any later version. * * * * "flatten-mime" is distributed in the hope that it will be useful, * * but WITHOUT ANY WARRANTY; without even the implied warranty of * * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * * GNU Affero Public License for more details. * * * * You should have received a copy of the GNU Affero Public License * * along with Edward. If not, see . * * * * Copyright (C) 2015 Andrew Engelbrecht (AGPLv3+) * ************************************************************************** """ import sys import email.parser mime_text = sys.stdin.read() email_struct = email.parser.Parser().parsestr(mime_text) for subpart in email_struct.walk(): payload_b = subpart.get_payload(decode=True) if payload_b: payload = payload_b.decode("utf-8") print(payload)