supports syncing of folders.
This commit is contained in:
@@ -205,7 +205,12 @@ def update_folder(folder_id):
|
||||
@login_required
|
||||
def imap_config_modal():
|
||||
"""Return the IMAP configuration modal."""
|
||||
response = make_response(render_template('partials/imap_config_modal.html'))
|
||||
# Pass existing IMAP config to the template if it exists
|
||||
response = make_response(render_template('partials/imap_config_modal.html',
|
||||
server=current_user.imap_config.get('server') if current_user.imap_config else None,
|
||||
port=current_user.imap_config.get('port') if current_user.imap_config else None,
|
||||
username=current_user.imap_config.get('username') if current_user.imap_config else None,
|
||||
use_ssl=current_user.imap_config.get('use_ssl', True) if current_user.imap_config else True))
|
||||
response.headers['HX-Trigger'] = 'open-modal'
|
||||
return response
|
||||
|
||||
@@ -213,6 +218,7 @@ def imap_config_modal():
|
||||
@login_required
|
||||
def test_imap_connection():
|
||||
"""Test IMAP connection with provided configuration."""
|
||||
print("HELLO")
|
||||
try:
|
||||
# Get form data
|
||||
server = request.form.get('server')
|
||||
@@ -235,7 +241,7 @@ def test_imap_connection():
|
||||
errors['password'] = 'Password is required'
|
||||
|
||||
if errors:
|
||||
response = make_response(render_template('partials/imap_config_modal.html', errors=errors))
|
||||
response = make_response(render_template('partials/imap_config_modal.html', errors=errors, server=server, port=port, username=username, use_ssl=use_ssl))
|
||||
response.headers['HX-Retarget'] = '#imap-modal'
|
||||
response.headers['HX-Reswap'] = 'outerHTML'
|
||||
return response
|
||||
@@ -246,7 +252,7 @@ def test_imap_connection():
|
||||
'port': int(port),
|
||||
'username': username,
|
||||
'password': password,
|
||||
'use_ssl': use_ssl,
|
||||
'use_ssl': False,
|
||||
'use_tls': False,
|
||||
'connection_timeout': 30
|
||||
}
|
||||
@@ -254,6 +260,7 @@ def test_imap_connection():
|
||||
# Test connection
|
||||
temp_user = type('User', (), {'imap_config': test_config})()
|
||||
imap_service = IMAPService(temp_user)
|
||||
print(temp_user, test_config)
|
||||
success, message = imap_service.test_connection()
|
||||
|
||||
if success:
|
||||
@@ -266,8 +273,9 @@ def test_imap_connection():
|
||||
response.headers['HX-Retarget'] = '#imap-modal'
|
||||
response.headers['HX-Reswap'] = 'outerHTML'
|
||||
else:
|
||||
print(message)
|
||||
response = make_response(render_template('partials/imap_config_modal.html',
|
||||
errors={'general': message}))
|
||||
errors={'general': message}, server=server, port=port, username=username, use_ssl=use_ssl))
|
||||
response.headers['HX-Retarget'] = '#imap-modal'
|
||||
response.headers['HX-Reswap'] = 'outerHTML'
|
||||
|
||||
@@ -275,8 +283,9 @@ def test_imap_connection():
|
||||
|
||||
except Exception as e:
|
||||
logging.exception("Error testing IMAP connection: %s", e)
|
||||
print(e)
|
||||
errors = {'general': 'An unexpected error occurred. Please try again.'}
|
||||
response = make_response(render_template('partials/imap_config_modal.html', errors=errors))
|
||||
response = make_response(render_template('partials/imap_config_modal.html', errors=errors, server=server, port=port, username=username, use_ssl=use_ssl))
|
||||
response.headers['HX-Retarget'] = '#imap-modal'
|
||||
response.headers['HX-Reswap'] = 'outerHTML'
|
||||
return response
|
||||
@@ -302,4 +311,5 @@ def sync_imap_folders():
|
||||
|
||||
except Exception as e:
|
||||
logging.exception("Error syncing IMAP folders: %s", e)
|
||||
return jsonify({'error': 'An unexpected error occurred. Please try again.'}), 500
|
||||
print(e)
|
||||
return jsonify({'error': 'An unexpected error occurred. Please try again.'}), 500
|
||||
|
||||
Reference in New Issue
Block a user