Bug fix in reconnection handling
This commit is contained in:
parent
d496749ddd
commit
325f3311a5
1
.gitignore
vendored
1
.gitignore
vendored
@ -5,3 +5,4 @@ __pycache__/
|
|||||||
migration.log
|
migration.log
|
||||||
statistics.json
|
statistics.json
|
||||||
venv/
|
venv/
|
||||||
|
migration_checkpoint.json
|
||||||
|
|||||||
21
migrate.py
21
migrate.py
@ -438,7 +438,7 @@ def migrate_all(source_conn, dest_conn, simulation=False):
|
|||||||
# --- Force a reconnection every 500 emails ---
|
# --- Force a reconnection every 500 emails ---
|
||||||
if current_email > 0 and current_email % RECONNECT_INTERVAL == 0:
|
if current_email > 0 and current_email % RECONNECT_INTERVAL == 0:
|
||||||
logger.debug("Forcing periodic reconnection of IMAP connections...")
|
logger.debug("Forcing periodic reconnection of IMAP connections...")
|
||||||
reconnect(source_folder)
|
source_conn, dest_conn = reconnect(source_folder)
|
||||||
# ---------------------------------------------------------
|
# ---------------------------------------------------------
|
||||||
|
|
||||||
# **Reduce IMAP request rate** (prevent timeouts/rate limiting)
|
# **Reduce IMAP request rate** (prevent timeouts/rate limiting)
|
||||||
@ -448,7 +448,7 @@ def migrate_all(source_conn, dest_conn, simulation=False):
|
|||||||
|
|
||||||
except imaplib.IMAP4.abort as e:
|
except imaplib.IMAP4.abort as e:
|
||||||
logger.error(f"IMAP connection lost during migration (mail #{num}). Error: {e}")
|
logger.error(f"IMAP connection lost during migration (mail #{num}). Error: {e}")
|
||||||
reconnect(source_folder)
|
source_conn, dest_conn = reconnect(source_folder)
|
||||||
|
|
||||||
progress_bar.close()
|
progress_bar.close()
|
||||||
|
|
||||||
@ -473,11 +473,20 @@ def migrate_all(source_conn, dest_conn, simulation=False):
|
|||||||
return total_emails, total_size_mb, skipped_emails
|
return total_emails, total_size_mb, skipped_emails
|
||||||
|
|
||||||
def reconnect(source_folder):
|
def reconnect(source_folder):
|
||||||
reconnect_imap(DEST_IMAP_SERVER, DEST_EMAIL, DEST_PASSWORD)
|
"""
|
||||||
source_conn = reconnect_imap(SOURCE_IMAP_SERVER, SOURCE_EMAIL, SOURCE_PASSWORD)
|
Reconnects both the source and destination IMAP connections and re-selects
|
||||||
|
the specified source folder.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
new_source_conn, new_dest_conn: The new connection objects.
|
||||||
|
"""
|
||||||
|
new_dest_conn = reconnect_imap(DEST_IMAP_SERVER, DEST_EMAIL, DEST_PASSWORD)
|
||||||
|
new_source_conn = reconnect_imap(SOURCE_IMAP_SERVER, SOURCE_EMAIL, SOURCE_PASSWORD)
|
||||||
|
new_source_conn.select(source_folder, readonly=True)
|
||||||
|
|
||||||
# Re-select the source folder after reconnecting.
|
time.sleep(0.5) # wait a few milliseconds
|
||||||
source_conn.select(source_folder, readonly=True)
|
|
||||||
|
return new_source_conn, new_dest_conn
|
||||||
|
|
||||||
# -------------------------------
|
# -------------------------------
|
||||||
# Now update your get_folder_mapping_info to use the consolidated function.
|
# Now update your get_folder_mapping_info to use the consolidated function.
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user