Accessing the Muddle Folder with EWS in Workplace365Alternate On-line

Accessing the Muddle Folder with EWS in Workplace365Alternate On-line To begin off the brand new yr I believed I might take a look at how one can go about utilizing a number of the new options which can be being launched in Alternate On-line. One of many massive new options is Muddle which all of us noticed at MEC is Austin and is now being rolled out to Workplace365 tenants. If you do not know what litter is take a look at http://blogs.workplace.com/2014/11/11/de-clutter-inbox-office-365/ however mainly it’s Machine studying (AI or skynet for the paranoid) to your Mailbox. Machine studying is among the fruits of accelerating processing energy and likewise the cloud in that software program improvement/rollout cycles are actually extra carefully aligned to what {hardware} can do. Remember that is simply the beginning of what the expertise can do, there’s simply thus far tweaking UI’s can go so this to me is the place the actually thrilling way forward for the tech is and I am trying ahead to see the place this goes within the coming yr.

Again to the topic at hand once you allow Muddle you find yourself with a brand new folder in your Mailbox that hangs of the MsgRoot known as Muddle (or the localized equal). Whereas there are a selection of latest objects for Muddle within the new Proxy definitions in EWS there isn’t a Distinguishedfolderid for the Muddle folder like most different Mailbox system folders. So to get the Muddle folder in EWS you’ll need to both seek for it by title of a greater manner is you need to use the ClutterFolderEntryId prolonged property which is obtainable on the Mailbox’s Non_ipm_root folder. If you request this property you’ll get returned the HexEntryId of the Muddle folder which you then must convert utilizing the ConvertId operation to an EWSId. You then will be capable of bind to the folder as per traditional. To place this collectively in a selected pattern listed below are two instance of doing this in c# and powershell. The next will get the Muddle folder and exhibiting the variety of Unread E mail on this folder.

c#

 1
2
3
4
5
6
7
8
9
10
11
12
13
14
            ExtendedPropertyDefinition ClutterFolderEntryId = new ExtendedPropertyDefinition(new Guid("{23239608-685D-4732-9C55-4C95CB4E8E33}"), "ClutterFolderEntryId", MapiPropertyType.Binary);
PropertySet iiips = new PropertySet();
iiips.Add(ClutterFolderEntryId);
String MailboxName = "jcool@domain.com";
FolderId FolderRootId = new FolderId(WellKnownFolderName.Root, MailboxName);
Folder FolderRoot = Folder.Bind(service, FolderRootId, iiips);
Byte[] FolderIdVal = null;
if (FolderRoot.TryGetProperty(ClutterFolderEntryId, out FolderIdVal))
{
AlternateId aiId = new AlternateId(IdFormat.HexEntryId, BitConverter.ToString(FolderIdVal).Change("-", ""), MailboxName);
AlternateId ConvertedId = (AlternateId)service.ConvertId(aiId, IdFormat.EwsId);
Folder ClutterFolder = Folder.Bind(service, new FolderId(ConvertedId.UniqueId));
Console.WriteLine("Unread Email in clutter : " + ClutterFolder.UnreadCount);
}

Powershell

  1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
## Get the Mailbox to Entry from the first commandline argument

$MailboxName = $args[0]

## Load Managed API dll

###CHECK FOR EWS MANAGED API, IF PRESENT IMPORT THE HIGHEST VERSION EWS DLL, ELSE EXIT
$EWSDLL = (($(Get-ItemProperty -ErrorAction SilentlyContinue -Path Registry::$(Get-ChildItem -ErrorAction SilentlyContinue -Path 'Registry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftExchangeWeb Providers'|Kind-Object Title -Descending| Choose-Object -First 1 -ExpandProperty Title)).'Set up Listing') + "Microsoft.Exchange.WebServices.dll")
if (Check-Path $EWSDLL)
{
Import-Module $EWSDLL
}
else
{
"$(get-date -format yyyyMMddHHmmss):"
"This script requires the EWS Managed API 1.2 or later."
"Please download and install the current version of the EWS Managed API from"
"http://go.microsoft.com/fwlink/?LinkId=255472"
""
"Exiting Script."
exit
}

## Set Alternate Model
$ExchangeVersion = [Microsoft.Exchange.WebServices.Data.ExchangeVersion]::Alternate2010_SP2

## Create Alternate Service Object
$service = New-Object Microsoft.Alternate.WebServices.Knowledge.ExchangeService($ExchangeVersion)

## Set Credentials to make use of two choices are availible Option1 to make use of explict credentials or Possibility 2 use the Default (logged On) credentials

