diff --git a/README.md b/README.md index 7f48cec..e12733f 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,7 @@ # backup_imap +Do a backup of an IMAP account in a folder. + ## Requirements ## Installation @@ -29,5 +31,22 @@ Ensure you have "C:\Users\${env:USERNAME}\AppData\Roaming\Python\Python${python_ ## Usage ```bash -backup_imap.sh [--debug-level|-d CRITICAL|ERROR|WARNING|INFO|DEBUG|NOTSET] # Other parameters +Usage: backup_imap.py [OPTIONS] + +Options: + -d, --debug-level [CRITICAL|ERROR|WARNING|INFO|DEBUG|NOTSET] + Set the debug level for the standard output. + -l, --log-file TEXT File to store all debug messages. + -s, --imap-server TEXT Hostname or IP of the IMAP server + [required] + -p, --imap-port INTEGER IMAP port to contact the server + -S, --use-ssl Use SSL to contact the IMAP server + -u, --imap-user TEXT User to connect to IMAP server [required] + -P, --imap-password TEXT User password to conect to IMAP server + [required] + -m, --mailbox TEXT Mailbox to backup + -F, --destination-folder TEXT Folder to save the messages and folders + [required] + --config FILE Read configuration from FILE. + --help Show this message and exit. ``` diff --git a/backup_imap/backup_imap.py b/backup_imap/backup_imap.py index 63e8911..cdec263 100644 --- a/backup_imap/backup_imap.py +++ b/backup_imap/backup_imap.py @@ -47,10 +47,6 @@ class BackupImap: 'backup_imap.log' ) self._init_log() - self._default_data = { - "last_update": 0, - } - self.data = self._read_cached_data() if not os.path.exists(self.config['destination_folder']): os.mkdir(self.config['destination_folder']) @@ -200,33 +196,7 @@ class BackupImap: sys.exit(4) def close(self): - '''Close class and save data''' - self._save_cached_data(self.data) - - def _read_cached_data(self): - if os.path.exists(self.config['cache_file']): - with open(self.config['cache_file'], 'r', encoding='utf-8') as cache_file: - try: - cached_data = json.load(cache_file) - if ( - 'last_update' in cached_data and - cached_data['last_update'] + self.config['max_cache_age'] > time.time() - ): - cached_data = self._default_data - except json.decoder.JSONDecodeError: - cached_data = self._default_data - return cached_data - else: - return self._default_data - - def _save_cached_data(self, data): - data['last_update'] = time.time() - with open(self.config['cache_file'], 'w', encoding='utf-8') as cache_file: - json.dump(data, cache_file, indent=2) - self._log.debug( - "Saved cached data in '%s'", - self.config['cache_file'] - ) + '''Close class''' def _init_log(self): ''' Initialize log object ''' @@ -285,12 +255,6 @@ class BackupImap: default=f"{LOG_FOLDER}/backup_imap.log", help="File to store all debug messages." ) -@click.option( - '--cache-file', - '-f', - default=f"{CACHE_FOLDER}/backup_imap.json", - help='Cache file to store data from each run', -) @click.option( '--imap-server', '-s', @@ -334,18 +298,6 @@ class BackupImap: required=True, help='Folder to save the messages and folders' ) -@click.option( - '--batch-size', - '-b', - default=1000, - help='Maximun number of messages to fetch per request' -) -@click.option( - '--max-cache-age', - '-a', - default=60*60*24*7, - help='Max age in seconds for the cache' -) # @click.option("--dummy","-n", is_flag=True, # help="Don't do anything, just show what would be done.") @click_config_file.configuration_option()