Movatterモバイル変換


[0]ホーム

URL:


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

Commit4b1caf4

Browse files
committed
edit reading emails tutorial
1 parent7cb0c97 commit4b1caf4

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

‎python-standard-library/reading-email-messages/reading_emails.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
# total number of emails
2424
messages=int(messages[0])
2525

26-
foriinrange(messages-4,messages-N-4,-1):
26+
foriinrange(messages,messages-N,-1):
2727
# fetch the email message by ID
2828
res,msg=imap.fetch(str(i),"(RFC822)")
2929
forresponseinmsg:
@@ -35,10 +35,12 @@
3535
ifisinstance(subject,bytes):
3636
# if it's a bytes, decode to str
3737
subject=subject.decode()
38-
# email sender
39-
from_=msg.get("From")
38+
# decode email sender
39+
From,encoding=decode_header(msg.get("From"))[0]
40+
ifisinstance(From,bytes):
41+
From=From.decode(encoding)
4042
print("Subject:",subject)
41-
print("From:",from_)
43+
print("From:",From)
4244
# if the email message is multipart
4345
ifmsg.is_multipart():
4446
# iterate over email parts
@@ -83,9 +85,7 @@
8385
open(filepath,"w").write(body)
8486
# open in the default browser
8587
webbrowser.open(filepath)
86-
8788
print("="*100)
88-
8989
# close the connection and logout
9090
imap.close()
9191
imap.logout()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp