joshdata / convert-outlook-msg-file Goto Github PK
View Code? Open in Web Editor NEWPython library to convert Microsoft Outlook .msg files to .eml/MIME message files.
License: MIT License
Python library to convert Microsoft Outlook .msg files to .eml/MIME message files.
License: MIT License
First, thank you for this. I've found it to be really useful at at a time when my colleague needed exactly this tool.
It would be great this into a Python package with a setup.py that will install dependencies with pip and automatically make outlookmsgfile.py
on the system path.
I can do this packaging work an send a pull request, but I wanted to make sure you hadn't already done this or were in-progress with this.
I’ve been encoutering messages such as the following when trying to convert several MSG files:
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x96 in position 933: invalid start byte
Unfortunately, I can’t share the MSGs, out of privacy concerns.
I noticed that if I change line #321 in outlookmsgfile.py from:
return value.decode("utf8")
to:
return value.decode("latin-1")
… then those MSGs seem to be processed fine.
I don’t understand the comment on lines 318-320 very well, and I’m not familiar enough with Python to understand the whole code, so I thought I’d just mention this here rather than doing a pull request.
If any more information or testing on those files is needed, please ask.
Traceback (most recent call last):
File "test.py", line 4, in
eml = outlookmsgfile.load('/tmp/333.msg')
File "/root/work/python/convert-outlook-msg-file/outlookmsgfile.py", line 33, in load
return load_message_stream(doc.root, True, doc)
File "/root/work/python/convert-outlook-msg-file/outlookmsgfile.py", line 38, in load_message_stream
props = parse_properties(entry['__properties_version1.0'], is_top_level, entry, doc)
File "/root/work/python/convert-outlook-msg-file/outlookmsgfile.py", line 221, in parse_properties
value = tag_type.load(value)
File "/root/work/python/convert-outlook-msg-file/outlookmsgfile.py", line 307, in load
return value.decode("utf8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb7 in position 0: invalid start byte
Thank you for your time
Python includes the "logging" library, which offers a configurable way to output (diagnostic) information.
Currently, the library uses print
to sys.stderr
when things go wrong. Because of this, the log parser we use gets confused sometimes, as it expects all output to be structured as JSON objects.
Using logging
would allow us to disable or format logs from this module. A default configuration could be included that keeps output the same (or very similar) to the way it currently is, when running outlookmsgfile.py
as a standalone script.
Would you be open to a pull request?
Hi,
I have run the lib, but I found this error:
/Users/friveros/anaconda3/lib/python3.6/site-packages/compoundfiles/reader.py:301: CompoundFileHeaderWarning: transaction signature is non-zero (2)
'transaction signature is non-zero (%d)' % txn_signature))
Thanks!
Before:
filename = props.get("ATTACH_FILENAME") or props.get("DISPLAY_NAME")```
After:
filename = props.get("ATTACH_LONG_FILENAME") or props.get("ATTACH_FILENAME") or props.get("DISPLAY_NAME")```
Using Homebrew, unfortunately updated from python 3.7.3 to 3.7.4 and broke my virtualenv. But convert-outlook-msg-file doesn't work even creating new virtualenv
Error after killing it:
File "qt1.py", line 107, in convert_msg
f.write(msg.as_bytes())
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/message.py", line 178, in as_bytes
g.flatten(self, unixfrom=unixfrom)
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/generator.py", line 116, in flatten
self._write(msg)
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/generator.py", line 195, in _write
self._write_headers(msg)
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/generator.py", line 418, in _write_headers
self._fp.write(self.policy.fold_binary(h, v))
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/policy.py", line 200, in fold_binary
folded = self._fold(name, value, refold_binary=self.cte_type=='7bit')
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/policy.py", line 206, in _fold
return value.fold(policy=self)
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/headerregistry.py", line 258, in fold
return header.fold(policy=policy)
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/_header_value_parser.py", line 157, in fold
return _refold_parse_tree(self, policy=policy)
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/_header_value_parser.py", line 2672, in _refold_parse_tree
part.ew_combine_allowed, charset)
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/_header_value_parser.py", line 2724, in _fold_as_ew
get_unstructured(lines[-1][last_ew:] + to_encode))
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/_header_value_parser.py", line 1127, in get_unstructured
_validate_xtext(vtext)
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/_header_value_parser.py", line 979, in _validate_xtext
if utils._has_surrogates(xtext):
File "/usr/local/Cellar/python/3.7.4/Frameworks/Python.framework/Versions/3.7/lib/python3.7/email/utils.py", line 51, in _has_surrogates
def _has_surrogates(s):
KeyboardInterrupt
Abort trap: 6
Created a couple of virtualenv, installed compoundfiles, same issue.
Homebrew uninstalled python, and reinstalled, created new virtualenv, same issue.
Uninstalled 3.7.4 and rolled back to python 3.7.3:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/c24d6bcd4795e9263617e49f340cc61498eea5d3/Formula/python.rb
It seems if an email does not include text in the body, and may only have attachments, script throws RTF_COMPRESSED error.
Traceback (most recent call last):
File "/Users/thorsted/Downloads/convert-outlook-msg-file-primary/outlookmsgfile.py", line 834, in
msg = load(fn)
File "/Users/thorsted/Downloads/convert-outlook-msg-file-primary/outlookmsgfile.py", line 36, in load
return load_message_stream(doc.root, True, doc)
File "/Users/thorsted/Downloads/convert-outlook-msg-file-primary/outlookmsgfile.py", line 123, in load_message_stream
rtf = props['RTF_COMPRESSED']
KeyError: 'RTF_COMPRESSED'
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.