Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
daily-scripts
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Recolic
daily-scripts
Commits
9b166969
There was an error fetching the commit references. Please try again later.
Commit
9b166969
authored
1 month ago
by
Recolic
Browse files
Options
Downloads
Patches
Plain Diff
.
parent
67e7d9e1
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
archived/py/listemail.py
+41
-0
41 additions, 0 deletions
archived/py/listemail.py
with
41 additions
and
0 deletions
archived/py/listemail.py
0 → 100644
+
41
−
0
View file @
9b166969
# usage: python archived/py/listemail.py (genpasswd btest@recolic.net)
import
imaplib
import
email
from
email.header
import
decode_header
import
sys
IMAP_SERVER
=
"
imap.recolic.net
"
USERNAME
=
"
btest@recolic.net
"
PASSWORD
=
sys
.
argv
[
1
]
# Connect and upgrade to TLS
mail
=
imaplib
.
IMAP4
(
IMAP_SERVER
,
143
)
mail
.
starttls
()
mail
.
login
(
USERNAME
,
PASSWORD
)
# Select inbox
mail
.
select
(
"
INBOX
"
)
# Search all emails
status
,
messages
=
mail
.
search
(
None
,
"
ALL
"
)
if
status
!=
"
OK
"
:
print
(
"
Failed to fetch emails
"
)
exit
()
# Get list of email IDs
email_ids
=
messages
[
0
].
split
()
# Fetch and print subject lines
for
eid
in
email_ids
:
status
,
msg_data
=
mail
.
fetch
(
eid
,
"
(RFC822.HEADER)
"
)
if
status
!=
"
OK
"
:
continue
msg
=
email
.
message_from_bytes
(
msg_data
[
0
][
1
])
subject
,
encoding
=
decode_header
(
msg
[
"
Subject
"
])[
0
]
if
isinstance
(
subject
,
bytes
):
subject
=
subject
.
decode
(
encoding
or
"
utf-8
"
,
errors
=
"
ignore
"
)
print
(
subject
)
mail
.
logout
()
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment