mark as seen
This commit is contained in:
parent
9ec0e95544
commit
1ae30cdece
|
@ -14,7 +14,7 @@
|
|||
|
||||
## Todo
|
||||
|
||||
* Move processed mail to subfolder
|
||||
* Parse PDF
|
||||
* Lodur Connect (Create Einsatzrapport)
|
||||
* IMAP idle
|
||||
* Error Handling
|
||||
|
|
10
main.py
10
main.py
|
@ -16,13 +16,14 @@ import aioeasywebdav
|
|||
from dotenv import load_dotenv, find_dotenv
|
||||
import paho.mqtt.client as mqtt
|
||||
|
||||
_EMAIL_SUBJECTS = '(OR SUBJECT "Einsatzausdruck_FW" SUBJECT "Einsatzprotokoll")'
|
||||
_EMAIL_SUBJECTS = '(OR SUBJECT "Einsatzausdruck_FW" SUBJECT "Einsatzprotokoll" UNSEEN)'
|
||||
|
||||
load_dotenv(find_dotenv())
|
||||
imap_server = os.getenv("IMAP_SERVER")
|
||||
imap_username = os.getenv("IMAP_USERNAME")
|
||||
imap_password = os.getenv("IMAP_PASSWORD")
|
||||
imap_mailbox = os.getenv("IMAP_MAILBOX", "INBOX")
|
||||
imap_mailbox_archive = os.getenv("IMAP_MAILBOX_ARCHIVE", "Archive")
|
||||
webdav_url = os.getenv("WEBDAV_URL")
|
||||
webdav_username = os.getenv("WEBDAV_USERNAME")
|
||||
webdav_password = os.getenv("WEBDAV_PASSWORD")
|
||||
|
@ -43,7 +44,7 @@ def get_attachments(mqtt_client):
|
|||
logger.info('Connecting to IMAP server ' + imap_server)
|
||||
imap = imaplib.IMAP4_SSL(imap_server)
|
||||
imap.login(imap_username, imap_password)
|
||||
imap.select(imap_mailbox, readonly=True)
|
||||
imap.select(imap_mailbox, readonly=False)
|
||||
|
||||
# search for matching messages
|
||||
logger.info('Searching for messages matching the subject')
|
||||
|
@ -55,6 +56,8 @@ def get_attachments(mqtt_client):
|
|||
print('Error searching for matching messages')
|
||||
raise
|
||||
|
||||
logger.info('Found ' + str(len(msg_ids[0].split())) + ' matching messages')
|
||||
|
||||
for msg_id in msg_ids[0].split():
|
||||
subject = str()
|
||||
f_id = str()
|
||||
|
@ -74,6 +77,9 @@ def get_attachments(mqtt_client):
|
|||
|
||||
mqtt_client.publish("pylokid/einsatz/" + f_id, subject)
|
||||
|
||||
# Mark as seen
|
||||
imap.store(msg_id, '+FLAGS', '(\\Seen)')
|
||||
|
||||
# extract attachment from body
|
||||
mail = email.message_from_string(str(msg_data[0][1],'utf-8'))
|
||||
|
||||
|
|
Loading…
Reference in New Issue