querying mails without categories not supported - microsoft-graph-api

We are trying to use Microsoft graph to query a mailbox and return us all uncategorized mails.
Following the OData spec here: https://docs.oasis-open.org/odata/odata/v4.0/errata03/os/complete/part2-url-conventions/odata-v4.0-errata03-os-part2-url-conventions-complete.html#_Toc453752358
We should be able to do something like this:
$filter=Categories/$count eq 0
But the call returns an operation not supported exception.
Is there another way to query for uncategorized Mail messages?

Querying mails without categories doesn't appear to be supported at this time. Please add a feature request to Microsoft Graph User Voice. I might as well share what I found in case it is useful to someone.
Unfortunately, the following doesn't work:
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$filter=not categories/any()&$select=categories
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$filter=categories/$count eq 0
This will return all mail with categories:
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$filter=categories/any()&$select=categories
This will return all mail of a particular category:
https://graph.microsoft.com/v1.0/me/mailFolders/inbox/messages?$filter=categories/any(x:x eq 'particular category')&$select=categories

Related

Twitter v1 stream API returns wrong mentions

I'm tracking all mentions of #UN with Tweepy using Twitter stream v1 API. However, I'm also getting all mentions of usernames containing #UN such as #UN_Women. I could filter them out in a post-processing step but this seems very inefficient.
Is there any way to avoid this?
This is my code:
class MyStreamListener(tweepy.StreamListener):
def on_status(self, status):
print(status.text)
myStreamListener = MyStreamListener()
myStream = tweepy.Stream(auth = api.auth, listener=myStreamListener())
myStream.filter(track=['#UN'])
Using follow instead of track should work. With follow, you supply a list of user IDs:
myStream.filter(follow=['14159148'])
I don't know if tweepy provides any further functionalities to avoid this. But what you can do here is, filter out the results while saving it to your database or csv.
Check the json response and look for entities object and in that check for user_mentions and screen_name. Save only the one with your desired screen_name

graph api me/messages endpoint doesn't allow start and end DateTime in select list

I am trying to list down all my meetings with a certain email id. I only want to select few things out of the huge response. Duration is one of the main insight and it won't allow to return the start and end datetime.
URL:
https://graph.microsoft.com/v1.0/me/messages?$select=startDateTime,subject,from,sender,toRecipients&$search="participants:xyz#contoso.com and kind:meetings"
Error I am getting is
"message": "Could not find a property named 'startDateTime' on type 'Microsoft.OutlookServices.Message'
Is this expected?
Are you looking for how to query all meetings ? but your query is for messages. Can you please clarify?
If you are looking for help with messages from specific person along with created data time you can update your query like this -
https://graph.microsoft.com/v1.0/me/messages?$select=createdDateTime,Id,lastModifiedDateTime,from,subject&$filter=from/emailAddress/name eq 'XYZ A'

Trying to get a list of Teams a user has ownership

Trying to get a list of Teams a specific user has ownership with Graph api.
Any assistance is much appreciated.
This command will provide a list of teams but you need to get the group id first:
https://graph.microsoft.com/beta/groups/{id}/owners
I tried the following but I couldn't get the correct results.
https://graph.microsoft.com/beta/groups?$expand=owners($filter=userprinciplename eq '<>'&$select=id,displayname,userprinciplename)&$filter=resourceProvisioningOptions/Any(x:x eq 'Team')
You can use ownedObjects to get the list of directory objects that are owned by the user. This includes Unified Groups in the groupTypes and output the resourceProvisioningOptions here too.
https://graph.microsoft.com/v1.0/me/ownedObjects
more documentation on that here https://learn.microsoft.com/en-us/graph/api/user-list-ownedobjects?view=graph-rest-1.0&tabs=cs .
Unfortunately it is not supported to use $filter like this. So you'll have to do on your side. So this won't work
https://graph.microsoft.com/v1.0/me/ownedObjects?$filter=resourceProvisioningOptions/Any(x:x eq 'Team')
Your query was incorrect. Please try the below updated query.
https://graph.microsoft.com/beta/groups?$expand=owners($filter=userprinciplename eq 'add your mail id here')&select=id,displayname&$filter=resourceProvisioningOptions/Any(x:x eq 'Team')

Rails Griddler and conversation / email threading

