-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdebug_folders.py
More file actions
executable file
·144 lines (116 loc) · 4.46 KB
/
debug_folders.py
File metadata and controls
executable file
·144 lines (116 loc) · 4.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
#!/usr/bin/env python3
"""
Debug script to see all IMAP folders and what gets filtered
"""
import imaplib
import sys
def debug_folders(email_addr, oauth_token):
"""Debug Gmail folder detection"""
print(f"Connecting to Gmail IMAP for: {email_addr}")
print("=" * 80)
try:
# Connect to Gmail IMAP with OAuth
imap = imaplib.IMAP4_SSL('imap.gmail.com')
# Authenticate using OAuth2
auth_string = f'user={email_addr}\x01auth=Bearer {oauth_token}\x01\x01'
def auth_callback(response):
return auth_string.encode('utf-8')
imap.authenticate('XOAUTH2', auth_callback)
print("✓ Authentication successful\n")
# List ALL folders
print("RAW IMAP LIST OUTPUT:")
print("-" * 80)
status, folders = imap.list()
if status != 'OK':
print("Failed to list folders")
return
all_folders = []
for folder in folders:
if isinstance(folder, bytes):
folder_str = folder.decode('utf-8')
else:
folder_str = folder
print(folder_str)
# Extract folder name using same logic as backend
parts = folder_str.split('"')
if len(parts) >= 3:
folder_name = parts[-2]
all_folders.append(folder_name)
print("\n" + "=" * 80)
print("EXTRACTED FOLDER NAMES (what backend sees):")
print("-" * 80)
for name in sorted(all_folders):
is_gmail_folder = name.startswith('[Gmail]/')
in_whitelist = name in ['[Gmail]/All Mail', '[Gmail]/Sent Mail', '[Gmail]/Trash', '[Gmail]/Spam']
will_include = (not is_gmail_folder) or in_whitelist
status_icon = "✓" if will_include else "✗"
print(f" {status_icon} {name}")
print("\n" + "=" * 80)
print("FOLDERS THAT WILL BE ANALYZED:")
print("-" * 80)
included = []
excluded = []
for name in all_folders:
is_gmail_folder = name.startswith('[Gmail]/')
in_whitelist = name in ['[Gmail]/All Mail', '[Gmail]/Sent Mail', '[Gmail]/Trash', '[Gmail]/Spam']
if not is_gmail_folder:
included.append(name)
elif in_whitelist:
included.append(name)
else:
excluded.append(name)
print(f"\nINCLUDED ({len(included)}):")
for name in sorted(included):
print(f" ✓ {name}")
if excluded:
print(f"\nEXCLUDED ({len(excluded)}):")
for name in sorted(excluded):
print(f" ✗ {name}")
# Test specific folders
print("\n" + "=" * 80)
print("TESTING SPECIFIC FOLDERS:")
print("-" * 80)
test_folders = [
'[Gmail]/All Mail',
'[Gmail]/Sent Mail',
'[Gmail]/Trash',
'[Gmail]/Spam',
'INBOX',
]
for folder_name in test_folders:
try:
status, data = imap.select(f'"{folder_name}"', readonly=True)
if status == 'OK':
msg_count = 0
if data and data[0]:
msg_count = int(data[0].decode('utf-8'))
print(f" ✓ {folder_name}: {msg_count} messages")
else:
print(f" ✗ {folder_name}: Cannot select (status: {status})")
except Exception as e:
print(f" ✗ {folder_name}: Error - {e}")
# Clean disconnect
imap.logout()
except Exception as e:
print(f"\n❌ Error: {e}")
import traceback
traceback.print_exc()
if __name__ == "__main__":
print("Gmail Folder Debug Tool")
print("=" * 80)
print()
# Get credentials
if len(sys.argv) != 3:
print("Usage: python debug_folders.py <email> <oauth_token>")
print()
print("To get your OAuth token:")
print("1. Go to: https://gmail-storage-analyzer.vercel.app")
print("2. Sign in with Google")
print("3. Open browser console (F12)")
print("4. Type: accessToken")
print("5. Copy the token value")
print()
sys.exit(1)
email = sys.argv[1]
token = sys.argv[2]
debug_folders(email, token)