From 4ec15cfe8403c44864c7b112ce00c072c0e9d7cb Mon Sep 17 00:00:00 2001 From: yshurik Date: Sat, 3 Mar 2018 17:21:32 +0100 Subject: [PATCH] Update for bb-v1.30 (#6) * Update to v1.30 * Log level for console as WARNING --- .travis.yml | 6 +- bitbay/BitMHalo.py | 262 +++++++++++++++++++++++++++------------------ src/debug.py | 3 +- 3 files changed, 163 insertions(+), 108 deletions(-) diff --git a/.travis.yml b/.travis.yml index d8ae67c..6ea3cfb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -47,9 +47,13 @@ install: export PATH="/usr/local/opt/python/libexec/bin:$PATH" && (brew doctor || echo skip) && (brew install ruby || echo skip) && + (brew install pyenv || echo skip) && + brew install python@2 && + export PATH="/usr/local/opt/python@2/libexec/bin:$PATH" && + pyenv versions && brew tap cartr/qt4 && brew tap-pin cartr/qt4 && - brew install sip pyqt@4 && + brew install pyqt@4 && python --version && pip install pyinstaller && pip install pyzmail && diff --git a/bitbay/BitMHalo.py b/bitbay/BitMHalo.py index bab99dc..9fb0d6c 100644 --- a/bitbay/BitMHalo.py +++ b/bitbay/BitMHalo.py @@ -88,7 +88,7 @@ def FileLock(self, islocked): return True else: lockTHIS=0 - return True + return True def run(self): # Create server server = SimpleXMLRPCServer(("localhost", 8878),requestHandler=RequestHandler, logRequests = False) @@ -149,6 +149,7 @@ def parse_list_response(line): ch="" path=os.path.join(application_path,"BitTMP.dat") outpath=os.path.join(application_path,"Outbox.dat") + mailpath=os.path.join(application_path,"MailCache.dat") data=[] data.append("0") data.append("0") @@ -165,6 +166,14 @@ def parse_list_response(line): f.flush() os.fsync(f) f.close() + with open(mailpath,'a+') as f: + f.close() + if os.stat(mailpath)[6]==0: + with open(mailpath,'w') as f: + f.write("{}") + f.flush() + os.fsync(f) + f.close() ticker=0 ticker2=22 ticker3=0 @@ -383,7 +392,7 @@ def parse_list_response(line): connection.login(fromAddress, EmailPassword) connection.sendmail(fromAddress, toAddress, headers+"\r\n\r\n"+str(content)) connection.close() - else: + else: b64=base64.b64decode(content['b64img']) text_content=unicode(content['Data']) html_content=u'' + content['Data'] + \ @@ -489,6 +498,17 @@ def parse_list_response(line): connection.login(dat['Email Address'], dat['Password']) typ, mailbox_data = connection.list() inbox = [] + try: + with open(mailpath,'r') as f: + mailbox=f.readline() + f.close() + mailbox=ast.literal_eval(mailbox) + if mailbox=="": + float('a') + if dat['Email Address'] not in mailbox: + mailbox[dat['Email Address']]={} + except: + mailbox={str(dat['Email Address']):{}} for line in mailbox_data: try: flags, delimiter, mailbox_name = parse_list_response(line) @@ -532,105 +552,121 @@ def parse_list_response(line): continue sys.stderr.write("\n\n"+str(msg_id)+"\n\n") mymessage={} - try: - if systemexit==1:#Attempt a clean exit when possible - systemexit=2 - sys.stderr.write(str("Closing Bitmessage...")) - sys.exit() - sys.stderr.write(str("\n\nFETCHING...\n\n")) - #This is to prevent dropped connections, for now only on fetching - timeresult = False - try:#Let Halo know through RPC we started to download - myrpc.MessageStatus("1","password") - except Exception, e: - pass - @stopit.threading_timeoutable(timeout_param='my_timeout') - def timethis():#If we get dropped, we can time out - global timeresult, typ, msg_data, connection - typ, msg_data = connection.uid('fetch', msg_id, '(RFC822)') #connection.fetch(msg_id, '(RFC822)') - timeresult = True - timethis(my_timeout=600)#10 minutes is very generous - if timeresult==False: - float("A") - try:#Let Halo know through RPC we finished - myrpc.MessageStatus("0","password") - except Exception, e: - pass - sys.stderr.write(str("\n\nFETCHED!!\n\n")) - #readmessages.append(msg_id) - except: - connection.close() - sys.stderr.write(str("FETCH ERROR")) - if systemexit==2: - sys.exit() - continue - body = "" - try: - for part in msg_data: - if isinstance(part, tuple): - msg = email.message_from_string(part[1]) - try: - src = (msg['from'].split('<')[1].split('>')[0]).strip() - except: - src = msg['from'].strip() - try: - src1 = (msg['to'].split('<')[1].split('>')[0]).strip() - except: - src1 = msg['to'].strip() - try: - if msg.is_multipart(): - for msub in msg.get_payload(): - body = msub.get_payload(decode = True).decode(msub.get_content_charset()) - break - else: - body = msg.get_payload(decode = True).decode(msg.get_content_charset()) - except: + if msg_id in mailbox[str(dat['Email Address'])]: + try: + mymessage['toAddress']=mailbox[str(dat['Email Address'])][msg_id]['toAddress'] + mymessage['fromAddress']=mailbox[str(dat['Email Address'])][msg_id]['fromAddress'] + mymessage['body']=mailbox[str(dat['Email Address'])][msg_id]['body'] + mymessage['uid']=mailbox[str(dat['Email Address'])][msg_id]['uid'] + body=mymessage['body'] + except: + body="" + mymessage={} + sys.stderr.write("\n\nMessage reading error!\n\n") + else: + try: + if systemexit==1:#Attempt a clean exit when possible + systemexit=2 + sys.stderr.write(str("Closing Bitmessage...")) + sys.exit() + sys.stderr.write(str("\n\nFETCHING...\n\n")) + #This is to prevent dropped connections, for now only on fetching + timeresult = False + try:#Let Halo know through RPC we started to download + myrpc.MessageStatus("1","password") + except Exception, e: + pass + @stopit.threading_timeoutable(timeout_param='my_timeout') + def timethis():#If we get dropped, we can time out + global timeresult, typ, msg_data, connection + typ, msg_data = connection.uid('fetch', msg_id, '(RFC822)') #connection.fetch(msg_id, '(RFC822)') + timeresult = True + timethis(my_timeout=600)#10 minutes is very generous + if timeresult==False: + float("A") + try:#Let Halo know through RPC we finished + myrpc.MessageStatus("0","password") + except Exception, e: + pass + sys.stderr.write(str("\n\nFETCHED!!\n\n")) + #readmessages.append(msg_id) + except: + connection.close() + sys.stderr.write(str("FETCH ERROR")) + if systemexit==2: + sys.exit() + continue + body = "" + try: + for part in msg_data: + if isinstance(part, tuple): + msg = email.message_from_string(part[1]) try: - body=str(msg.encode('utf8')) + src = (msg['from'].split('<')[1].split('>')[0]).strip() except: - body=str(msg) - except Exception, e: - sys.stderr.write(str("MESSAGE ERROR ")) - sys.stderr.write(str(e)) - mymessage['toAddress']=str(src1) - mymessage['fromAddress']=str(src) - try: - body=str(body.encode('utf8')) - except: - sys.stderr.write(str("Not encoded")) - try: - body = body.split('****')[1].split('****')[0] - except: + src = msg['from'].strip() + try: + src1 = (msg['to'].split('<')[1].split('>')[0]).strip() + except: + src1 = msg['to'].strip() + try: + if msg.is_multipart(): + for msub in msg.get_payload(): + body = msub.get_payload(decode = True).decode(msub.get_content_charset()) + break + else: + body = msg.get_payload(decode = True).decode(msg.get_content_charset()) + except: + try: + body=str(msg.encode('utf8')) + except: + body=str(msg) + except Exception, e: + sys.stderr.write(str("MESSAGE ERROR ")) + sys.stderr.write(str(e)) + mymessage['toAddress']=str(src1) + mymessage['fromAddress']=str(src) try: - if 'You have received a payment of ' not in str(body): - body="" - else: - #I'm hoping email providers will not change this as identifying the full base64 string would be challenging. - #Any added padding gets changed when uploading the base64 image with the pyzmail library, although the bitmap is lossless - body = body.split('\nContent-Disposition: inline\n\n')[1].split('\n--=========')[0] - body="PAY TO EMAIL BASE64 IMAGE:"+body - except:#Okay they changed it we can try something else + body=str(body.encode('utf8')) + except: + sys.stderr.write(str("Not encoded")) + try: + body = body.split('****')[1].split('****')[0] + except: try: - bodymsg = email.message_from_string(str(body)) - x=0 - posx=0 - while x\nContent-Disposition: inline\n\n')[1].split('\n--=========')[0] + body="PAY TO EMAIL BASE64 IMAGE:"+body + except:#Okay they changed it we can try something else + try: + bodymsg = email.message_from_string(str(body)) + x=0 + posx=0 + while x