none
EWS deleting custom categories RRS feed

  • Question

  • Hello,

    I have written a small app that allows a member of support to change the outlook delegate of a specified user by mereley entering the smtp address.  All was fine, so I thought till we changed the delegate for one of our board members.  The delegate changed but all the custom categories were deleted. 

    Is there a way to prevent this from happening?

    namespace Delegates
    {
        public class Program
        {
    
            public static void Main()
            {
                Console.WriteLine("You are adding delegate permissions");
                Console.WriteLine();
                Console.WriteLine("Please enter the board member's email address:");
                var ownerUser = Console.ReadLine();
    
                Console.WriteLine("Please enter the PA's email address:");
                var delegateUser = Console.ReadLine();
    
                Console.WriteLine("Attempting to add '{0}' as a delegate for '{1}'", delegateUser, ownerUser);
    
                // Bind to the service by using the primary e-mail address credentials.
                ExchangeService service = new ExchangeService(ExchangeVersion.Exchange2010_SP1);
                service.Url = new Uri("https://p-slo-mail2010.aspectcapital.com/EWS/Exchange.asmx/");
                service.UseDefaultCredentials = true;
                service.ImpersonatedUserId = new ImpersonatedUserId(ConnectingIdType.SmtpAddress, ownerUser);
                //service.Credentials = new NetworkCredential(adminUsername, adminPassword, "ASPECT");
                try
                {
                    service.AutodiscoverUrl(ownerUser);
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex);
                }
                DelegateUser newDelegate1 = new DelegateUser(delegateUser);
                
    
                newDelegate1.Permissions.CalendarFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
                newDelegate1.Permissions.InboxFolderPermissionLevel = DelegateFolderPermissionLevel.Editor;
                newDelegate1.ReceiveCopiesOfMeetingMessages = true;
    
                Mailbox mailbox1 = new Mailbox(ownerUser);
    
                List<UserId> remove = new List<UserId>();
    
                DelegateInformation result1 = service.GetDelegates(mailbox1, true);
    
                if (result1.DelegateUserResponses.Count > 0)
                {
                    foreach (DelegateUserResponse delegateUserResponse in result1.DelegateUserResponses)
                    {
                        remove.Add(delegateUserResponse.DelegateUser.UserId);
    
                    }
    
                    Collection<DelegateUserResponse> response = service.RemoveDelegates(mailbox1, remove);
                }
                
                var resp = service.AddDelegates(mailbox1, MeetingRequestsDeliveryScope.DelegatesAndMe, newDelegate1);
    
                if (resp.Any(r => r.Result != ServiceResult.Success))
                {
                    Console.WriteLine("Problem adding delegate");
                }
    
                Collection<DelegateUserResponse> result2 = service.UpdateDelegates(mailbox1, MeetingRequestsDeliveryScope.DelegatesAndMe, newDelegate1);
    
                if (result2.Any(r => r.Result != ServiceResult.Success))
                {
                    Console.WriteLine("Problem setting delegate permissions");
                }
    
            }
        }
    }


    Kind Regards djsd


    • Edited by djsd Wednesday, August 7, 2013 11:09 AM
    Wednesday, August 7, 2013 11:04 AM

Answers

  • The Master categories list is unrelated the delegates code, do you have code that also updates the categories list ? if so that's where your issue maybe if its corrupting the property etc. Other things like someone running /cleancategories against the outlook profile would clear them as well.

    If its some type of bug you should be able to reproduce it, you can try enable auditing on the Exchange server but I don't think that will tell you much. You might want to look at the Master Category List object in a MAPI editor like OutlookSpy of MFCMapi http://blogs.technet.com/b/outlooking/archive/2010/05/14/useful-tools-while-troubleshooting-outlook-issues-3-mfcmapi.aspx and have a look at the creationDate, LastModificationTime to see if they correspond with the time you ran/run your code.

    Cheers
    Glen

    • Marked as answer by djsd Thursday, August 29, 2013 7:42 PM
    Friday, August 9, 2013 7:13 AM

All replies

  • What do you mean by custom Categories are you talking about the Master categories list or categories that have been set on particular items ?

    Setting the Delegate has nothing to do with Custom categories its more likely some other action has caused this to happen.  

    The Master Categories list is stored in an FAI item in the Mailbox and the individual Categories are all stored on particular items in the Keywords property.

    The only thing setting the Delegates does is enable a Meeting forward rule, if you also had a clear categories rule enabled that modification could have been triggered that rule to run but I've never heard of it happening especially against existing items. Can you reproduce the effect on another mailbox ?

    Cheers
    Glen

    Thursday, August 8, 2013 5:25 AM
  • Hi There Glen,

    Yes the Master category list.  The Board members have customised lists e.g. added\removed categories on the master list.  This helps the PAs manage their calendars.

    I was suprised when this happened. It seemed like the only explanation. Since the Board member was out of office and I changed his delegate just to test the that the application worked.

    I have tried to re-produce this on a non Board mailbox and the categories have stayed intact.  Thanks for suggesting that. Although I am still stumped as to what happened.

    Any ideas??  Would logging everything the application does help? 

    I am new to .NET and developing in general but this code which was sound when debugging is very sporadic. 


    Kind Regards djsd

    Friday, August 9, 2013 6:55 AM
  • The Master categories list is unrelated the delegates code, do you have code that also updates the categories list ? if so that's where your issue maybe if its corrupting the property etc. Other things like someone running /cleancategories against the outlook profile would clear them as well.

    If its some type of bug you should be able to reproduce it, you can try enable auditing on the Exchange server but I don't think that will tell you much. You might want to look at the Master Category List object in a MAPI editor like OutlookSpy of MFCMapi http://blogs.technet.com/b/outlooking/archive/2010/05/14/useful-tools-while-troubleshooting-outlook-issues-3-mfcmapi.aspx and have a look at the creationDate, LastModificationTime to see if they correspond with the time you ran/run your code.

    Cheers
    Glen

    • Marked as answer by djsd Thursday, August 29, 2013 7:42 PM
    Friday, August 9, 2013 7:13 AM
  • Nope.  No code for categories.  The code above is the entirety of the console application.  I will have a look at the board category list as suggested.  Thanks for your input.

    Kind Regards djsd

    Friday, August 9, 2013 7:49 AM