MCPcopy Index your code
hub / github.com/Bitmessage/PyBitmessage / readSentMsg

Function readSentMsg

src/bitmessagecli.py:950–1006  ·  view source on GitHub ↗
(msgNum)

Source from the content-addressed store, hash-verified

948 print ' -----------------------------------\n'
949
950def readSentMsg(msgNum): #Opens a sent message for reading
951 global usrPrompt
952 try:
953 outboxMessages = json.loads(api.getAllSentMessages())
954 numMessages = len(outboxMessages['sentMessages'])
955 except:
956 print '\n Connection Error\n'
957 usrPrompt = 0
958 main()
959
960 print ' '
961
962 if (msgNum >= numMessages):
963 print '\n Invalid Message Number.\n'
964 main()
965
966 #Begin attachment detection
967 message = outboxMessages['sentMessages'][msgNum]['message'].decode('base64')
968
969 while True: #Allows multiple messages to be downloaded/saved
970 if (';base64,' in message): #Found this text in the message, there is probably an attachment.
971 attPos= message.index(";base64,") #Finds the attachment position
972 attEndPos = message.index("' />") #Finds the end of the attachment
973 #attLen = attEndPos - attPos #Finds the length of the message
974
975
976 if ('alt = "' in message): #We can get the filename too
977 fnPos = message.index('alt = "') #Finds position of the filename
978 fnEndPos = message.index('" src=') #Finds the end position
979 #fnLen = fnEndPos - fnPos #Finds the length of the filename
980
981 fileName = message[fnPos+7:fnEndPos]
982 else:
983 fnPos = attPos
984 fileName = 'Attachment'
985
986 uInput = userInput('\n Attachment Detected. Would you like to save the attachment, (Y)es or (N)o?').lower()
987 if (uInput == "y" or uInput == 'yes'):
988
989 attachment = message[attPos+9:attEndPos]
990 saveFile(fileName,attachment)
991
992 message = message[:fnPos] + '~<Attachment data removed for easier viewing>~' + message[(attEndPos+4):]
993
994 else:
995 break
996
997 #End attachment Detection
998
999 print '\n To:', getLabelForAddress(outboxMessages['sentMessages'][msgNum]['toAddress']) #Get the to address
1000 print ' From:', getLabelForAddress(outboxMessages['sentMessages'][msgNum]['fromAddress']) #Get the from address
1001 print ' Subject:', outboxMessages['sentMessages'][msgNum]['subject'].decode('base64') #Get the subject
1002 print ' Status:', outboxMessages['sentMessages'][msgNum]['status'] #Get the subject
1003 print ' Last Action Time:', datetime.datetime.fromtimestamp(float(outboxMessages['sentMessages'][msgNum]['lastActionTime'])).strftime('%Y-%m-%d %H:%M:%S')
1004 print ' Message:\n'
1005 print message #inboxMessages['inboxMessages'][msgNum]['message'].decode('base64')
1006 print ' '
1007

Callers 1

UIFunction · 0.85

Calls 5

userInputFunction · 0.85
saveFileFunction · 0.85
getLabelForAddressFunction · 0.85
mainFunction · 0.70
decodeMethod · 0.45

Tested by

no test coverage detected