diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000..5008ddf Binary files /dev/null and b/.DS_Store differ diff --git a/.gitignore b/.gitignore index c7baf76..0264179 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ list_alias.py -malias.zip \ No newline at end of file +malias.zip +malias_local.py \ No newline at end of file diff --git a/malias.py b/malias.py index b2e375d..6e48023 100644 --- a/malias.py +++ b/malias.py @@ -29,7 +29,7 @@ database = filepath.joinpath('malias.db') logfile = filepath.joinpath('malias.log') Path(filepath).mkdir(parents=True, exist_ok=True) logging.basicConfig(filename=logfile,level=logging.INFO,format='%(message)s') -app_version = '0.1' +app_version = '0.2' def connect_database(): @@ -294,12 +294,38 @@ def check_local_db(alias_id): def search(alias): - results = checklist(alias) + apikey = get_api() mail_server = get_settings('mail_server') - if results == True: - print('\n\nThe mail address %s exists. Using the mailcow instance : %s\n\n'%(alias,mail_server)) + cursor = conn.cursor() + cursor.execute('SELECT data_copy FROM settings where id = 1') + result = cursor.fetchone()[0] + if result == 1: + search_term = '%'+alias+'%' + cursor.execute('SELECT * from aliases where alias like ? or goto like ?',(search_term,search_term,)) + remoteData = cursor.fetchall() + i = 0 + print('\nAliases on %s that contains %s' %(mail_server,alias)) + print('=================================================================') + for search in remoteData: + the_alias = remoteData[i][1].ljust(20,' ') + print(the_alias + '\tgoes to\t\t' + remoteData[i][2]) + i=i+1 + print('\n\nData from local DB') else: - print('\n\nThe mail address %s [b]does not[/b] exists. Using the mailcow instance : %s\n\n'%(alias,mail_server)) + req = urllib.request.Request('https://'+mail_server+'/api/v1/get/alias/all') + req.add_header('Content-Type', 'application/json') + req.add_header('X-API-Key', apikey) + current = urllib.request.urlopen(req) + remote = current.read().decode('utf-8') + remoteData = json.loads(remote) + i = 0 + print('\nAliases on %s that contains %s' %(mail_server,alias)) + print('=================================================') + for search in remoteData: + if alias in remoteData[i]['address'] or alias in remoteData[i]['goto']: + print(remoteData[i]['address'] + '\tgoes to\t\t' + remoteData[i]['goto']) + i=i+1 + print('\n\nData from server')