Exemplo n.º 1
0
    def privmsg(self, user, channel, msg):
        """This will get called when the bot receives a message."""
        user = user.split('!', 1)[0]

        username = self.factory.transport.uniblab.username_from_irc(user.lower())
        message = uniblab_message.uniblab_message(user, channel, msg, None, self.transport_type, username)
        self.factory.transport.uniblab.message(message,self.factory.transport )
Exemplo n.º 2
0
 def onMessage(self, msg):
     if msg["type"] == 'chat' and hasattr(msg, "body") and msg.body:
         self.typing_notification(msg['from'])
         user = msg['from'].split('/')[0]
         username = self.transport.uniblab.username_from_gtalk(user.strip().lower())
         message = uniblab_message.uniblab_message(msg['from'], self.transport.xmpp_user, str(msg.body), None, self.transport_type, username)
         self.transport.uniblab.message(message,self.transport )
Exemplo n.º 3
0
 def availableReceived(self, entity, show=None, statuses=None, priority=0):
     user = entity.full().split('/')[0]
     username = self.transport.uniblab.username_from_gtalk(user.strip().lower())
     new_status = None
     if statuses:
         new_status = statuses[None]
     message = uniblab_message.uniblab_message(entity.full(), self.transport.xmpp_user, new_status, None, self.transport_type, username)
     self.transport.uniblab.status(message,self.transport )
     print "Available from %s (%s, %s)" % (entity.full(), show, statuses)
Exemplo n.º 4
0
 def read_new_messages(self):
     try:
         s = IMAP4_SSL(self.mail_host, self.mail_port)
         s.login(self.mail_user, self.mail_pass)
         s.select()
         typ, data = s.search(None, '(UNDELETED)')
         messages = list()
         for msgnum in data[0].split():
             env,parts = s.fetch(msgnum, 'RFC822')
             for part in parts:
                 if(len(part) > 1):
                     msg = email.message_from_string(part[1])
                     datestr = msg.get('Date')
                     if datestr != None:
                         senddate = datetime.datetime.fromtimestamp(time.mktime(email.utils.parsedate(datestr)))
                         now = datetime.date.today()
                         if senddate.date() == now:
                             for m in msg.walk():
                                 if m.get_content_type() == 'text/plain':
                                     body = m.get_payload()
                                     break
                                 elif m.get_content_type() == 'text/html':
                                     body = m.get_payload()
                                     break
                             from_addr = msg['from']
                             email_match = email_pattern.search(from_addr)
                             if email_match:
                                 from_addr = email_match.group(2)
                                 username = self.uniblab.username_from_email(from_addr)
                                 print 'Processing email from', msg['from'], 'which is user', username
                             message = uniblab_message.uniblab_message(from_addr,msg['to'], msg['subject'], body, self.transport_type, username)
                             self.uniblab.message(message,self)
                         else:
                             print "Found a message that wasn't sent today, but on", senddate.date()
                     s.store(msgnum, '+FLAGS', '\\Deleted')
         s.expunge()
         s.logout()
     except:
         print 'Encountered an error in the email loop'