def _data_dir(self, dir=None):
        if dir:
            base_path = os.path.join(self.eaxs, self.account_name)
            self.data_dir = os.path.normpath(
                os.path.abspath(os.path.join(base_path, dir)))
            self.xml_dir = os.path.normpath(
                os.path.abspath(os.path.join(base_path, "eaxs_xml")))

            os.makedirs(self.data_dir)
            os.makedirs(self.xml_dir)
            if CommonMethods.get_store_json():
                self.json_dir = os.path.normpath(
                    os.path.abspath(os.path.join(base_path, "eaxs_json")))
                os.makedirs(self.json_dir)
                CommonMethods.set_json_directory(self.json_dir)

            CommonMethods.set_rel_attachment_dir(
                os.path.join(
                    os.path.sep,
                    os.path.join(os.path.split(base_path)[-1], 'attachments')))
            CommonMethods.set_attachment_dir(self.data_dir)
            CommonMethods.set_xml_dir(self.xml_dir)
        else:
            base_path = os.path.join(self.eaxs, self.account_name)
            CommonMethods.set_base_path(base_path)
            CommonMethods.set_rel_attachment_dir(
                os.path.join(
                    os.path.sep,
                    os.path.join(os.path.split(base_path)[-1], 'attachments')))
            self.data_dir = os.path.normpath(os.path.join(base_path, "data"))
            self.xml_dir = os.path.normpath(
                os.path.abspath(os.path.join(base_path, "eaxs_xml")))
            try:
                os.makedirs(self.data_dir)
                os.makedirs(self.xml_dir)
            except FileExistsError as e:
                print("An EAXS package for: ({}) already exists.".format(
                    self.account_name))
                raise FileExistsError
            CommonMethods.set_attachment_dir(self.data_dir)
            CommonMethods.set_xml_dir(self.xml_dir)
            if CommonMethods.get_store_json():
                CommonMethods.set_json_directory(self.json_dir)
                os.makedirs(self.json_dir)
                self.json_dir = os.path.normpath(
                    os.path.abspath(os.path.join(base_path, "eaxs_json")))
Beispiel #2
0
 def _fldr_render(self, path):
     fldr = Folder(self.current_relpath, path)
     fldr.messages = self.messages
     fldr.render()
     if CommonMethods.get_store_json():
         fh = open(os.path.join(self.json_write, fldr.name + ".json"),
                   'w',
                   encoding='utf-8')
         fh.write(',')
         jsn = fldr.render_json()
         json.dump(jsn, fh)
         fh.close()
     self.logger.info('Wrote folder of size {} bytes'.format(
         fldr.mbox_size))
     self.logger.info('Messages processed: {}'.format(
         self.total_messages_processed))
     fldr = None
     self.messages = []
     gc.collect()
Beispiel #3
0
 def __init__(self, root_level, xml_dir, account_name):
     """Constructor for DirectoryWalker"""
     self.mbx = None  # type: mailbox.mbox
     self.root = root_level
     self.folders = {}
     self.messages = []
     self.current_relpath = None  # type: str
     self.xml_dir = xml_dir
     self.account = Account(account_name, xml_dir)
     self.logger = logging.getLogger("MboxWalker")
     self.total_messages_processed = 0  # type: int
     self.chunks = CommonMethods.get_chunksize()  # type: int
     self.tracking_pos = 0  # type: int
     self.messages_in_folder = 0  # type: int
     self.messages_no_start_fldr = 0  # type: int
     self.message_no_end_flder = 0  # type: int
     self.new_account = True
     self.mboxes = []  # type: list
     self.new_folder = False
     self.mesg_begin = re.compile('^From((\s(\"|.+).+\@)|(\s(\".+\")\s))')
     self.json_folders = []
     if CommonMethods.get_store_json():
         self.json_write = CommonMethods.get_json_directory()