1 | # msg2txt.py:
|
---|
2 | #
|
---|
3 | # Converts & output Outlook .MSG files to Text(STDOUT).
|
---|
4 | #
|
---|
5 | # Copyright 2009 Frank J Bruzzaniti
|
---|
6 | #
|
---|
7 | # This program is free software; you can redistribute it and/or
|
---|
8 | # modify it under the terms of the GNU General Public License as
|
---|
9 | # published by the Free Software Foundation; either version 2 of the
|
---|
10 | # License, or (at your option) any later version.
|
---|
11 | #
|
---|
12 | # This program is distributed in the hope that it will be useful,
|
---|
13 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
14 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
15 | # GNU General Public License for more details.
|
---|
16 | #
|
---|
17 | # You should have received a copy of the GNU General Public License
|
---|
18 | # along with this program; if not, write to the Free Software
|
---|
19 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
|
---|
20 | # USA
|
---|
21 |
|
---|
22 | import sys, os, email, subprocess
|
---|
23 | # added extra import because of bug using freeze.py
|
---|
24 | import email.iterators
|
---|
25 |
|
---|
26 | # Check to see argument is givin
|
---|
27 | if len(sys.argv) != 2:
|
---|
28 | print 'No file specified\n'
|
---|
29 | sys.exit()
|
---|
30 |
|
---|
31 | # Create bitbucket for errors
|
---|
32 | devnull = open(os.devnull, "w")
|
---|
33 |
|
---|
34 | # Run perl script
|
---|
35 | p = subprocess.Popen(['perl','-MEmail::Outlook::Message','-e','print new Email::Outlook::Message($ARGV[0])->to_email_mime->as_string',sys.argv[1]],stdout=subprocess.PIPE,stderr=devnull)
|
---|
36 |
|
---|
37 | devnull.close()
|
---|
38 |
|
---|
39 | # feed mime created by perl script to msg via email.message_from_string()
|
---|
40 | msg = email.message_from_string(p.stdout.read())
|
---|
41 |
|
---|
42 | # For each section that iis NOT an attachment print to stdout
|
---|
43 | for part in msg.walk():
|
---|
44 | strContent = part.get_content_type()
|
---|
45 | if strContent[0:5] == 'text/':
|
---|
46 | print part.get_payload(decode=True)
|
---|
47 |
|
---|
48 |
|
---|
49 |
|
---|
50 |
|
---|
51 |
|
---|
52 |
|
---|