84 lines
2.2 KiB
Python
84 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
|
"""Simple Proton Mail Bridge IMAP test - clean version"""
|
|
|
|
import socket
|
|
|
|
IMAP_HOST = "127.0.0.1"
|
|
IMAP_PORT = 1143
|
|
USERNAME = "alexthenerdyai@proton.me"
|
|
PASSWORD = "Is413#dfslw@alex"
|
|
|
|
def get_response(sock, tag):
|
|
"""Read response until we see our tag"""
|
|
response = b""
|
|
while True:
|
|
chunk = sock.recv(4096)
|
|
if not chunk:
|
|
break
|
|
response += chunk
|
|
if tag.encode() in response:
|
|
break
|
|
return response.decode()
|
|
|
|
def main():
|
|
print("=" * 50)
|
|
print("Proton Mail Bridge - IMAP Test")
|
|
print("=" * 50)
|
|
|
|
# Connect
|
|
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
|
sock.settimeout(10)
|
|
sock.connect((IMAP_HOST, IMAP_PORT))
|
|
|
|
# Greeting
|
|
greeting = sock.recv(1024).decode()
|
|
print(f"\n[CONNECT] {greeting.strip()[:80]}...")
|
|
|
|
# Login
|
|
sock.send(f'A1 LOGIN "{USERNAME}" "{PASSWORD}"\r\n'.encode())
|
|
resp = get_response(sock, "A1 OK")
|
|
print("[LOGIN] Success!")
|
|
|
|
# List folders with LSUB
|
|
sock.send(b'A2 LSUB "" "*"\r\n')
|
|
resp = get_response(sock, "A2 OK")
|
|
print("\n[FOLDERS]")
|
|
folders = []
|
|
for line in resp.split('\r\n'):
|
|
if 'LSUB' in line and '/' in line:
|
|
folder = line.split('"/"')[-1].strip().strip('"')
|
|
folders.append(folder)
|
|
print(f" - {folder}")
|
|
|
|
# Check INBOX
|
|
sock.send(b'A3 EXAMINE "INBOX"\r\n')
|
|
resp = get_response(sock, "A3 OK")
|
|
|
|
# Count messages
|
|
exists = 0
|
|
for line in resp.split('\r\n'):
|
|
if 'EXISTS' in line:
|
|
exists = int(line.split()[1])
|
|
break
|
|
print(f"\n[INBOX] {exists} total messages")
|
|
|
|
# Check unread
|
|
sock.send(b'A4 SEARCH UNSEEN\r\n')
|
|
resp = get_response(sock, "A4 OK")
|
|
unseen_count = 0
|
|
for line in resp.split('\r\n'):
|
|
if 'SEARCH' in line and '*' in line:
|
|
parts = line.split('SEARCH')
|
|
if len(parts) > 1:
|
|
unseen = parts[1].strip().split()
|
|
unseen_count = len(unseen) if unseen and unseen[0] else 0
|
|
print(f"[INBOX] {unseen_count} unread messages")
|
|
|
|
# Logout
|
|
sock.send(b'A5 LOGOUT\r\n')
|
|
print("\n[LOGOUT] Done!")
|
|
sock.close()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|