-
-
Notifications
You must be signed in to change notification settings - Fork 178
Using msg extractor In Your Own Code
Before anything else, you will first, of course, need to import the module.
import extract_msgAll example codes will be assuming that you have imported the module like so.
It is highly recommended that you do not open an MSG file directly using a class, but rather use openMsg to do this. This function will automatically determine if the MSG file has support in any form, and if it does, which class to use for reading it.
msg = extract_msg.openMsg('path/to/msg/file.msg')MSG files can be closed in the same way that a normal file can, simply using the close method of the class.
msg.close()MSGFile, the base class for all MSG file types, supports the __enter__ and __exit__ magic functions, allowing you to use the with context manager with them. At the end of the with context manager, the file will automatically be closed.
with extract_msg.openMsg('path/to/msg/file.msg') as msg:
# Do some stuffopenMsg takes a filename for its first argument. It can also the raw bytes that would make up an MSG file or a file-like object. File-like objects at minimum will require a read, seek, tell, and close method. The read method MUST return bytes and MUST return at most the number of bytes requested.
Not all classes support saving. If you try to call a save function when a class doesn't have it, the function will raise a NotImplementedError. Currently the only class that supports saving is the Message class. This function requires no arguments, but it is likely that you will want to use some of them. The function also returns a reference to the current instance, allowing for you to chain certain functions directly.
msg.save()