Demo
- 📅 2021-04-18T11:51:03.000Z
- 👁️ 136 katselukertaa
- 🔓 Julkinen
from flask import Flask
from imapclient import IMAPClient
import ssl
app = Flask(__name__)
ssl_context = ssl.create_default_context()
ssl_context.check_hostname = False
ssl_context.verify_mode = ssl.CERT_NONE
@app.route('/')
def hello():
with IMAPClient(host="dovecot", ssl_context=ssl_context) as client:
client.login('admin', 'pass')
client.select_folder('INBOX')
# search criteria are passed in a straightforward way
# (nesting is supported)
messages = client.search(['NOT', 'DELETED'])
# fetch selectors are passed as a simple list of strings.
response = client.fetch(messages, ['FLAGS', 'RFC822.SIZE'])
# `response` is keyed by message id and contains parsed,
# converted response items.
return response
for message_id, data in response.items():
print('{id}: {size} bytes, flags={flags}'.format(
id=message_id,
size=data[b'RFC822.SIZE'],
flags=data[b'FLAGS']))
#return 'Accessing mails...'
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)