exchangelib icon indicating copy to clipboard operation
exchangelib copied to clipboard

Support GetUserRetentionPolicyTags service

Open mnj009 opened this issue 4 years ago • 7 comments

Hi Team ,

Could you please help us to read below two attributes/fields of an email Retention policy Expires

I have searched in headers , but no luck

Thanks in advance

mnj009 avatar May 07 '21 18:05 mnj009

I can’t find any documentation that these fields should be available on an EWS message item. Do you have a link describing these fields?

ecederstrand avatar May 08 '21 06:05 ecederstrand

https://docs.microsoft.com/en-us/exchange/client-developer/exchange-web-services/whats-new-in-ews-and-other-web-services-in-exchange

https://docs.microsoft.com/en-us/exchange/client-developer/web-service-reference/getuserretentionpolicytags-operation?redirectedfrom=MSDN

mnj009 avatar May 08 '21 07:05 mnj009

Ah, ok. The GetUserRetentionPolicyTags service is not yet supported in exchangelib.

I still don't know what Expires refers to here.

ecederstrand avatar May 09 '21 12:05 ecederstrand

In EWS , they have named it as retention date Here is the documentation from EWS

https://docs.microsoft.com/en-us/dotnet/api/microsoft.exchange.webservices.data.item.retentiondate

mnj009 avatar May 09 '21 14:05 mnj009

Hi, I have also similar task needs to be done using the exchangelib in python to get the rentention date.please provide a update on this.

ahalyarekha avatar May 10 '21 21:05 ahalyarekha

I don't have any plans to work on this myself in the near future. Contributions are welcome, as always.

ecederstrand avatar May 10 '21 21:05 ecederstrand

I know this one is old, but thought I'd update what I did during recent testing. I'm very new to python so, I'm sure there's better ways to do this, but I just followed the same logic for flags referenced here: https://github.com/ecederstrand/exchangelib/issues/85#issuecomment-283448809

I had to convert the binary (bytes) to a Microsoft system GUID, so used a function referenced here.

class Label(ExtendedProperty):
    property_tag = 0x3019
    property_type = 'Binary'

    def to_guid():
        b = self.value
        return '-'.join(map(bytes.decode, map(
            binascii.hexlify, (b[0:4][::-1], b[4:6][::-1], b[6:8][::-1], b[8:10], b[10:])
        )))

Message.register('label', Label)

for m in account.inbox.all():
    if m.label:
        print("Subject: " + m.subject)
        print("Label: " + m.label.to_guid())

End result:

Subject: Test email with M365 retention label
Label: 37d7071b-7818-4e98-ae3e-56c0dc330119

Which, with the GUID, you can pull back the name using EXO PowerShell:

Get-ComplianceTag 37d7071b-7818-4e98-ae3e-56c0dc330119 | select Name

Name
----
7YearRecord-LastModified

I think the label names are stored/accessible via EWS since EWSEditor can pull them, but that's as far as I got.

I also didn't look at the Expiration date, but based on the EWSEditor references, I think it might be 0x301c as SystemTime property type

brenle avatar Jun 27 '22 22:06 brenle