improved attachment handling

This commit is contained in:
Tobias Brunner 2017-12-26 14:23:34 +01:00
parent 8ec4c900e8
commit 7de5856829
2 changed files with 13 additions and 4 deletions

View File

@ -23,6 +23,7 @@
* Store parsed data in Lodur text fields for copy/paste
* Cleanup code into proper functions and classes
* Lodur "API" class
* Heartbeat
### Known instabilities

16
main.py
View File

@ -77,11 +77,10 @@ def store_attachments(imap, msg_ids):
subject = mail['subject']
logger.info('Getting attachment from: ' + subject)
for part in mail.walk():
if part.get_content_maintype() == 'multipart':
continue
if part.get('Content-Disposition') is None:
continue
file_name = part.get_filename()
if not file_name:
logger.debug('Most probably not an attachment as no filename found')
continue
logger.info('Extracting attachment: ' + file_name)
@ -220,6 +219,15 @@ def main():
logger.info(
'Einsatzrapport ' + f_id + ' already created in Lodur: ' + lodur_id
)
# Upload Alarmdepesche as it could contain more information than the first one
upload_alarmdepesche(
lodur_user,
lodur_password,
lodur_base_url,
lodur_id,
file_name,
os.path.join(tmp_dir, file_name),
)
else:
# this is real - publish Einsatz on MQTT
mqtt_client.publish('pylokid/' + f_type, f_id)