# Path: notify.py
# class Notify():
#     """Send an Email to notify user"""
#     def send(self, msg):
#         self.logger = logging.getLogger()
#         self.msg = msg
#         threading.Thread(target=self._send).start()
# 
#     def _send(self):
#         try:
#             config = configparser.ConfigParser()
#             config.read('notify.ini')
#             # load user defined email settings
#             user = config.get('authentication', 'user', fallback=None)
#             password = config.get('authentication', 'password', fallback=None)
#             server = config.get('authentication', 'server', fallback=None)
#             port = config.getint('authentication', 'port', fallback=465)
#             to_addr = config.get('header', 'to_address', fallback=None)
#             subject = config.get('header', 'subject', fallback='Smoopi notification')
# 
#         except Exception as err:
#             self.logger.error('Notify: notify.ini file errors: {}'.format(err))
#             return False
# 
#         if user is None:
#             self.logger.error('Notify: no user specified')
#             return False
#         if password is None:
#             self.logger.error('Notify: no password specified')
#             return False
#         if server is None:
#             self.logger.error('Notify: no server specified')
#             return False
#         if to_addr is None:
#             self.logger.error('Notify: no to address specified')
#             return False
# 
#         body = '{}\n'.format(self.msg)
# 
#         email_text = """\
# From: %s
# To: %s
# Subject: %s
# 
# %s
# """ % (user, to_addr, subject, body)
# 
#         try:
#             server = smtplib.SMTP_SSL(server, port)
#             server.ehlo()
#             server.login(user, password)
#             server.sendmail(user, to_addr, email_text)
#             server.close()
#             return True
# 
#         except Exception as ex:
#             self.logger.error('Notify: Failed to send email: {}'.format(ex))
#             return False


import threading
import asyncio
import aiofiles
import logging
import functools
import sys
import re
import os
import traceback
import serial.tools.list_ports
import subprocess
import socket
import time
import libs.serial_asyncio.serial_asyncio
    import datetime
from notify import Notify
                        while self.pause_stream:
                            await asyncio.sleep(1)
                            if self.progress:
                                self.progress(linecnt)
                            if self.abort_stream:
                                break

                        # recreate okcnt
                        if self.ping_pong:
                            self.okcnt = asyncio.Event()

                    # read next line
                    line = await f.readline()

                    if not line:
                        # EOF
                        break

                    if self.abort_stream:
                        break

                    line = line.strip()
                    if len(line) == 0 or line.startswith(';'):
                        continue

                    if line.startswith('(MSG'):
                        self.app.main_window.async_display(line)
                        continue

                    if line.startswith('(NOTIFY'):

# Path: notify.py
# class Notify():
#     """Send an Email to notify user"""
#     def send(self, msg):
#         self.logger = logging.getLogger()
#         self.msg = msg
#         threading.Thread(target=self._send).start()
# 
#     def _send(self):
#         try:
#             config = configparser.ConfigParser()
#             config.read('notify.ini')
#             # load user defined email settings
#             user = config.get('authentication', 'user', fallback=None)
#             password = config.get('authentication', 'password', fallback=None)
#             server = config.get('authentication', 'server', fallback=None)
#             port = config.getint('authentication', 'port', fallback=465)
#             to_addr = config.get('header', 'to_address', fallback=None)
#             subject = config.get('header', 'subject', fallback='Smoopi notification')
# 
#         except Exception as err:
#             self.logger.error('Notify: notify.ini file errors: {}'.format(err))
#             return False
# 
#         if user is None:
#             self.logger.error('Notify: no user specified')
#             return False
#         if password is None:
#             self.logger.error('Notify: no password specified')
#             return False
#         if server is None:
#             self.logger.error('Notify: no server specified')
#             return False
#         if to_addr is None:
#             self.logger.error('Notify: no to address specified')
#             return False
# 
#         body = '{}\n'.format(self.msg)
# 
#         email_text = """\
# From: %s
# To: %s
# Subject: %s
# 
# %s
# """ % (user, to_addr, subject, body)
# 
#         try:
#             server = smtplib.SMTP_SSL(server, port)
#             server.ehlo()
#             server.login(user, password)
#             server.sendmail(user, to_addr, email_text)
#             server.close()
#             return True
# 
#         except Exception as ex:
#             self.logger.error('Notify: Failed to send email: {}'.format(ex))
#             return False


# Path: comms.py
import threading
import asyncio
import aiofiles
import logging
import functools
import sys
import re
import os
import traceback
import serial.tools.list_ports
import subprocess
import socket
import time
import libs.serial_asyncio.serial_asyncio
    import datetime
from notify import Notify

                        while self.pause_stream:
                            await asyncio.sleep(1)
                            if self.progress:
                                self.progress(linecnt)
                            if self.abort_stream:
                                break

                        # recreate okcnt
                        if self.ping_pong:
                            self.okcnt = asyncio.Event()

                    # read next line
                    line = await f.readline()

                    if not line:
                        # EOF
                        break

                    if self.abort_stream:
                        break

                    line = line.strip()
                    if len(line) == 0 or line.startswith(';'):
                        continue

                    if line.startswith('(MSG'):
                        self.app.main_window.async_display(line)
                        continue

                    if line.startswith('(NOTIFY'):

                        notify = Notify()