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

Function attachment

src/bitmessagecli.py:637–723  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

635 print '\n Successfully saved '+ filePath + '\n'
636
637def attachment(): #Allows users to attach a file to their message or broadcast
638 theAttachmentS = ''
639
640 while True:
641
642 isImage = False
643 theAttachment = ''
644
645 while True:#loops until valid path is entered
646 filePath = userInput('\nPlease enter the path to the attachment or just the attachment name if in this folder.')
647
648 try:
649 with open(filePath): break
650 except IOError:
651 print '\n %s was not found on your filesystem or can not be opened.\n' % filePath
652 pass
653
654 #print filesize, and encoding estimate with confirmation if file is over X size (1mb?)
655 invSize = os.path.getsize(filePath)
656 invSize = (invSize / 1024) #Converts to kilobytes
657 round(invSize,2) #Rounds to two decimal places
658
659 if (invSize > 500.0):#If over 500KB
660 print '\n WARNING:The file that you are trying to attach is ', invSize, 'KB and will take considerable time to send.\n'
661 uInput = userInput('Are you sure you still want to attach it, (Y)es or (N)o?').lower()
662
663 if uInput != "y":
664 print '\n Attachment discarded.\n'
665 return ''
666 elif (invSize > 184320.0): #If larger than 180MB, discard.
667 print '\n Attachment too big, maximum allowed size:180MB\n'
668 main()
669
670 pathLen = len(str(ntpath.basename(filePath))) #Gets the length of the filepath excluding the filename
671 fileName = filePath[(len(str(filePath)) - pathLen):] #reads the filename
672
673 filetype = imghdr.what(filePath) #Tests if it is an image file
674 if filetype is not None:
675 print '\n ---------------------------------------------------'
676 print ' Attachment detected as an Image.'
677 print ' <img> tags will automatically be included,'
678 print ' allowing the recipient to view the image'
679 print ' using the "View HTML code..." option in Bitmessage.'
680 print ' ---------------------------------------------------\n'
681 isImage = True
682 time.sleep(2)
683
684 print '\n Encoding Attachment, Please Wait ...\n' #Alert the user that the encoding process may take some time.
685
686 with open(filePath, 'rb') as f: #Begin the actual encoding
687 data = f.read(188743680) #Reads files up to 180MB, the maximum size for Bitmessage.
688 data = data.encode("base64")
689
690 if (isImage == True): #If it is an image, include image tags in the message
691 theAttachment = """
692<!-- Note: Image attachment below. Please use the right click "View HTML code ..." option to view it. -->
693<!-- Sent using Bitmessage Daemon. https://github.com/Dokument/PyBitmessage-Daemon -->
694

Callers 3

sendMsgFunction · 0.85
sendBrdFunction · 0.85
replyMsgFunction · 0.85

Calls 4

userInputFunction · 0.85
readMethod · 0.80
mainFunction · 0.70
encodeMethod · 0.45

Tested by

no test coverage detected