def send(self) -> None: mail: Mail = Mail(recipient=self.api_mail.user, addressee=Addressee(f'<{self.addressee.text()}>'), contents=self.contents.toPlainText(), subject=self.subject.text(), id=bytes()) self.api_mail.send(mail)
def download(self) -> List[Mail]: self.mail.select('inbox') status, data = self.mail.search(None, 'ALL') mails: List[Mail] = [] if status == 'OK': ids = [] for block in data: ids += block.split() for i in ids: status, data = self.mail.fetch(i, '(RFC822)') if status == 'OK': for response_part in data: if isinstance(response_part, tuple): message: Message = email.message_from_bytes(response_part[1]) mail_content: str = '' if message.is_multipart(): for part in message.get_payload(): if part.get_content_type() == 'text/plain': mail_content += part.get_payload() else: mail_content = message.get_payload() mail: Mail = Mail(id=i, addressee=Addressee(message['from']), recipient=message['to'], subject=message['subject'], contents=mail_content, date=message['date']) mail.change_category(self.classifier.guess(mail.contents)[0]) mails.append(mail) return mails
def handleICode(self, user, icode): # 处理邀请码,奖励 #自己进入的 mailType = configs_default['mail']['type']['rookieaward'] rookieAwardType = configs_default['actAwardType']['invalid'] icodeGGL = icode if configs_default['actAwardType'].has_key(icode) and icode != 'share': icodeGGL = 'ggl' mailType = configs_default['mail']['type']['gglaward'] if Dal_User().ownActAwardFlag(user.id,icodeGGL): rookieAwardType = configs_default['actAwardType']['post'] elif configs_default['actAwardType'].has_key(icode): rookieAwardType = configs_default['actAwardType'][icode] rookieAward = configs_default['actAward'][icode] # 给新人发新手奖励 if rookieAward > 0: user.money = user.money + rookieAward kwargs = {"money": user.money} Dal_User().uqdateUser(user.id, **kwargs) Dal_User().addActAwardFlag(user.id,icodeGGL) # 邮件记录 mail = Mail() mail.uid = user.id mail.type = mailType mail.content = str(rookieAward) mail.time = Utils().dbTimeCreate() Dal_Mail().addMail(mail) Dal_User().addMails(user.id, mail.id) return rookieAwardType
def post(self): msgReq = msg_pb2.Msg() msgReq.ParseFromString(self.request.body) msgResp = msg_pb2.Msg() msgResp.type = msg_pb2.EnumMsg.Value('luckyresponse') user = Dal_User().getUser(msgReq.request.luckyRequest.nUserID) if user == None: msgResp.response.luckyResponse.nErrorCode = config_error[ 'userinvaild'] elif user.luckytime and Utils().dbTime2Number( user.luckytime) >= Utils().LastDayEndTime(): msgResp.response.luckyResponse.nErrorCode = config_error[ 'luckytimeerror'] else: msgResp.response.luckyResponse.nErrorCode = config_error['success'] #抽奖逻辑 randNum = Utils().random_index(configs_default['luckysRate']) msgResp.response.luckyResponse.nLucky = randNum luckGood = configs_default['luckys'][randNum] if luckGood['type'] == configs_default['goodType']['money']: user.money = user.money + luckGood['extra'] elif luckGood['type'] == configs_default['goodType']['gold']: user.gold = user.gold + luckGood['extra'] user.luckytime = Utils().dbTimeCreate() msgResp.response.luckyResponse.newAssets.nUserID = user.id msgResp.response.luckyResponse.newAssets.nGold = user.gold msgResp.response.luckyResponse.newAssets.nMoney = user.money kwargs = { "gold": user.gold, "money": user.money, "luckytime": user.luckytime } Dal_User().uqdateUser(user.id, **kwargs) # 邮件记录 mail = Mail() mail.uid = user.id mail.type = configs_default['mail']['type']['luckyaward'] mail.content = str(luckGood['type']) + ':' + str(luckGood['extra']) mail.time = Utils().dbTimeCreate() Dal_Mail().addMail(mail) Dal_User().addMails(mail.uid, mail.id) dataR = msgResp.SerializeToString() self.write(dataR)
def received_new(self, msg): """ Called when a new message is received. """ engine = create_engine("sqlite:///data/emails.db", echo=True) Session = sessionmaker(bind=engine) session = Session(expire_on_commit=True) create_database(engine) logger.info("Subject: %s, From: %s, To: %s", msg['subject'], msg['from'], msg['to']) mmail = Mail(sender=msg['from'], subject=msg['subject'], payload=msg.get_payload(), datetime=msg['date'], to=msg["to"], category='0') session.add(mmail) session.commit()
def post(self): root = ElementTree.fromstring(self.request.body) node_result_code = root.find('result_code') node_return_code = root.find('return_code') attach = root.find('attach') totle_fee = root.find('total_fee') time_end = root.find('time_end') userData = str(attach.text) arrData = userData.split(';') UID = arrData[0] GID = arrData[1] Count = arrData[2] Money = arrData[3] if node_result_code.text == 'SUCCESS' and node_return_code.text == 'SUCCESS': #给支付返回结果 # returnMsg = "<xml><return_code><![CDATA[SUCCESS]]></return_code><return_msg><![CDATA[OK]]></return_msg></xml>"#self.createReturnXML() self.write("SUCCESS") #避免重复通知 if Dal_CZTime().getCZTime(time_end.text) != None: return # 记录支付通知结果时间 避免重复通知 czT = CZTime(time=time_end.text) Dal_CZTime().addCZTime(czT) #处理回调结果 user = Dal_User().getUser(UID) goodConfig = configs_default['goods'][GID] if goodConfig['type'] == configs_default['goodType']['money']: user.money = user.money + goodConfig['extra'] user.totalmoney = user.totalmoney + goodConfig['extra'] user.totalrmb = user.totalrmb + goodConfig['rmb'] # 检测代理充值奖励 delegater = Dal_Delegate().getDelegate(user.id) dLv = str(delegater.slevel) #原始等级 parentDelegater = Dal_Delegate().getDelegate(delegater.parent) if parentDelegater: # 对上级代理做奖励 parentUser = Dal_User().getUser(parentDelegater.id) awardPercent = configs_default['delegate']['payAwards'][ dLv] awardPay = math.ceil(goodConfig['extra'] * awardPercent) parentUser.money = parentUser.money + awardPay parentDelegater.awards = parentDelegater.awards + awardPay #给上级代理奖励的钻石 kwargs = {"money": parentUser.money} Dal_User().uqdateUser(parentUser.id, **kwargs) #上级代理获得的奖励总数 kwargs = {"awards": parentDelegater.awards} Dal_Delegate().uqdateDelegate(parentDelegater.id, **kwargs) # 邮件记录 mail = Mail() mail.uid = parentDelegater.id mail.type = configs_default['mail']['type'][ 'deleparentaward'] mail.content = str(awardPay) mail.time = Utils().dbTimeCreate() Dal_Mail().addMail(mail) Dal_User().addMails(mail.uid, mail.id) elif goodConfig['type'] == configs_default['goodType']['gold']: user.gold = user.gold + goodConfig['extra'] kwargs = { "gold": user.gold, "money": user.money, "totalmoney": user.totalmoney, "totalrmb": user.totalrmb } Dal_User().uqdateUser(user.id, **kwargs) # 充值 re = Recharge(id=None, time=Utils().dbTimeCreate(), money=Money, uid=UID, good=GID, count=Count, fromc=0) Dal_Recharge().addRecharge(re)
def __send(self, mail, response): my_mail: Mail = Mail(recipient=mail.recipient, addressee=mail.addressee, contents=response, subject=mail.category, id=bytes()) self.api_mail.send(mail=my_mail)
def test_another_subject_Mail(app): app.session.login(Credentials(username="******", password="******")) app.field_and_send_message(Mail(email="*****@*****.**", subject="ALERT! ALERT!")) time.sleep(1) app.session.logout()