opulentfox-29 / protonmail-api-client

This is not an official python ProtonMail API client. it allows you to read, send and delete messages in protonmail, as well as render a ready-made template with embedded images.
GNU General Public License v3.0
15 stars 5 forks source link

new_message returning empty body #3

Closed iceFbr closed 9 months ago

iceFbr commented 9 months ago

Really nice job with that api! ty!

btw, is new_message method returning empty body message just for me? =)

iceFbr commented 9 months ago

fix it, i am sorry. Messed up when implementing proxy over your code kkk

iceFbr commented 9 months ago

(just added read_message after capturing the last message receveid... but would be a nice fix over client.py, no? )

opulentfox-29 commented 9 months ago

The wait_for_new_message method is supposed to wait for a new message, but not read it. If you need you can read it further:

new_message = proton.wait_for_new_message()
new_message = proton.read_message(new_message)

The user is not always required to read the received message. Depending on the subject of the message or the sender, the user can decide whether to read the message or not.

new_message = proton.wait_for_new_message()
if "authorization code" in new_message:
    new_message = proton.read_message(new_message)
    html = new_message.body
    ...  # parse html
else:
    proton.delete_messages([new_message])

Forcing the user to read a message that he does not want to read at the moment is not the best solution.

opulentfox-29 commented 9 months ago

But I added read_message parameter to the wait_for_new_message method. https://github.com/opulentfox-29/protonmail-api-client/commit/2c0560fa55af7b035547977f3d338ae814616180

new_message = proton.wait_for_new_message(read_message=True)
print(new_message.body)  # your html