#Credentials Possibility 1 utilizing UPN for the home windows Account
$psCred = Get-Credential
$creds = New-Object System.Web.NetworkCredential($psCred.UserName.ToString(),$psCred.GetNetworkCredential().password.ToString())
$service.Credentials = $creds

#Credentials Possibility 2
#service.UseDefaultCredentials = $true

## Select to disregard any SSL Warning points attributable to Self Signed Certificates

## Code From http://poshcode.org/624
## Create a compilation surroundings
$Supplier=New-Object Microsoft.CSharp.CSharpCodeProvider
$Compiler=$Supplier.CreateCompiler()
$Params=New-Object System.CodeDom.Compiler.CompilerParameters
$Params.GenerateExecutable=$False
$Params.GenerateInMemory=$True
$Params.IncludeDebugInformation=$False
$Params.ReferencedAssemblies.Add("System.DLL") | Out-Null

$TASource=@'
namespace Native.ToolkitExtensions.Web.CertificatePolicy{
public class TrustAll : System.Web.ICertificatePolicy {
public TrustAll() {
}
public bool CheckValidationResult(System.Web.ServicePoint sp,
System.Safety.Cryptography.X509Certificates.X509Certificates cert,
System.Web.WebRequest req, int drawback) {
return true;
}
}
}
'@
$TAResults=$Supplier.CompileAssemblyFromSource($Params,$TASource)
$TAAssembly=$TAResults.CompiledAssembly

## We now create an occasion of the TrustAll and fasten it to the ServicePointManager
$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
[System.Net.ServicePointManager]::CertificatePolicy=$TrustAll

## finish code from http://poshcode.org/624

## Set the URL of the CAS (Shopper Entry Server) to make use of two choices are availbe to make use of Autodiscover to search out the CAS URL or Hardcode the CAS to make use of

#CAS URL Possibility 1 Autodiscover
$service.AutodiscoverUrl($MailboxName,{$true})
"Using CAS Server : " + $Service.url

#CAS URL Possibility 2 Hardcoded

#$uri=[system.URI] "https://casservername/ews/exchange.asmx"
#$service.Url = $uri

## Non-obligatory part for Alternate Impersonation

#$service.ImpersonatedUserId = new-object Microsoft.Alternate.WebServices.Knowledge.ImpersonatedUserId([Microsoft.Exchange.WebServices.Data.ConnectingIdType]::SmtpAddress, $MailboxName)

operate ConvertId{
param (
$HexId = "$( throw 'HexId is a compulsory Parameter' )"
)
course of{
$aiItem = New-Object Microsoft.Alternate.WebServices.Knowledge.AlternateId
$aiItem.Mailbox = $MailboxName
$aiItem.UniqueId = $HexId
$aiItem.Format = [Microsoft.Exchange.WebServices.Data.IdFormat]::HexEntryId
$convertedId = $service.ConvertId($aiItem, [Microsoft.Exchange.WebServices.Data.IdFormat]::EwsId)
return $convertedId.UniqueId
}
}

# Bind to the Root Folder
$folderid= new-object Microsoft.Alternate.WebServices.Knowledge.FolderId([Microsoft.Exchange.WebServices.Data.WellKnownFolderName]::Root,$MailboxName)
$ClutterFolderEntryId = new-object Microsoft.Alternate.WebServices.Knowledge.ExtendedPropertyDefinition([System.Guid]::Parse("{23239608-685D-4732-9C55-4C95CB4E8E33}"), "ClutterFolderEntryId", [Microsoft.Exchange.WebServices.Data.MapiPropertyType]::Binary);
$psPropset= new-object Microsoft.Alternate.WebServices.Knowledge.PropertySet([Microsoft.Exchange.WebServices.Data.BasePropertySet]::FirstClassProperties)
$psPropset.Add($ClutterFolderEntryId)
$RootFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$folderid,$psPropset)
$FolderIdVal = $null
if ($RootFolder.TryGetProperty($ClutterFolderEntryId,[ref]$FolderIdVal))
{
$Clutterfolderid= new-object Microsoft.Alternate.WebServices.Knowledge.FolderId((ConvertId -HexId ([System.BitConverter]::ToString($FolderIdVal).Change("-",""))))
$ClutterFolder = [Microsoft.Exchange.WebServices.Data.Folder]::Bind($service,$Clutterfolderid);
"Unread Email in clutter : " + $ClutterFolder.UnreadCount
}
else{
"Clutter Folder not found"
}

Leave a Reply