Example #1
0
	def getVCards(self):
		vcards = []
		fields = self.getFields()
		for card in self.getBodyAttr('values'):
			card_dict = {}
			for n in range(self.getBodyAttr('fields_num')):
				card_dict[fields[n]] = utils.win2str(card[n])
			vcards.append(card_dict)
		return vcards
Example #2
0
 def getVCards(self):
     vcards = []
     fields = self.getFields()
     for card in self.getBodyAttr('values'):
         card_dict = {}
         for n in range(self.getBodyAttr('fields_num')):
             card_dict[fields[n]] = utils.win2str(card[n])
         vcards.append(card_dict)
     return vcards
Example #3
0
 def __init__(self, data):
     UserDict.UserDict.__init__(self)
     self.msg = email.message_from_string(data)
     self.boundary = self.msg['Boundary']
     self.payload = self.msg.get_payload().split('--%s--' % self.boundary)
     self['from'] = self.msg['From']
     self['date'] = parsedate(self.msg['Date'])
     self['subject'] = self.msg['Subject']
     self['flags'] = eval('0x' + self.msg['X-MRIM-Flags'])
     self['version'] = self.msg['Version']
     self['message'] = utils.win2str(self.payload[0].strip())
     self['rtf-message'] = self.payload[1].strip()
Example #4
0
	def __init__(self, data):
		UserDict.UserDict.__init__(self)
		self.msg = email.message_from_string(data)
		self.boundary = self.msg['Boundary']
		self.payload = self.msg.get_payload().split('--%s--' % self.boundary)
		self['from'] = self.msg['From']
		self['date'] = parsedate(self.msg['Date'])
		self['subject'] = self.msg['Subject']
		self['flags'] = eval('0x'+self.msg['X-MRIM-Flags'])
		self['version'] = self.msg['Version']
		self['message'] = utils.win2str(self.payload[0].strip())
		self['rtf-message'] = self.payload[1].strip()
Example #5
0
 def getUsers(self):
     d = {}
     for u in self.packet.getBodyAttr('contacts'):
         contact = {
             'flags': u[0],
             'group': u[1],
             'nick': utils.win2str(u[3]),
             'server_flags': u[4],
             'status': u[5],
             'phones': u[6]
         }
         if (u[0] & CONTACT_FLAG_SMS):
             d[u[6]] = contact
         else:
             d[u[2]] = contact
     return d
Example #6
0
	def getUsers(self):
		d = {}
		for u in self.packet.getBodyAttr('contacts'):
			contact = {
					'flags':u[0],
					'group':u[1],
					'nick':utils.win2str(u[3]),
					'server_flags':u[4],
					'status':u[5],
					'phones':u[6]
			}
			if (u[0] & CONTACT_FLAG_SMS):
				d[u[6]] = contact
			else:
				d[u[2]] = contact
		return d
Example #7
0
 def getGroups(self):
     d = {}
     for g in self.packet.getBodyAttr('groups'):
         d[g[0]] = {'name': utils.win2str(g[1])}
     return d
Example #8
0
 def getBodyPayload(self):
     return utils.win2str(self.getBodyAttr('message'))
