question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

mark a message as read by object_id

See original GitHub issue

Hi,

is it possible to mark a message as read by the messages ID?

I have obtained the ID as the below but am unable to use it to mark a message as read it seems?

message obtained by message.object_id

account = Account((credentials.username, credentials.password))
mailbox = account.mailbox()
query = mailbox.new_query().on_attribute('id').contains(message_id)
messages = mailbox.get_messages(limit=1, query=query)

...| Error Message: The property 'Id' does not support filtering.

I assumed I would filter the mailbox then mark that message as read, is there another way?

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:13 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
OttomanZcommented, Oct 25, 2022

Latest Solution Working 25/11/22

full_message_object=self.sales_folder.get_message(object_id=message.object_id, download_attachments=True)

If you already have a message object like from .get_messages(limit=1000) and you want to only download attachment’s for certain messages and not all for speed or whatever reason you might have the best solution in that case is using the above code to get attachment, as follows,

if message.has_attachments:
     # fetch the message with message.object_id and download_attachmets=True

I hope you understand.

0reactions
hrvacadaIMcommented, Nov 8, 2022

Hi.

I found other way to patch the message. After investigating further MS Graph I found there are 4 endpoints for patching the message: https://github.com/microsoftgraph/microsoft-graph-docs/blob/main/api-reference/beta/api/message-update.md#http-request. For me this one worked: PATCH /users/{id | userPrincipalName}/mailFolders/{id}/messages/{id}. So at the end I ended up using requests module and send PATCH request to the MS Graph. Something like:

def mark_message_as_read(message):
    # Other way to update emails to read
    access_token = get_access_token()

    url = f'https://graph.microsoft.com/v1.0/users/{ACCOUNT}/mailFolders/Inbox/messages/{message.object_id}'
    body = {
        'isRead': True
    }
    headers = {
        'Authorization': f'Bearer {access_token}',
        'Content-Type': 'application/json;charset=UTF-8'
    }

    try:
        response = requests.patch(url, json=body, headers=headers)
        response.raise_for_status()
        return True
    except requests.exceptions.HTTPError as ex:
        pprint.pprint(ex)
        return False
Read more comments on GitHub >

github_iconTop Results From Across the Web

ObjectId — MongoDB Manual
Returns a new ObjectId value. The 12-byte ObjectId value consists of: a 4-byte timestamp value, representing the ObjectId's creation, measured in seconds since ......
Read more >
MongoDB / NOSQL: Best approach to handling read/unread ...
Suppose you have a large number of users (M) and a large number of documents (N) and you want each user to be...
Read more >
What Is Objectid in Mongodb and How to Generate It Manually
Learn from what is ObjectId and its importance, generating a new ObjectId manually to methods available over Object Id and how to use...
Read more >
Search by ObjectId in mongodb with PyMongo - Python
Read ; Discuss; Courses; Practice; Video ... ObjectId is the default primary key for MongoDB documents and is usually found in “_id” field....
Read more >
Can´t read from Azure Cosmos DB (because ObjectId?)?
I have also hit my head on this issue using the Azure CosmosDb MongoDb API, finally found a workaround which so far is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found