-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp_cli.py
More file actions
executable file
·67 lines (56 loc) · 1.72 KB
/
app_cli.py
File metadata and controls
executable file
·67 lines (56 loc) · 1.72 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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import argparse
import email
import imaplib
PARSER = argparse.ArgumentParser(description='Parse inbox email address in mail.ru')
PARSER.add_argument('-e', help='email address', required=True)
PARSER.add_argument('-p', help='password', required=True)
ARGS = vars(PARSER.parse_args())
EMAIL = ARGS['e']
PASSWORD = ARGS['p']
BADWORDS = [words.strip() for words in open('badwords.txt').readlines()]
def UniqueList(LIST):
seen = set()
result = []
for mail in LIST:
if mail in seen:
continue
seen.add(mail)
result.append(mail)
LIST = result
return LIST
def CheckBadWords(LIST):
bad_list = []
for mail in LIST:
for word in BADWORDS:
if word in mail:
bad_list.append(mail)
break
for bad in bad_list:
LIST.remove(bad)
return LIST
mail = imaplib.IMAP4_SSL('imap.mail.ru')
mail.login(EMAIL, PASSWORD)
mail.select("Inbox")
result, data = mail.uid('search', None, "ALL")
email_uid_list = data[0].split()
email_list = []
counter = 0
for i in email_uid_list:
try:
counter += 1
result, data = mail.uid('fetch', i, '(RFC822)')
raw_email = data[0][1]
email_message = email.message_from_bytes(raw_email)
email_list.append(email.utils.parseaddr(email_message['From'])[1])
print("Cheking mail: {}/{}".format(counter, len(email_uid_list)), end="\r")
except TypeError as e:
print(e)
except AttributeError as e:
print(e)
unique_list = UniqueList(email_list)
result_list = CheckBadWords(unique_list)
with open("result/{}.txt".format(EMAIL), 'w', encoding='utf-8') as f:
for i in result_list:
f.write(i + '\n')