Example #9
0
	def _workup_packet(self, mmp_packet):

		ptype = mmp_packet.getType()
		msg_id = mmp_packet.getId()
		_ack = self._get_buffer_acks(msg_id)

		if ptype == MRIM_CS_HELLO_ACK:
			self.ping_period = mmp_packet.getBodyAttr('ping_period')
			self.log(logging.INFO, "Successfully connected")
			self.log(logging.DEBUG, "Server version is %s" % mmp_packet.getVersion())
			self.log(logging.DEBUG, "Server has set ping period to %d seconds" % self.ping_period)
			self._got_hello_ack()

		elif ptype == MRIM_CS_LOGIN_ACK:
			self.ping()
			self.state = 'session_established'
			self.log(logging.INFO, "Authorization successfull: logged in")
			for p in self.__outbuf:
				self._send_packet(p)
			self.mmp_handler_server_authorized()

		elif ptype == MRIM_CS_LOGIN_REJ:
			res = utils.win2str(mmp_packet.getBodyAttr('reason'))
			self.log(logging.INFO, "Authorization failure: %s" % res)
			self.mmp_handler_server_not_authorized(res)

		elif ptype == MRIM_CS_MESSAGE_ACK:
			mess = protocol.Message(payload=mmp_packet)
			if not mess.hasFlag(MESSAGE_FLAG_NORECV):
				msg_body_id = mess.getBodyAttr('msg_id')
				frm = mess.getBodyAttr('from')
				d = {
					'msg_id':msg_body_id,
					'from':frm
				}
				mess_reply = protocol.MMPPacket(typ=MRIM_CS_MESSAGE_RECV,dict=d)
				self._send_packet(mess_reply)
			self._parse_message(mess)

		elif ptype == MRIM_CS_MESSAGE_STATUS:
			status = mmp_packet.getBodyAttr('status')
			_ack['ackf'](status, **_ack['acka'])
			self.mmp_handler_got_message_status(status,msg_id)

		elif ptype == MRIM_CS_CONTACT_LIST2:
			self.contact_list = protocol.ContactList(mmp_packet)
			self._got_roster = True
			self.mmp_handler_got_contact_list2()

		elif ptype == MRIM_CS_MAILBOX_STATUS:
			n = mmp_packet.getBodyAttr('count')
			sender = utils.win2str(mmp_packet.getBodyAttr('sender'))
			subject = utils.win2str(mmp_packet.getBodyAttr('subject'))
			unix_time = mmp_packet.getBodyAttr('unix_time')
			email_key = mmp_packet.getBodyAttr('key')
			self._got_new_mail(n,sender,subject,unix_time,email_key)
		
		elif ptype == MRIM_CS_MAILBOX_STATUS_OLD:
			status = mmp_packet.getBodyAttr('status')
			self.mmp_handler_got_mailbox_status_old(status)

		elif ptype == MRIM_CS_USER_INFO:
			total = mmp_packet.getBodyAttr('total')
			unread = mmp_packet.getBodyAttr('unread')
			nickname = mmp_packet.getBodyAttr('nickname')
			self.myname = utils.win2str(nickname)
			self._got_mbox_status(total, unread)

		elif ptype == MRIM_CS_USER_STATUS:
			if self._got_roster:
				status = mmp_packet.getBodyAttr('status')
				e_mail = mmp_packet.getBodyAttr('user')
				try:
					self.contact_list.setUserStatus(e_mail, status)
				except KeyError:
					self.log(logging.ERROR,
						"Got status from unknown user. There is no %s in contact list: %s" 
							% (e_mail, self.contact_list.getEmails()))
					return
				self.mmp_handler_got_user_status(e_mail, status)

		elif ptype == MRIM_CS_LOGOUT:
			log_reason = "Server has forced logout with reason: "
			reason = mmp_packet.getBodyAttr('reason')
			if reason == LOGOUT_NO_RELOGIN_FLAG:
				log_reason += "dual login"
				self.log(logging.INFO, log_reason)
				self.mmp_handler_dual_login()
			else:
				log_reason += "unknown (%s)" % hex(reason)
				self.log(logging.INFO, log_reason)

		elif ptype == MRIM_CS_GET_MPOP_SESSION_ACK:
			if mmp_packet.getBodyAttr('status'):
				hash_key = mmp_packet.getBodyAttr('session')
				_ack['ackf'](self._mbox_url+hash_key, **_ack['acka'])

		elif ptype == MRIM_CS_CONNECTION_PARAMS:
			self.ping_period = mmp_packet.getBodyAttr('ping_period')

		elif ptype == MRIM_CS_OFFLINE_MESSAGE_ACK:
			uid = mmp_packet.getBodyAttr('uidl')
			d = {'uidl':uid}
			p = protocol.MMPPacket(typ=MRIM_CS_DELETE_OFFLINE_MESSAGE,dict=d)
			self._send_packet(p)
			offmsg = protocol.OfflineMessage(mmp_packet.getBodyAttr('message'))
			msg = offmsg.buildMessage()
			offtime = offmsg.getUTCTime()
			self._parse_message(msg, offtime)

		elif ptype == MRIM_CS_ANKETA_INFO:
			anketa = protocol.Anketa(mmp_packet.__str__())
			if _ack['add']:
				status = anketa.getStatus()
				if status == MRIM_ANKETA_INFO_STATUS_OK:
					card = anketa.getVCards()[0]
					e_mail = card['Username']+'@'+card['Domain']
					nickname = card['Nickname'].strip() or e_mail
					#mrim_status = int(card['mrim_status'])
					self.mmp_add_contact(e_mail,nick=nickname,status=0,
						ackf=_ack['ackf'],acka=_ack['acka'])
				else:
					if status == MRIM_ANKETA_INFO_STATUS_NOUSER:
						s = CONTACT_OPER_NO_SUCH_USER
					elif status == MRIM_ANKETA_INFO_STATUS_DBERR:
						s = CONTACT_OPER_ERROR
					else:
						s =  CONTACT_OPER_INTERR
					_ack['ackf'](s, **_ack['acka'])
			else:
				_ack['ackf'](anketa, **_ack['acka'])

		elif ptype == MRIM_CS_AUTHORIZE_ACK:
			user = mmp_packet.getBodyAttr('user')
			if self._got_roster:
				self.contact_list.setAuthFlag(user,0)
			self.mmp_handler_got_subscribed(user)

		elif ptype == MRIM_CS_ADD_CONTACT_ACK:
			status = mmp_packet.getBodyAttr('status')
			if status == CONTACT_OPER_SUCCESS:
				self.contact_list.users[_ack['mail']] = {
					'flags':0,
					'group':0,
					'nick':_ack['nick'],
					'server_flags':1,
					'status':_ack['status'],
					'phones':''
				}
				self.contact_list.cids[_ack['mail']] = mmp_packet.getBodyAttr('contact_id')
			_ack['ackf'](status, **_ack['acka'])

		elif ptype == MRIM_CS_MODIFY_CONTACT_ACK:
			status = mmp_packet.getBodyAttr('status')
			if status == CONTACT_OPER_SUCCESS:
				try:
					self.contact_list.delUser(_ack['mail'])
				except KeyError:
					pass
			_ack['ackf'](status, **_ack['acka'])
Example #10
0
	def getGroups(self):
		d = {}
		for g in self.packet.getBodyAttr('groups'):
			d[g[0]] = {'name':utils.win2str(g[1])}
		return d
Example #11
0
	def getBodyPayload(self):
		return utils.win2str(self.getBodyAttr('message'))