Update all
This commit is contained in:
+30
-13
@@ -12,7 +12,7 @@ import time # Import time module for sleep functionality
|
||||
load_dotenv()
|
||||
|
||||
# Define server details
|
||||
host = "180.1.1.164"
|
||||
host = "imap.strato.de"
|
||||
port = 993
|
||||
|
||||
# Function to send an email notification
|
||||
@@ -66,7 +66,8 @@ while True:
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
email TEXT,
|
||||
messages_transferred INTEGER,
|
||||
date TEXT
|
||||
date TEXT,
|
||||
auth_failed INTEGER DEFAULT 0
|
||||
)
|
||||
''')
|
||||
|
||||
@@ -92,13 +93,21 @@ while True:
|
||||
username, password, domain = user
|
||||
local_part = username.split('@')[0]
|
||||
print(f"User: {username} running.")
|
||||
|
||||
# Check if the user previously had an authentication failure
|
||||
cursor.execute("SELECT auth_failed FROM sync_results WHERE email = ? ORDER BY date DESC LIMIT 1", (username,))
|
||||
result = cursor.fetchone()
|
||||
if result and result[0] == 1:
|
||||
print(f"Skipping {username} due to previous authentication failure.")
|
||||
# continue # Skip this user due to previous authentication failure
|
||||
|
||||
# Command for imapsync
|
||||
command = [
|
||||
"imapsync",
|
||||
"--host1", domain,
|
||||
"--user1", username,
|
||||
"--password1", password,
|
||||
"--host2", "180.1.1.164",
|
||||
"--host2", "192.168.178.90",
|
||||
"--user2", "archiv@trendsetzer.eu",
|
||||
"--password2", "Ln0m2YQZd23H54L5tCiyjIBWLEn8mk36v7KauqS8QFGzu",
|
||||
"--subfolder2", f"{local_part}",
|
||||
@@ -112,29 +121,37 @@ while True:
|
||||
result = subprocess.run(command, capture_output=True, text=True)
|
||||
output = result.stdout
|
||||
|
||||
# Initialize variables
|
||||
auth_failed = 0
|
||||
transferred_count = 0
|
||||
|
||||
# Check for EXIT_AUTHENTICATION_FAILURE_USER error
|
||||
if "EXIT_AUTHENTICATION_FAILURE_USER" in output:
|
||||
subject = f"Authentication Failure for {username}"
|
||||
body = f"An authentication failure occurred for user {username} during IMAP sync."
|
||||
send_email(subject, body, os.getenv('TO_EMAIL'))
|
||||
auth_failed = 1 # Mark authentication failure
|
||||
|
||||
# Find and extract the "Messages transferred" line
|
||||
for line in output.splitlines():
|
||||
if "Messages transferred" in line:
|
||||
transferred_messages = line.split(":")[-1].strip()
|
||||
transferred_count = int(transferred_messages)
|
||||
current_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# Insert result into SQLite database
|
||||
cursor.execute('''
|
||||
INSERT INTO sync_results (email, messages_transferred, date)
|
||||
VALUES (?, ?, ?)
|
||||
''', (username, transferred_count, current_date))
|
||||
conn.commit()
|
||||
print(f"Data inserted for {username}: {transferred_count} messages on {current_date}")
|
||||
break
|
||||
|
||||
# Insert into the database if messages were transferred or if there was an auth failure
|
||||
if transferred_count > 0 or auth_failed == 1:
|
||||
current_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
# Insert result into SQLite database
|
||||
cursor.execute('''
|
||||
INSERT INTO sync_results (email, messages_transferred, date, auth_failed)
|
||||
VALUES (?, ?, ?, ?)
|
||||
''', (username, transferred_count, current_date, auth_failed))
|
||||
conn.commit()
|
||||
print(f"Data inserted for {username}: {transferred_count} messages on {current_date}")
|
||||
else:
|
||||
print(f"No 'Messages transferred' line found for {username}.")
|
||||
print(f"No messages transferred for {username}.")
|
||||
except Exception as e:
|
||||
print(f"Error running imapsync for {username}: {e}")
|
||||
|
||||
|
||||
Reference in New Issue
Block a user