mirror of
https://github.com/Sneed-Group/pypush-plus-plus
synced 2024-12-23 03:15:15 -06:00
Upload files to ''
This commit is contained in:
parent
902965a410
commit
6598540ff9
5 changed files with 98 additions and 74 deletions
29
albert.py
29
albert.py
File diff suppressed because one or more lines are too long
39
demo.py
39
demo.py
|
@ -178,12 +178,22 @@ while True:
|
|||
if msg == 'help' or msg == 'h':
|
||||
print('help (h): show this message')
|
||||
print('quit (q): quit')
|
||||
#print('send (s) [recipient] [message]: send a message')
|
||||
print('filter (f) [recipient]: set the current chat')
|
||||
print('send (s) [recipient] [message]: send a message')
|
||||
#print('filter (f) [recipient]: set the current chat')
|
||||
print('effect (e): adds an iMessage effect to the next sent message')
|
||||
print('note: recipient must start with tel: or mailto: and include the country code')
|
||||
print('handle <handle>: set the current handle (for sending messages)')
|
||||
print('\\: escape commands (will be removed from message)')
|
||||
elif msg.startswith('send') or msg.startswith('s'):
|
||||
msg = msg.split(' ')
|
||||
if len(msg) < 3:
|
||||
print('send [recipient] [message]')
|
||||
else:
|
||||
im.send(imessage.iMessage(
|
||||
text=' '.join(msg[2:]),
|
||||
participants=[msg[1], user.handles[0]],
|
||||
#sender=user.handles[0]
|
||||
))
|
||||
elif msg == 'quit' or msg == 'q':
|
||||
break
|
||||
elif msg == 'effect' or msg == 'e' or msg.startswith("effect ") or msg.startswith("e "):
|
||||
|
@ -193,14 +203,14 @@ while True:
|
|||
else:
|
||||
print(f"next message will be sent with [{msg[1]}]")
|
||||
current_effect = msg[1]
|
||||
elif msg == 'filter' or msg == 'f' or msg.startswith('filter ') or msg.startswith('f '):
|
||||
#elif msg == 'filter' or msg == 'f' or msg.startswith('filter ') or msg.startswith('f '):
|
||||
# Set the curernt chat
|
||||
msg = msg.split(' ')
|
||||
if len(msg) < 2 or msg[1] == '':
|
||||
print('filter [recipients]')
|
||||
else:
|
||||
print(f'Filtering to {[fixup_handle(h) for h in msg[1:]]}')
|
||||
current_participants = [fixup_handle(h) for h in msg[1:]]
|
||||
#msg = msg.split(' ')
|
||||
#if len(msg) < 2 or msg[1] == '':
|
||||
#print('filter [recipients]')
|
||||
#else:
|
||||
#print(f'Filtering to {[fixup_handle(h) for h in msg[1:]]}')
|
||||
#current_participants = [fixup_handle(h) for h in msg[1:]]
|
||||
elif msg == 'handle' or msg.startswith('handle '):
|
||||
msg = msg.split(' ')
|
||||
if len(msg) < 2 or msg[1] == '':
|
||||
|
@ -235,14 +245,3 @@ while True:
|
|||
|
||||
time.sleep(0.1)
|
||||
|
||||
# elif msg.startswith('send') or msg.startswith('s'):
|
||||
# msg = msg.split(' ')
|
||||
# if len(msg) < 3:
|
||||
# print('send [recipient] [message]')
|
||||
# else:
|
||||
# im.send(imessage.iMessage(
|
||||
# text=' '.join(msg[2:]),
|
||||
# participants=[msg[1], user.handles[0]],
|
||||
# #sender=user.handles[0]
|
||||
# ))
|
||||
|
||||
|
|
91
imessage.py
91
imessage.py
|
@ -28,6 +28,7 @@ logger = logging.getLogger("imessage")
|
|||
|
||||
NORMAL_NONCE = b"\x00" * 15 + b"\x01" # This is always used as the AES nonce
|
||||
|
||||
bundled_payloads = []
|
||||
|
||||
class BalloonBody:
|
||||
"""Represents the special parts of message extensions etc."""
|
||||
|
@ -257,20 +258,34 @@ class iMessageUser:
|
|||
Returns None if no conforming notification is found
|
||||
"""
|
||||
|
||||
def check_response(x):
|
||||
if x[0] != 0x0A:
|
||||
return False
|
||||
if apns._get_field(x[1], 2) != sha1("com.apple.madrid".encode()).digest():
|
||||
return False
|
||||
resp_body = apns._get_field(x[1], 3)
|
||||
if resp_body is None:
|
||||
# logger.debug("Rejecting madrid message with no body")
|
||||
return False
|
||||
resp_body = plistlib.loads(resp_body)
|
||||
if "P" not in resp_body:
|
||||
# logger.debug(f"Rejecting madrid message with no payload : {resp_body}")
|
||||
return False
|
||||
return True
|
||||
#def check_response(x):
|
||||
#if x[0] != 0x0A:
|
||||
#return False
|
||||
#if apns._get_field(x[1], 2) != sha1("com.apple.madrid".encode()).digest():
|
||||
#return False
|
||||
#resp_body = apns._get_field(x[1], 3)
|
||||
#if resp_body is None:
|
||||
# logger.debug("Rejecting madrid message with no body")
|
||||
#return False
|
||||
#resp_body = plistlib.loads(resp_body)
|
||||
#if "P" not in resp_body:
|
||||
# logger.debug(f"Rejecting madrid message with no payload : {resp_body}")
|
||||
#return False
|
||||
#return True
|
||||
|
||||
def check_response(x):
|
||||
if x[0] != 0x0A:
|
||||
return False
|
||||
if apns._get_field(x[1], 2) != sha1("com.apple.madrid".encode()).digest():
|
||||
return False
|
||||
resp_body = apns._get_field(x[1], 3)
|
||||
if resp_body is None:
|
||||
return False
|
||||
resp_body = plistlib.loads(resp_body)
|
||||
if "c" not in resp_body or resp_body["c"] != 255:
|
||||
return False
|
||||
return True
|
||||
|
||||
|
||||
payload = self.connection.incoming_queue.pop_find(check_response)
|
||||
if payload is None:
|
||||
|
@ -494,7 +509,6 @@ class iMessageUser:
|
|||
raw = message.to_raw()
|
||||
import base64
|
||||
|
||||
bundled_payloads = []
|
||||
for participant in message.participants:
|
||||
participant = participant.lower()
|
||||
for push_token in self.USER_CACHE[participant]:
|
||||
|
@ -530,6 +544,7 @@ class iMessageUser:
|
|||
"sP": message.sender,
|
||||
}
|
||||
|
||||
|
||||
body = plistlib.dumps(body, fmt=plistlib.FMT_BINARY)
|
||||
|
||||
self.connection.send_message("com.apple.madrid", body, msg_id)
|
||||
|
@ -537,29 +552,29 @@ class iMessageUser:
|
|||
# This code can check to make sure we got a success response, but waiting for the response is annoying,
|
||||
# so for now we just YOLO it and assume it worked
|
||||
|
||||
# def check_response(x):
|
||||
# if x[0] != 0x0A:
|
||||
# return False
|
||||
# if apns._get_field(x[1], 2) != sha1("com.apple.madrid".encode()).digest():
|
||||
# return False
|
||||
# resp_body = apns._get_field(x[1], 3)
|
||||
# if resp_body is None:
|
||||
# return False
|
||||
# resp_body = plistlib.loads(resp_body)
|
||||
# if "c" not in resp_body or resp_body["c"] != 255:
|
||||
# return False
|
||||
# return True
|
||||
#def check_response(x):
|
||||
#if x[0] != 0x0A:
|
||||
#return False
|
||||
#if apns._get_field(x[1], 2) != sha1("com.apple.madrid".encode()).digest():
|
||||
#return False
|
||||
#resp_body = apns._get_field(x[1], 3)
|
||||
#if resp_body is None:
|
||||
#return False
|
||||
#resp_body = plistlib.loads(resp_body)
|
||||
#if "c" not in resp_body or resp_body["c"] != 255:
|
||||
#return False
|
||||
#return True
|
||||
|
||||
num_recv = 0
|
||||
|
||||
# num_recv = 0
|
||||
# while True:
|
||||
# if num_recv == len(bundled_payloads):
|
||||
# break
|
||||
# payload = self.connection.incoming_queue.wait_pop_find(check_response)
|
||||
# if payload is None:
|
||||
# continue
|
||||
while True:
|
||||
if num_recv == len(bundled_payloads):
|
||||
break
|
||||
payload = self.connection.incoming_queue.wait_pop_find(check_response)
|
||||
if payload is None:
|
||||
continue
|
||||
|
||||
# resp_body = apns._get_field(payload[1], 3)
|
||||
# resp_body = plistlib.loads(resp_body)
|
||||
# logger.error(resp_body)
|
||||
# num_recv += 1
|
||||
resp_body = apns._get_field(payload[1], 3)
|
||||
resp_body = plistlib.loads(resp_body)
|
||||
logger.error(resp_body)
|
||||
num_recv += 1
|
||||
|
|
|
@ -7,3 +7,4 @@ pbkdf2
|
|||
unicorn
|
||||
rich
|
||||
prompt_toolkit
|
||||
trio
|
||||
|
|
Loading…
Reference in a new issue