# Path: Peach/publisher.py
# class Publisher(object):
#     """
#     The Publisher object(s) implement a way to send and/or receive data by
#     some means. There are two "types" of publishers, stream based and call
#     based. This base class supports both types.
#     To support stream based publishing implement everything but "call". To
#     support call based publishing implement start, stop, and call. A
#     publisher can support both stream and call based publishing.
#     """
# 
#     def __init__(self):
#         #: Indicates which method should be called.
#         self.withNode = False
#         self.publisherBuffer = None
# 
#     def initialize(self):
#         """
#         Called at start of test run. Called once per <Test> section.
#         """
#         pass
# 
#     def finalize(self):
#         """
#         Called at end of test run. Called once per <Test> section.
#         """
#         pass
# 
#     def start(self):
#         """
#         Change state such that send/receive will work. For TCP this could be
#         connecting to a remote host.
#         """
#         pass
# 
#     def stop(self):
#         """
#         Change state such that send/receive will not work. For TCP this could
#         be closing a connection, for a file it might be closing the file
#         handle.
#         """
#         pass
# 
#     def send(self, data):
#         """
#         Publish some data.
# 
#         :param data: data to publish
#         :type data: str
#         """
#         raise PeachException("Action 'send' not supported by publisher.")
# 
#     def sendWithNode(self, data, dataNode):
#         """
#         Publish some data.
# 
#         :param data: data to publish
#         :type data: str
#         :param dataNode: root of data model that produced data
#         :type dataNode: DataElement
#         """
#         raise PeachException("Action 'sendWithNode' not supported by "
#                              "publisher.")
# 
#     def receive(self, size=None):
#         """
#         Receive some data.
# 
#         :param size: number of bytes to return
#         :type size: int
#         :returns: data received
#         :rtype: str
#         """
#         raise PeachException("Action 'receive' not supported by publisher.")
# 
#     def call(self, method, args):
#         """
#         Call a method using arguments.
# 
#         :param method: method to call
#         :type method: str
#         :param args: list of strings as arguments
#         :type args: list
#         :returns: data (if any)
#         :rtype: str
#         """
#         raise PeachException("Action 'call' not supported by publisher.")
# 
#     def callWithNode(self, method, args, argNodes):
#         """
#         Call a method using arguments.
# 
#         :param method: method to call
#         :type method: str
#         :param args: list of strings as arguments
#         :type args: list
#         :param argNodes: list of DataElements
#         :type argNodes: list
#         :returns: data (if any)
#         :rtype: str
#         """
#         raise PeachException("Action 'callWithNode' not supported by publisher.")
# 
#     def property(self, property, value=None):
#         """
#         Get or set property.
# 
#         :param property: name of method to invoke
#         :type property: str
#         :param value: value to set. If None, return property instead
#         :type value: object
#         """
#         raise PeachException("Action 'property' not supported by publisher.")
# 
#     def propertyWithNode(self, property, value, valueNode):
#         """
#         Get or set property.
# 
#         :param property: name of method to invoke
#         :type property: str
#         :param value: value to set. If None, return property instead
#         :type value: object
#         :param valueNode: data model root node that produced value
#         :type valueNode: DataElement
#         """
#         raise PeachException("Action 'propertyWithNode' not supported by publisher.")
# 
#     def connect(self):
#         """
#         Called to connect or open a connection / file.
#         """
#         raise PeachException("Action 'connect' not supported by publisher.")
# 
#     def accept(self):
#         """
#         Accept incoming connection. Blocks until incoming connection occurs.
#         """
#         raise PeachException("Action 'accept' not supported by publisher.")
# 
#     def close(self):
#         """
#         Close current stream/connection.
#         """
#         raise PeachException("Action 'close' not supported by publisher.")
# 
#     def debug(self, fmt):
#         print("{}: {}".format(self.__class__.__name__, fmt))
# 
# Path: Peach/Engine/common.py
# class PeachException(HardException):
#     """
#     Peach exceptions are specialized hard exceptions.
#     The message contained in a PeachException is presentable to the user w/o any stack trace, etc.
#     Examples would be:
#         "Error: The DataModel element requires a name attribute."
#     """
#     def __init__(self, msg, module="Unknown"):
#         Exception.__init__(self, msg)
#         self.module = module
#         self.msg = msg


import time
import sys
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import Encoders
from email.Utils import COMMASPACE, formatdate
from Peach.publisher import Publisher
from Peach.Engine.common import PeachException
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.



class SMTPPublisher(Publisher):
    def __init__(self, host="localhost",
                 port=smtplib.SMTP_PORT,
                 debugLevel=0,
                 mailFrom="localhost@localhost",
                 mailTo="localhost@localhost",
                 username="",
                 password=""):
        Publisher.__init__(self)
        self.host = host
        try:
            self.port = int(port)
        except:

# Path: Peach/publisher.py
# class Publisher(object):
#     """
#     The Publisher object(s) implement a way to send and/or receive data by
#     some means. There are two "types" of publishers, stream based and call
#     based. This base class supports both types.
#     To support stream based publishing implement everything but "call". To
#     support call based publishing implement start, stop, and call. A
#     publisher can support both stream and call based publishing.
#     """
# 
#     def __init__(self):
#         #: Indicates which method should be called.
#         self.withNode = False
#         self.publisherBuffer = None
# 
#     def initialize(self):
#         """
#         Called at start of test run. Called once per <Test> section.
#         """
#         pass
# 
#     def finalize(self):
#         """
#         Called at end of test run. Called once per <Test> section.
#         """
#         pass
# 
#     def start(self):
#         """
#         Change state such that send/receive will work. For TCP this could be
#         connecting to a remote host.
#         """
#         pass
# 
#     def stop(self):
#         """
#         Change state such that send/receive will not work. For TCP this could
#         be closing a connection, for a file it might be closing the file
#         handle.
#         """
#         pass
# 
#     def send(self, data):
#         """
#         Publish some data.
# 
#         :param data: data to publish
#         :type data: str
#         """
#         raise PeachException("Action 'send' not supported by publisher.")
# 
#     def sendWithNode(self, data, dataNode):
#         """
#         Publish some data.
# 
#         :param data: data to publish
#         :type data: str
#         :param dataNode: root of data model that produced data
#         :type dataNode: DataElement
#         """
#         raise PeachException("Action 'sendWithNode' not supported by "
#                              "publisher.")
# 
#     def receive(self, size=None):
#         """
#         Receive some data.
# 
#         :param size: number of bytes to return
#         :type size: int
#         :returns: data received
#         :rtype: str
#         """
#         raise PeachException("Action 'receive' not supported by publisher.")
# 
#     def call(self, method, args):
#         """
#         Call a method using arguments.
# 
#         :param method: method to call
#         :type method: str
#         :param args: list of strings as arguments
#         :type args: list
#         :returns: data (if any)
#         :rtype: str
#         """
#         raise PeachException("Action 'call' not supported by publisher.")
# 
#     def callWithNode(self, method, args, argNodes):
#         """
#         Call a method using arguments.
# 
#         :param method: method to call
#         :type method: str
#         :param args: list of strings as arguments
#         :type args: list
#         :param argNodes: list of DataElements
#         :type argNodes: list
#         :returns: data (if any)
#         :rtype: str
#         """
#         raise PeachException("Action 'callWithNode' not supported by publisher.")
# 
#     def property(self, property, value=None):
#         """
#         Get or set property.
# 
#         :param property: name of method to invoke
#         :type property: str
#         :param value: value to set. If None, return property instead
#         :type value: object
#         """
#         raise PeachException("Action 'property' not supported by publisher.")
# 
#     def propertyWithNode(self, property, value, valueNode):
#         """
#         Get or set property.
# 
#         :param property: name of method to invoke
#         :type property: str
#         :param value: value to set. If None, return property instead
#         :type value: object
#         :param valueNode: data model root node that produced value
#         :type valueNode: DataElement
#         """
#         raise PeachException("Action 'propertyWithNode' not supported by publisher.")
# 
#     def connect(self):
#         """
#         Called to connect or open a connection / file.
#         """
#         raise PeachException("Action 'connect' not supported by publisher.")
# 
#     def accept(self):
#         """
#         Accept incoming connection. Blocks until incoming connection occurs.
#         """
#         raise PeachException("Action 'accept' not supported by publisher.")
# 
#     def close(self):
#         """
#         Close current stream/connection.
#         """
#         raise PeachException("Action 'close' not supported by publisher.")
# 
#     def debug(self, fmt):
#         print("{}: {}".format(self.__class__.__name__, fmt))
# 
# Path: Peach/Engine/common.py
# class PeachException(HardException):
#     """
#     Peach exceptions are specialized hard exceptions.
#     The message contained in a PeachException is presentable to the user w/o any stack trace, etc.
#     Examples would be:
#         "Error: The DataModel element requires a name attribute."
#     """
#     def __init__(self, msg, module="Unknown"):
#         Exception.__init__(self, msg)
#         self.module = module
#         self.msg = msg


# Path: Peach/Publishers/smtp.py
import time
import sys
import smtplib
from email.mime.multipart import MIMEMultipart
from email.mime.base import MIMEBase
from email.mime.text import MIMEText
from email import Encoders
from email.Utils import COMMASPACE, formatdate
from Peach.publisher import Publisher
from Peach.Engine.common import PeachException

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.



class SMTPPublisher(Publisher):
    def __init__(self, host="localhost",
                 port=smtplib.SMTP_PORT,
                 debugLevel=0,
                 mailFrom="localhost@localhost",
                 mailTo="localhost@localhost",
                 username="",
                 password=""):
        Publisher.__init__(self)
        self.host = host
        try:
            self.port = int(port)
        except:

            raise PeachException("The SMTP publisher parameter for port is not a valid number.")