# Path: lib/baseClass.py
# class AbstractClass(object):
#     """
#     Generic parent class for all class
#     """
#     __metaclass__ = ABCMeta
# 
#     @classmethod
#     def get_config(cls):
#         return {}
# 
#     """
#     __init__ params'name must be the same with config
#     """
#     @classmethod
#     def get_instance(cls):
#         config = cls.get_config()
#         instance = cls(**config)
#         return instance
# 
#     @classmethod
#     @abstractmethod
#     def is_available(cls):
#         return true
# 
#     def __init__(self, **kwargs):
#         self._logger = lib.util.init_logger(__name__)


import sys, os, time, random
import yaml
import smtplib
import lib.appPath
from email import encoders
from email.header import Header
from email.utils import parseaddr, formataddr
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from lib.baseClass import AbstractClass
                    if 'smtpPort' in mail_config:
                        config['smtpPort'] = mail_config['smtpPort']
        return config

    @classmethod
    def is_available(cls):
        return (super(cls, cls).is_available() and
                lib.diagnose.check_python_import('smtplib'))

    def _formatAddr(cls,s): 
        name, addr = parseaddr(s) 
        return formataddr((
            Header(name, 'utf-8').encode(),
            addr.encode('utf-8') if isinstance(addr, unicode) else addr))

    def sendImageEmail(self,image):
        msg = MIMEMultipart()
        msg['Subject'] = Header(u'邮件', 'utf-8').encode()
        msg['From'] = self._formatAddr(u'小C(weedge)  <%s>' % self.fromEmail)
        msg['To'] = self._formatAddr(u'主人邮箱 <%s>' % self.toEmail)
        
        #邮件内容
        msg.attach(MIMEText('Hi,您好,监控文件见附件', 'plain', 'utf-8'))
        
        #图片附件
        mime = MIMEBase('image', 'jpg', filename='img.jpg')
        # 加上必要的头信息:
        mime.add_header('Content-Disposition', 'attachment', filename='img.jpg')
        mime.add_header('Content-ID', '<0>')
        mime.add_header('X-Attachment-Id', '0')

# Path: lib/baseClass.py
# class AbstractClass(object):
#     """
#     Generic parent class for all class
#     """
#     __metaclass__ = ABCMeta
# 
#     @classmethod
#     def get_config(cls):
#         return {}
# 
#     """
#     __init__ params'name must be the same with config
#     """
#     @classmethod
#     def get_instance(cls):
#         config = cls.get_config()
#         instance = cls(**config)
#         return instance
# 
#     @classmethod
#     @abstractmethod
#     def is_available(cls):
#         return true
# 
#     def __init__(self, **kwargs):
#         self._logger = lib.util.init_logger(__name__)


# Path: lib/mail.py
import sys, os, time, random
import yaml
import smtplib
import lib.appPath
from email import encoders
from email.header import Header
from email.utils import parseaddr, formataddr
from email.MIMEMultipart import MIMEMultipart
from email.MIMEText import MIMEText
from email.MIMEBase import MIMEBase
from lib.baseClass import AbstractClass

                    if 'smtpPort' in mail_config:
                        config['smtpPort'] = mail_config['smtpPort']
        return config

    @classmethod
    def is_available(cls):
        return (super(cls, cls).is_available() and
                lib.diagnose.check_python_import('smtplib'))

    def _formatAddr(cls,s): 
        name, addr = parseaddr(s) 
        return formataddr((
            Header(name, 'utf-8').encode(),
            addr.encode('utf-8') if isinstance(addr, unicode) else addr))

    def sendImageEmail(self,image):
        msg = MIMEMultipart()
        msg['Subject'] = Header(u'邮件', 'utf-8').encode()
        msg['From'] = self._formatAddr(u'小C(weedge)  <%s>' % self.fromEmail)
        msg['To'] = self._formatAddr(u'主人邮箱 <%s>' % self.toEmail)
        
        #邮件内容
        msg.attach(MIMEText('Hi,您好,监控文件见附件', 'plain', 'utf-8'))
        
        #图片附件
        mime = MIMEBase('image', 'jpg', filename='img.jpg')
        # 加上必要的头信息:
        mime.add_header('Content-Disposition', 'attachment', filename='img.jpg')
        mime.add_header('Content-ID', '<0>')
        mime.add_header('X-Attachment-Id', '0')

        mime.set_payload(image)