-
Notifications
You must be signed in to change notification settings - Fork 0
/
mail_tools.py
296 lines (279 loc) · 10 KB
/
mail_tools.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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
import requests
import os
from apscheduler.schedulers.asyncio import AsyncIOScheduler
from main_startup.core.decorators import friday_on_cmd
from main_startup.helper_func.basic_helpers import edit_or_reply, get_text
from main_startup import Friday
from main_startup.config_var import Config
from xtraplugins.dB.mail_tools import (
add_mail_update_mail,
get_msg_id,
get_mail_id,
add_msg_update_msg,
delete_mail_id
)
supported_domains = ["esiix.com", "1secmail.net", "wwjmp.com", "1secmail.org", "1secmail.com"]
@friday_on_cmd(
["add_mail"],
is_official=False,
cmd_help={
"help": "Create Temporary Mail!",
"example": "{ch}add_mail (mail-id)"
}
)
async def add_mail_to_db(client, message):
pablo = await edit_or_reply(message, "`Processing.....`")
mail_id = get_text(message)
if not mail_id:
await pablo.edit("`Please Give Me A Valid Input. You Can Check Help Menu To Know More!`")
return
lmao = mail_id.split("@", 1)
try:
domain = lmao[1]
except BaseException:
await pablo.edit(
"`What are you providing me lmao?. Check Help Menu Idiot!`"
)
return
if domain.lower() in supported_domains:
pass
else:
await pablo.edit("`Oops, I don't Support that Domain! Check Help Menu To Get Supported Site List!`")
return
await add_mail_update_mail(mail_id)
await pablo.edit(f"`Your Mail ID {mail_id} successfully added to dB`")
@friday_on_cmd(
["list_mails"],
is_official=False,
cmd_help={
"help": "Get List Of Available Mail Domains!",
"example": "{ch}list_mails"
}
)
async def list_mails(client, message):
pablo = await edit_or_reply(message, "`Processing.....`")
cap = "List Of Available Mail Domains Are : \n\n"
for x in supported_domains:
cap +=f"`{x}` \n"
await pablo.edit(cap)
@friday_on_cmd(
["check_mail"],
is_official=False,
cmd_help={
"help": "Check Temporary Mail",
"example": "{ch}check_mail",
},
)
async def check_mail(client, message):
pablo = await edit_or_reply(message, "`Processing.....`")
email = await get_mail_id()
if not email:
await pablo.edit("`You Sure You Added Your Mail To dB?`")
return
caption = ""
mail_ = email.split("@", 1)
login = mail_[0]
domain = mail_[1]
link = f"https://www.1secmail.com/api/v1/?action=getMessages&login={login}&domain={domain}"
r = requests.get(link)
r_json = r.json()
try:
latest_mail = r_json[0].get('id')
except IndexError:
await pablo.edit("`You Don't Have Any Mails Yet ;( Ask Your Gf To Send Some Nudes!`")
return
kk = f"https://www.1secmail.com/api/v1/?action=readMessage&login={login}&domain={domain}&id={latest_mail}"
r = requests.get(kk)
lmao = r.json()
is_file = False
if lmao["attachments"] != []:
fl_name = lmao["attachments"][0].get("filename")
is_file = True
lenk = f'https://www.1secmail.com/api/v1/?action=download&login={login}&domain={domain}&id={lmao.get("id")}&file={fl_name}'
r = requests.get(lenk)
with open(fl_name, 'wb') as f:
f.write(r.content)
fromo = lmao.get("from")
date = lmao.get("date")
sub = lmao.get("subject")
body = lmao.get("textBody")
last = f"""**Mail From :** {fromo}
**Date :** {date}
**Subject :** {sub}
**Body :** {body}"""
if not is_file:
if len(last) > 1024:
file_names = "email.text"
open(file_names, "w").write(last)
await client.send_document(message.chat.id, file_names, caption = "Your Mail")
os.remove(file_names)
else:
await client.send_message(
message.chat.id, last)
else:
if len(last) > 1024:
await client.send_document(message.chat.id, fl_name, caption = "Your Mail Attachment")
await client.send_document(message.chat.id, file_names, caption = "Your Mail")
os.remove(fl_name)
os.remove(file_names)
else:
await client.send_document(message.chat.id, fl_name, caption = last)
os.remove(fl_name)
await pablo.delete()
@friday_on_cmd(
["my_mail"],
is_official=False,
cmd_help={
"help": "Get Your Temporary Mail Id",
"example": "{ch}my_mail",
},
)
async def my_mail(client, message):
pablo = await edit_or_reply(message, "`Processing.....`")
email = await get_mail_id()
if not email:
await pablo.edit("`You Sure You Added Your Mail To dB?`")
return
await pablo.edit(f"Hey Boss, Your Mail ID is : `{email}`")
@friday_on_cmd(
["all_mails"],
is_official=False,
cmd_help={
"help": "Get All Your Mails At Ones",
"example": "{ch}all_mails",
},
)
async def all_mails(client, message):
pablo = await edit_or_reply(message, "`Processing.....`")
email = await get_mail_id()
if not email:
await pablo.edit("`You Sure You Added Your Mail To dB?`")
return
last_msg = await get_msg_id(email)
msg_ids = []
mail_ = email.split("@", 1)
login = mail_[0]
domain = mail_[1]
link = f"https://www.1secmail.com/api/v1/?action=getMessages&login={login}&domain={domain}"
r = requests.get(link)
r_json = r.json()
for lol in r_json:
msg_ids.append(lol.get("id"))
if msg_ids == []:
await pablo.edit("You Didn't Receive Any Mails")
return
for id in msg_ids:
kk = f"https://www.1secmail.com/api/v1/?action=readMessage&login={login}&domain={domain}&id={id}"
r = requests.get(kk)
lmao = r.json()
is_file = False
if lmao["attachments"] != []:
fl_name = lmao["attachments"][0].get("filename")
is_file = True
lenk = f'https://www.1secmail.com/api/v1/?action=download&login={login}&domain={domain}&id={id}&file={fl_name}'
r = requests.get(lenk)
with open(fl_name, 'wb') as f:
f.write(r.content)
fromo = lmao.get("from")
date = lmao.get("date")
sub = lmao.get("subject")
body = lmao.get("textBody")
last = f"""**Mail From :** {fromo}
**Date :** {date}
**Subject :** {sub}
**Body :** {body}"""
if not is_file:
if len(last) > 1024:
file_names = "email.text"
open(file_names, "w").write(last)
await client.send_document(message.chat.id, file_names, caption = "Your Mail")
os.remove(file_names)
else:
await client.send_message(
message.chat.id, last)
else:
if len(last) > 1024:
await client.send_document(message.chat.id, fl_name, caption = "Your Mail Attachment")
await client.send_document(message.chat.id, file_names, caption = "Your Mail")
os.remove(fl_name)
os.remove(file_names)
else:
await client.send_document(message.chat.id, fl_name, caption = last)
os.remove(fl_name)
await pablo.delete()
@friday_on_cmd(
["delete_mail"],
is_official=False,
cmd_help={
"help": "Delete Temporary Mail",
"example": "{ch}delete_mail",
},
)
async def delete_mail(client, message):
pablo = await edit_or_reply(message, "`Processing.....`")
email = await get_mail_id()
if not email:
await pablo.edit("`You Sure You Added Your Mail To dB?`")
return
await delete_mail_id()
await pablo.edit("Successfully Deleted Your Email")
async def track_mails():
email = await get_mail_id()
if not email:
return
caption = ""
last_msg = await get_msg_id(email)
mail_ = email.split("@", 1)
login = mail_[0]
domain = mail_[1]
link = f"https://www.1secmail.com/api/v1/?action=getMessages&login={login}&domain={domain}"
r = requests.get(link)
r_json = r.json()
try:
latest_mail = r_json[0].get('id')
except IndexError:
return
if last_msg == latest_mail:
return
else:
await add_msg_update_msg(latest_mail)
kk = f"https://www.1secmail.com/api/v1/?action=readMessage&login={login}&domain={domain}&id={latest_mail}"
r = requests.get(kk)
lmao = r.json()
is_file = False
if lmao["attachments"] != []:
fl_name = lmao["attachments"][0].get("filename")
is_file = True
lenk = f'https://www.1secmail.com/api/v1/?action=download&login={login}&domain={domain}&id={lmao.get("id")}&file={fl_name}'
r = requests.get(lenk)
with open(fl_name, 'wb') as f:
f.write(r.content)
fromo = lmao.get("from")
date = lmao.get("date")
sub = lmao.get("subject")
body = lmao.get("textBody")
last = f"""**Mail From :** {fromo}
**Date :** {date}
**Subject :** {sub}
**Body :** {body}"""
if not is_file:
if len(last) > 1024:
file_names = "email.text"
open(file_names, "w").write(last)
await Friday.send_document(Config.LOG_GRP, file_names, caption = "Your Mail")
os.remove(file_names)
else:
await Friday.send_message(
Config.LOG_GRP, last)
else:
if len(last) > 1024:
await Friday.send_document(Config.LOG_GRP, fl_name, caption = "Your Mail Attachment")
await Friday.send_document(Config.LOG_GRP, file_names, caption = "Your Mail")
os.remove(fl_name)
os.remove(file_names)
else:
await Friday.send_document(Config.LOG_GRP, fl_name, caption = last)
os.remove(fl_name)
scheduler = AsyncIOScheduler()
scheduler.add_job(track_mails, 'interval', minutes=5)
scheduler.start()