Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a2c5fa4

Browse files
committed
added comments in attachment.py
1 parent 6a3564e commit a2c5fa4

File tree

3 files changed

+21
-13
lines changed

3 files changed

+21
-13
lines changed

‎Attachment_Downloader/attachment.py‎

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,39 @@
11
import ezgmail
22

33
def attachmentdownload(resulthreads):
4+
# Two Objects used in code are GmailThread and GmailMessage
5+
# 1. GmailThread - Represents conversation threads
6+
# 2. GmailMessage - Represents individual emails within Threads
7+
countofresults = len(resulthreads)
48
try:
5-
for i in range(len(resulthreads)):
6-
if len(resulthreads[i].messages) > 1:
9+
for i in range(countofresults):
10+
if len(resulthreads[i].messages) > 1:# checks whether the count of messages in threads is greater than 1
711
for j in range(len(resulthreads[i].messages)):
8-
resulthreads[i].messages[j].downloadAllAttachments()
12+
resulthreads[i].messages[
13+
j].downloadAllAttachments() # downloads attachment(s) for individual messages
914
else:
10-
resulthreads[i].messages[0].downloadAllAttachments()
15+
resulthreads[i].messages[0].downloadAllAttachments() # downloads attachment(s) for single message
16+
print("Download compelete. Please check your root directory.")
1117
except:
1218
raise Exception("Error occured while downloading attachment(s).")
13-
finally:
14-
print("Download compelete. Please check your root directory.")
19+
1520

1621
if __name__ == '__main__':
1722
query = input("Enter search query: ")
18-
newquery = query + " + has:attachment"
19-
resulthreads = ezgmail.search(newquery)
23+
newquery = query + " + has:attachment"# appending to make sure the result threads always has an attachment
24+
resulthreads = ezgmail.search(newquery)# search functions accepts all the operators described at https://support.google.com/mail/answer/7190?hl=en
2025

2126
if len(resulthreads) == 0:
22-
print("Results have no attachments")
27+
print("Result has no attachments")# Executed if results don't have attachment
2328
else:
24-
print("Results: ")
29+
print("Result(s): ")
2530
for threads in resulthreads:
26-
print(f"Email Subject: {threads.messages[0].subject}")
31+
print(f"Email Subject: {threads.messages[0].subject}")# prints the subject line of email thread in results
2732
try:
28-
ask = input("Do you want to download attachment(s) in results (Yes/No)? ")
33+
ask = input(
34+
"Do you want to download attachment(s) in result(s) (Yes/No)? ") # Allows user to decide whether they want to download attachment(s) or not
2935
if ask == "Yes":
30-
attachmentdownload(resulthreads)
36+
attachmentdownload(resulthreads)# calls the function that downloads attachment(s)
3137
else:
3238
print("Program exited")
3339
except:
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"installed":{"client_id":"1004827760520-vhe76mj8bnhl2djbi911hul9ebiuar5p.apps.googleusercontent.com","project_id":"attachment-downl-1615836904083","auth_uri":"https://accounts.google.com/o/oauth2/auth","token_uri":"https://oauth2.googleapis.com/token","auth_provider_x509_cert_url":"https://www.googleapis.com/oauth2/v1/certs","client_secret":"jiOeNPFSLKb6TeAGge-Fta-5","redirect_uris":["urn:ietf:wg:oauth:2.0:oob","http://localhost"]}}

‎Attachment_Downloader/token.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{"access_token": "ya29.a0AfH6SMD8DyPYCFTJf7BhOwGEoo59dmruTK1_VEjH23ESyxyONhGYnqEZCRRKId6wMe93a-jRwAzryCcYoH8sM4HOZuf0Em3mudNCS3zG_MzjGNDQS_axcF5J68XqS2GNVz8w8NyLa-qr33VvMKL1yReek0s-vw", "client_id": "1004827760520-vhe76mj8bnhl2djbi911hul9ebiuar5p.apps.googleusercontent.com", "client_secret": "jiOeNPFSLKb6TeAGge-Fta-5", "refresh_token": "1//0grs3VlWC1FgpCgYIARAAGBASNwF-L9Ir6d_ihrdvKysfTi86Eqv2w18XTWSxi8x8GHHBoeZjm_viWL3RT7qr45a4KIhYoLMbvd4", "token_expiry": "2021年03月16日T11:52:35Z", "token_uri": "https://oauth2.googleapis.com/token", "user_agent": null, "revoke_uri": "https://oauth2.googleapis.com/revoke", "id_token": null, "id_token_jwt": null, "token_response": {"access_token": "ya29.a0AfH6SMD8DyPYCFTJf7BhOwGEoo59dmruTK1_VEjH23ESyxyONhGYnqEZCRRKId6wMe93a-jRwAzryCcYoH8sM4HOZuf0Em3mudNCS3zG_MzjGNDQS_axcF5J68XqS2GNVz8w8NyLa-qr33VvMKL1yReek0s-vw", "expires_in": 3599, "scope": "https://mail.google.com/", "token_type": "Bearer"}, "scopes": ["https://mail.google.com/"], "token_info_uri": "https://oauth2.googleapis.com/tokeninfo", "invalid": false, "_class": "OAuth2Credentials", "_module": "oauth2client.client"}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /