mht ファイルを解析し、親からパート メッセージを抽出して別の mht ファイルに書き込む mht スクリプトを作成しています。
file_location で mht ファイルを開き、特定の content_id を検索して新しい mht ファイルに書き込む以下の関数を作成しました。
def extract_content(self, file_location, content_id,extension):
first_part = file_location.split(extension)[0]
#checking if file exists
new_file = first_part + "-" + content_id.split('.')[0] + extension
while os.path.exists(new_file):
os.remove(new_file)
with open(file_location, 'rb') as mime_file, open(new_file, 'w') as output:
***#Extracting the message from the mht file***
message = message_from_file(mime_file)
t = mimetypes.guess_type(file_location)[0]
#Walking through the message
for i, part in enumerate(message.walk()):
#Check the content_id if the one we are looking for
if part['Content-ID'] == '<' + content_id + '>':
***witing the contents***
output.write(part.as_string(unixfrom=False))
application/pdf と application/octet-streamの場合、IE で出力部分を開くことができないようです。
application/pdf や application/octet-stream などのこれらの Content-Type を mht ファイルに書き込んで、IE で画像や pdf を表示できるようにするにはどうすればよいですか?
ありがとう