#!/usr/bin/env python3 """Quick test of Proton Mail Bridge IMAP connectivity""" import socket import ssl import base64 # Proton Bridge settings IMAP_HOST = "127.0.0.1" IMAP_PORT = 1143 USERNAME = "alexthenerdyai@proton.me" PASSWORD = "8yiNBTJBMc6HyOQjIZKjMw" def send_command(sock, cmd): """Send IMAP command and get response""" sock.send(f"{cmd}\r\n".encode()) response = b"" while True: try: sock.settimeout(5) chunk = sock.recv(4096) if not chunk: break response += chunk # Check if we got a complete response (ends with \r\n) if b"\r\n" in chunk: break except socket.timeout: break return response.decode() def main(): print("=" * 50) print("Proton Mail Bridge IMAP Test") print("=" * 50) # Connect to IMAP server print(f"\n[1] Connecting to {IMAP_HOST}:{IMAP_PORT}...") sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.settimeout(10) try: sock.connect((IMAP_HOST, IMAP_PORT)) greeting = sock.recv(1024).decode() print(f"[OK] Connected! Server: {greeting.strip()}") except Exception as e: print(f"[ERR] Connection failed: {e}") return # Authenticate with LOGIN print("\n[2] Authenticating...") response = send_command(sock, f'A1 LOGIN "{USERNAME}" "{PASSWORD}"') if "OK" in response and "completed" in response.lower(): print("[OK] Authentication successful!") elif "OK" in response: print("[OK] Authentication successful!") else: print(f"[ERR] Authentication failed: {response.strip()}") sock.close() return # List folders print("\n[3] Listing mailboxes...") # Try LSUB first (subscribed folders) response = send_command(sock, 'A2a LSUB "" "*"') print(f"LSUB response:\n{response}") response = send_command(sock, 'A2b LIST "" "*"') print(f"LIST response:\n{response}") folders = [] for line in response.split("\r\n"): if 'LSUB' in line: # Parse folder name from LSUB response if '"/' in line: folder = line.split('"/"')[-1].strip().strip('"') else: folder = line.split()[-1].strip().strip('"') folders.append(folder) print(f" [FOLDER] {folder}") # Check INBOX for unread print("\n[4] Checking INBOX...") response = send_command(sock, 'A3 EXAMINE "INBOX"') print(f"EXAMINE response: {response[:200]}") # Search for unread messages response = send_command(sock, 'A4 SEARCH UNSEEN') print(f"SEARCH response: {response[:200]}") if 'SEARCH' in response: unseen = response.split('SEARCH')[1].strip().split() if unseen and unseen[0] != '': print(f"[OK] {len(unseen)} unread messages") else: print("[OK] No unread messages") else: print(" Could not check unread count") # Logout print("\n[5] Logging out...") send_command(sock, "A5 LOGOUT") print("[OK] Done!") sock.close() if __name__ == "__main__": main()