-
-
Notifications
You must be signed in to change notification settings - Fork 172
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from Syncurity/master
v0.22
- Loading branch information
Showing
19 changed files
with
727 additions
and
170 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,51 @@ | ||
import logging | ||
import os | ||
import sys | ||
import traceback | ||
|
||
from extract_msg import __doc__, utils | ||
from extract_msg.compat import os_ as os | ||
from extract_msg.message import Message | ||
|
||
if __name__ == '__main__': | ||
# Setup logging to stdout, indicate running from cli | ||
CLI_LOGGING = 'extract_msg_cli' | ||
|
||
args = utils.get_command_args() | ||
args = utils.get_command_args(sys.argv[1:]) | ||
level = logging.INFO if args.verbose else logging.WARNING | ||
utils.setup_logging(args.config_path, level, args.log, args.file_logging) | ||
currentdir = os.getcwd() # Store this just in case the paths that have been given are relative | ||
currentdir = os.getcwdu() # Store this just in case the paths that have been given are relative | ||
if args.out_path: | ||
if not os.path.exists(args.out_path): | ||
os.makedirs(args.out_path) | ||
out = args.out_path | ||
else: | ||
out = currentdir | ||
if args.dev: | ||
import extract_msg.dev | ||
extract_msg.dev.main(args, sys.argv[1:]) | ||
elif args.validate: | ||
import json | ||
import pprint | ||
import time | ||
|
||
for x in args.msgs: | ||
try: | ||
with Message(x[0]) as msg: | ||
#Right here we should still be in the path in currentdir | ||
os.chdir(out) | ||
msg.save(toJson = args.json, useFileName = args.use_filename, ContentId = args.cid) | ||
except Exception as e: | ||
print("Error with file '" + filename + "': " + | ||
traceback.format_exc()) | ||
os.chdir(currentdir) | ||
from extract_msg import validation | ||
|
||
val_results = {x[0]: validation.validate(x[0]) for x in args.msgs} | ||
filename = 'validation {}.json'.format(int(time.time())) | ||
print('Validation Results:') | ||
pprint.pprint(val_results) | ||
print('These results have been saved to {}'.format(filename)) | ||
with open(filename, 'w') as fil: | ||
fil.write(json.dumps(val_results)) | ||
utils.get_input('Press enter to exit...') | ||
else: | ||
utils.setup_logging(args.config_path, level, args.log, args.file_logging) | ||
for x in args.msgs: | ||
try: | ||
with Message(x[0]) as msg: | ||
# Right here we should still be in the path in currentdir | ||
os.chdir(out) | ||
msg.save(toJson = args.json, useFileName = args.use_filename, ContentId = args.cid) | ||
except Exception as e: | ||
print("Error with file '" + x[0] + "': " + | ||
traceback.format_exc()) | ||
os.chdir(currentdir) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
""" | ||
Compatibility module to ensure that certain functions exist across python versions | ||
""" | ||
|
||
from os import * | ||
import sys | ||
|
||
if sys.version_info[0] >= 3: | ||
getcwdu = getcwd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
""" | ||
Module for collecting data to be sent to the developer. | ||
""" | ||
|
||
# NOTE: Order of tasks: | ||
# 1. Check for exceptions: | ||
# * Check the entire process for exceptions raised by a specific file and log them. If none occur, | ||
# log something like "No exceptions were detected." | ||
# 2. Run the file through the developer versions of the classes | ||
|
||
|
||
import logging | ||
|
||
from extract_msg import dev_classes | ||
from extract_msg import utils | ||
from extract_msg.compat import os_ as os | ||
from extract_msg.message import Message | ||
|
||
|
||
logger = logging.getLogger(__name__) | ||
logger.addHandler(logging.NullHandler()) | ||
|
||
|
||
def setup_dev_logger(default_path=None, logfile = None, env_key='EXTRACT_MSG_LOG_CFG'): | ||
utils.setup_logging(default_path, 5, logfile, True, env_key) | ||
|
||
|
||
def main(args, argv): | ||
""" | ||
Please only run this from the command line. Attempting to use this | ||
otherwise is likely to fail. :param args: is the class instance | ||
returned by `extract_msg.utils.get_command_args`. :param argv: is | ||
the list of arguments that were the input to the aforementioned | ||
function. | ||
""" | ||
setup_dev_logger(args.config_path, args.log) | ||
currentdir = os.getcwdu() # Store this just in case the paths that have been given are relative | ||
if args.out_path: | ||
if not os.path.exists(args.out_path): | ||
os.makedirs(args.out_path) | ||
out = args.out_path | ||
else: | ||
out = currentdir | ||
logger.log(5, 'ARGV: {}'.format(argv)) | ||
for y, x in enumerate(args.msgs): | ||
logger.log(5, '---- RUNNING DEVELOPER MODE ON FILE {} ----'.format(x[0])) | ||
logger.log(5, 'EXCEPTION CHECK:') | ||
try: | ||
with Message(x[0]) as msg: | ||
# Right here we should still be in the path in currentdir | ||
os.chdir(out) | ||
msg.save(toJson = args.json, useFileName = args.use_filename, ContentId = args.cid) | ||
except Exception as e: | ||
logger.exception(e) | ||
else: | ||
logger.log(5, 'No exceptions raised.') | ||
logger.log(5, 'DEVELOPER CLASS OUTPUT:') | ||
os.chdir(currentdir) | ||
dev_classes.Message(x[0]) | ||
logger.log(5, '---- END OF DEVELOPER LOG ----') | ||
logpath = None; | ||
for x in logging.root.handlers: | ||
try: | ||
logpath = x.baseFilename | ||
except AttributeError: | ||
pass; | ||
print('Logging complete. Log has been saved to {}'.format(logpath)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
from extract_msg.dev_classes.attachment import Attachment | ||
from extract_msg.dev_classes.message import Message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
import logging | ||
|
||
from extract_msg import constants | ||
from extract_msg.properties import Properties | ||
from extract_msg.utils import properHex | ||
|
||
logger = logging.getLogger(__name__) | ||
logger.addHandler(logging.NullHandler()) | ||
|
||
|
||
class Attachment(object): | ||
""" | ||
Developer version of the `extract_msg.attachment.Attachment` class. | ||
""" | ||
def __init__(self, msg, dir_): | ||
""" | ||
:param msg: the Message instance that the attachment belongs to. | ||
:param dir_: the directory inside the msg file where the attachment is located. | ||
""" | ||
object.__init__(self) | ||
self.__msg = msg | ||
self.__dir = dir_ | ||
self.__props = Properties( | ||
msg._getStream([self.__dir, '__properties_version1.0']), | ||
constants.TYPE_ATTACHMENT) | ||
|
||
# Get attachment data | ||
if msg.Exists([dir_, '__substg1.0_37010102']): | ||
self.__type = 'data' | ||
self.__data = msg._getStream([dir_, '__substg1.0_37010102']) | ||
elif msg.Exists([dir_, '__substg1.0_3701000D']): | ||
if (self.__props['37050003'].value & 0x7) != 0x5: | ||
logger.log(5, 'Printing details of NotImplementedError...') | ||
logger.log(5, 'dir_ = {}'.format(dir_)) | ||
logger.log(5, 'Writing properties stream to output:') | ||
logger.log(5, '--------Start-Properties-Stream--------\n' + | ||
properHex(self.__props.stream) + | ||
'\n---------End-Properties-Stream---------') | ||
logger.log(5, 'Writing directory contents to output:') | ||
logger.log(5, '--------Start-Directory-Content--------\n' + | ||
'\n'.join([repr(x) for x in msg.listDir(True, True)])) | ||
logger.log(5, '---------End-Directory-Content---------') | ||
logger.log(5, 'End of NotImplementedError details') | ||
else: | ||
self.__prefix = msg.prefixList + [dir_, '__substg1.0_3701000D'] | ||
self.__type = 'msg' | ||
self.__data = msg.__class__(msg.path, self.__prefix) | ||
else: | ||
raise TypeError('Unknown attachment type.') | ||
|
||
@property | ||
def data(self): | ||
""" | ||
Returns the attachment data. | ||
""" | ||
return self.__data | ||
|
||
@property | ||
def dir(self): | ||
""" | ||
Returns the directory inside the msg file where the attachment is located. | ||
""" | ||
return self.__dir | ||
|
||
@property | ||
def msg(self): | ||
""" | ||
Returns the Message instance the attachment belongs to. | ||
""" | ||
return self.__msg | ||
|
||
@property | ||
def props(self): | ||
""" | ||
Returns the Properties instance of the attachment. | ||
""" | ||
return self.__props | ||
|
||
@property | ||
def type(self): | ||
""" | ||
Returns the type of the data. | ||
""" | ||
return self.__type |
Oops, something went wrong.