Пример #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()
Пример #2
0
 def run(self):
     self.__mail_listener = MailListener(
         mailhost=self.registration_host,
         username=self.registration_username,
         password=self.registration_password,
         listener=self.__dispatch,
     )
     self.__mail_parser = MailParser(self.registration_username)
     self.__mail_listener.start()
Пример #3
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()
Пример #4
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()
Пример #5
0
class AccountRegistrationListener:
    def __init__(self, username=None, host=None, password=None):

        self.registration_username = username
        self.registration_host = host
        self.registration_password = password

        self.dispatcher_map = {}

        self.__mail_listener = None
        self.__mail_parser = None

    def run(self):
        self.__mail_listener = MailListener(
            mailhost=self.registration_host,
            username=self.registration_username,
            password=self.registration_password,
            listener=self.__dispatch,
        )
        self.__mail_parser = MailParser(self.registration_username)
        self.__mail_listener.start()

    def close(self):
        if self.__mail_listener:
            self.__mail_listener.close()

    def __dispatch(self, txt):
        email = self.__mail_parser.parse_raw_mail(txt)
        message = Message(self.__mail_parser.find_metadata(email))

        for key, dispatcher in self.dispatcher_map.items():
            string = message.get(key, "")
            dispatcher.search(string, message)

    def add_rule(self, pattern, callable, match_on=ALL_TEXT):
        """Add a rule based upon the contents of a message emailed by a third-party indicating a signup/follow of us.
        This is done with a regular expression pattern and a function which is called if matched."""
        dispatcher = self.dispatcher_map.setdefault(match_on, REDispatcher(None))
        dispatcher.register_pattern(pattern, callable)
Пример #6
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)
Пример #7
0
class AccountRegistrationListener:
    
    def __init__(self, username=None, host=None, password=None):
        
        self.registration_username=username
        self.registration_host=host
        self.registration_password=password
        
    
        self.dispatcher_map={}
    
        self.__mail_listener = None
        self.__mail_parser = None
    
    def run(self):
        self.__mail_listener = MailListener(mailhost=self.registration_host, username=self.registration_username, password=self.registration_password, listener=self.__dispatch)
        self.__mail_parser = MailParser(self.registration_username)
        self.__mail_listener.start()
        
    def close(self):
        if self.__mail_listener:
            self.__mail_listener.close()
            
    def __dispatch(self, txt):
        email = self.__mail_parser.parse_raw_mail(txt)
        message = Message(self.__mail_parser.find_metadata(email))
        
        for key, dispatcher in self.dispatcher_map.items():
            string = message.get(key, "")
            dispatcher.search(string, message)
    
    def add_rule(self, pattern, callable, match_on=ALL_TEXT):
        """Add a rule based upon the contents of a message emailed by a third-party indicating a signup/follow of us.
        This is done with a regular expression pattern and a function which is called if matched."""
        dispatcher = self.dispatcher_map.setdefault(match_on, REDispatcher(None))
        dispatcher.register_pattern(pattern, callable)
Пример #8
0
 def run(self):
     self.__mail_listener = MailListener(mailhost=self.registration_host, username=self.registration_username, password=self.registration_password, listener=self.__dispatch)
     self.__mail_parser = MailParser(self.registration_username)
     self.__mail_listener.start()
Пример #9
0
 def xtestFetch(self):
     server = MailListener(username='******', password='******')
     server.run()