Skip to content

Commit 6a3564e

Browse files
committed
Added Attachment Downloader Folder
1 parent d7aed7e commit 6a3564e

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

Attachment_Downloader/attachment.py

+38
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import ezgmail
2+
3+
def attachmentdownload(resulthreads):
4+
try:
5+
for i in range(len(resulthreads)):
6+
if len(resulthreads[i].messages) > 1:
7+
for j in range(len(resulthreads[i].messages)):
8+
resulthreads[i].messages[j].downloadAllAttachments()
9+
else:
10+
resulthreads[i].messages[0].downloadAllAttachments()
11+
except:
12+
raise Exception("Error occured while downloading attachment(s).")
13+
finally:
14+
print("Download compelete. Please check your root directory.")
15+
16+
if __name__ == '__main__':
17+
query = input("Enter search query: ")
18+
newquery = query + " + has:attachment"
19+
resulthreads = ezgmail.search(newquery)
20+
21+
if len(resulthreads) == 0:
22+
print("Results have no attachments")
23+
else:
24+
print("Results: ")
25+
for threads in resulthreads:
26+
print(f"Email Subject: {threads.messages[0].subject}")
27+
try:
28+
ask = input("Do you want to download attachment(s) in results (Yes/No)? ")
29+
if ask == "Yes":
30+
attachmentdownload(resulthreads)
31+
else:
32+
print("Program exited")
33+
except:
34+
print("Something went wrong")
35+
36+
37+
38+

0 commit comments

Comments
 (0)