Ejemplo n.º 1
0
 def run(self):
     parser = MailParser(email_address=['*****@*****.**', '*****@*****.**'], fullname='Zander The Wonderhorse')
     sender = MailSender(username='******', password='******')
     receiver = MailListener(username='******', password='******')
     
     
     for txt in receiver.run():
         message = parser.parse_raw_mail(txt)
         metadata = parser.find_metadata(message)
         metadata['reminder_message'] = "It's time to get up"
         reply = parser.construct_email(metadata, 'reminder_message')
         
         sender.send(reply)
     sender.disconnect()
Ejemplo n.º 2
0
class GmailPlugin(IPlugin):
    def __init__(self, parser=None, db=None, properties={}):
        self.is_preceeded_by = ['database', 'passwords']
        self.is_followed_by = ['email_database']
        self.parser = parser
        self.database = db
        self.properties = properties
        self.mail_parser = None
        self.mail_sender = None
        self.mail_receiver = None
        self.gmail_dao = None
        
    def install(self, ctx):
        gmail_user = self.properties['gmail_user'] 
        gmail_password = self.properties['gmail_password']

        if not self.mail_parser:
            self.mail_parser = MailParser(email_address=gmail_user, fullname=self.properties['agent_name'])
        if not self.mail_sender:
            self.mail_sender = MailSender(username=gmail_user, password=gmail_password)
        if not self.mail_receiver:
            self.mail_receiver = MailListener(username=gmail_user, password=gmail_password, listener=self.parse_mail)
        
        if not self.gmail_dao:
            self.gmail_dao = GmailDAO(self.database)
        
        ctx.er.transport_dao.add('email', self.gmail_dao)
        
        
    def start_up(self, ctx):
        ctx.er.parser_actions.add(EmailSender(sender=self.mail_sender, parser=self.mail_parser))
        ctx.er.template_files.add(self, 'ui/templates/email.txt')
        
    def run(self):
        self.mail_receiver.start()
        
    def parse_mail(self, txt):
        message = self.mail_parser.parse_raw_mail(txt)
        metadata = self.mail_parser.find_metadata(message)
        self.parser.process_dictionary(metadata)
    
    def stop(self):
        self.mail_receiver.close()
        self.mail_sender.disconnect()
Ejemplo n.º 3
0
    def install(self, ctx):
        gmail_user = self.properties['gmail_user'] 
        gmail_password = self.properties['gmail_password']

        if not self.mail_parser:
            self.mail_parser = MailParser(email_address=gmail_user, fullname=self.properties['agent_name'])
        if not self.mail_sender:
            self.mail_sender = MailSender(username=gmail_user, password=gmail_password)
        if not self.mail_receiver:
            self.mail_receiver = MailListener(username=gmail_user, password=gmail_password, listener=self.parse_mail)
        
        if not self.gmail_dao:
            self.gmail_dao = GmailDAO(self.database)
        
        ctx.er.transport_dao.add('email', self.gmail_dao)
Ejemplo n.º 4
0
    def run(self):
        parser = MailParser(email_address=[
            '*****@*****.**', '*****@*****.**'
        ],
                            fullname='Zander The Wonderhorse')
        sender = MailSender(username='******',
                            password='******')
        receiver = MailListener(username='******',
                                password='******')

        for txt in receiver.run():
            message = parser.parse_raw_mail(txt)
            metadata = parser.find_metadata(message)
            metadata['reminder_message'] = "It's time to get up"
            reply = parser.construct_email(metadata, 'reminder_message')

            sender.send(reply)
        sender.disconnect()