I'm trying to work out how best to connect / thread a chain of emails. This seems like such a common problem that I was surprised that I couldn't easily locate information on how other people have dealt with it. The only thing I found was a post about JWZ threading which looked more concerned with parsing together a thread in one email. I was wondering if anyone could point to me some current solutions.
I'm using the thoughtbot griddler gem to process incoming emails into a model Message(s) and a separate model Contact(s), and I have a third model for storing replies, e.g. Reply.
My current thinking is to thread them by the unique contact and the subject line. But then again the subject line will change slightly. e.g. from "This subject" -> "Re: re: This subject" I could use regex to try parsing out "re:"s or I could use something like amatch to do string comparisons?
But then again, what to do about the same subject appearing for the same user 2 months later? Also add some logic regarding the current date so that threads only use recent emails. Then there might be something else useful stored in the email header itself?
User (by unique email address)
Unique Subject line (regex re: processing issues?)
Current date (emails must be date relative to each other)
Some other clues to look for in the email header?
I have i rough idea of how to do it, I'm just curious to see some current implementations, I just can't seem to find any.
Any pointers would be greatly appreciated!
Email threads are a linked list, the information in the headers contains enough information to reconstruct the list from its component parts.
Introspect the email headers and to look for some specific headers.
The key ones you'll use are Message-ID, In-Reply-To and References. These headers give you information about which message was replied to and what other ids matter to the email thread itself.
The easiest way to find information about the headers of an email is to open the 'Original Message' in gmail (from the more menu).
There is a new gem named Msgthr, which is an implementation JWZ's algorithm. It's not matching subjects, senders or dates, so it's not exactly what you're looking for, but I think it's a good start.
The neatest thing about Msgthr is that it's container-agnostic, hence you don't have to install requirements such as TMail, as in Frederik Dietz's ruby port. This also means it can be used for other types of communications.
Here's some sample code, given a list of messages, let's group them into threads:
thr = Msgthr.new
threads = {}
[1, 11, 12, 2, 21, 211].each{ |id| threads[id] = [id]}
my_add = lambda do |id, refs, msg|
thr.add(id, refs, msg) do |parent, child|
threads[child.mid] = threads[parent.mid]
end
end
# Create the following structure
# 1
# \
# | 1.1
# \
# 1.2
# 2
# \
# 2.1
# \
# 2.1.1
my_add.call(1, nil, '1')
my_add.call(11, [1], '1.1')
my_add.call(12, [1], '1.2')
my_add.call(2, nil, '2')
my_add.call(21, [2], '2.1')
my_add.call(211, [21], '2.1.1')
thr.thread!
thr.rootset.each do |cnt|
threads[cnt.mid][0] = cnt.msg
end
Disclosure: I'm one of the contributors to the gem.

Twitter gem for Ruby: How to safely iterate over friends of someone who has A LOT of friends

I'm confused about the friends method in the Twitter gem. I see that Twitter::REST::FriendsAndFollowers#friends uses a GET friends/list request and the cursor_from_response_with_user method.
The documentation for GET friends/list says that requests are limited to 20 users. I assume this means that 20 friends will be returned per request. But, say I am following 22 people and I use the following:
twitter_client = Twitter::REST::Client.new { [my credentials here] }
twitter_client.friends
This returns an array of all 22 friends. I didn't do anything to mess with cursors, so why am I getting all 22? On to my main question...
In my app, when someone imports their friends, I'm iterating over them and creating some other records. Something like this
twitter_client.friends.each do |friend|
SomeModel.do_what_you_need_to_with(friend)
AnotherModel.do_something_else_with(friend)
end
Let's say someone has 5001 Twitter friends. (Impressive!) I'm thinking this is going to be a problem with rate limiting, etc. What's the safest way to get all the friends, and iterate over all of them?
I've tried to figuring out the gem's documentation on cursors, but the fact that friends returned 22 results is throwing me off...
The 20 that you mention is the number of users per page returned by the API. The gem will iterate over all pages, so it will return as many users as possible within the rate limit.
As how to handle the rate limiting, it's up to you. There's an example here that will just put the process to sleep for a while and then retry. Another option is to just quit the app and run it again in a few minutes with something like cron, but it obviously depends on your app.
This is a great question. I ran into the same issue.
I can see how iterating over ALL friends is a feature. However, if you are only interested in the first 20 friends , here's how to not request any more friends:
twitter_client.friends.to_h[ :users ]
Since friends request returns 20, this may not be so useful. If you want friend_ids or follower_ids, the API will return up to 5,000. For many use cases 5,000 is plenty.
twitter_client.friends.to_h[ :ids ]

Resources