none
EWS JAVA : Set senderflag (swappedToDoData) followup RRS feed

  • Question

  • Hi @ all,

    I have a problem with setting the sender flag (which will be set by PidTagSwappedToDoData). I can read the binary data from a draft mail message via PidTagSwappedToDoData, but when I try save a new mail message with a sender flag it will not be set. 

    To set the sender flag I also use the extended property PidTagSwappedToDoData, and set a byte array with 540 byte to it. Here are a example of my swappedToDoData byte array and my extended property in java:

    final ExtendedPropertyDefinition senderFollowUp = new ExtendedPropertyDefinition(0x0E2D, MapiPropertyType.Binary);
    final byte[] data = {1, 0, 0, 0, -7, 0, 0, 0, 1, 0, 0, 0, 115, 0, 101, 0, 110, 0, 100, 0, 101, 0, 114, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 32, -61, -15, 12, 32, -61, -15, 12, -28, -62, -15, 12, 1, 0, 0, 0};

    exchangeMail.setExtendedProperty(senderFollowUp, data);

    After that I save the mail to drafts:

    exchangeMail.save();

    I also try to set the swappedToDoStore property, but it doesn´t work at all. Is there any other property i have to set too? If anyone has an idea, please let me know. :)

    Thanks a lot,

    Tobi
    • Edited by TTobiasL Wednesday, November 27, 2013 1:40 PM
    Wednesday, November 27, 2013 1:33 PM

All replies

  • Are you getting any errors ?

    The sender flag should get set after you send the Message (as per http://msdn.microsoft.com/en-us/library/ee217246(v=exchg.80).aspx  so saving it shouldn't have any affect other then just setting those particular properties (the process that converts those properties to primary messages follow-up flags happens at submission). Eg the following works okay for me where the both those properties have valid data

                EmailMessage TestSenderFlag = new EmailMessage(service);
                TestSenderFlag.ToRecipients.Add("user@domain.com");
                TestSenderFlag.Subject = "test";
                TestSenderFlag.Body = new MessageBody("test");
                ExtendedPropertyDefinition PR_SWAPPED_TODO_DATA = new ExtendedPropertyDefinition(0x0E2D,MapiPropertyType.Binary);
                ExtendedPropertyDefinition PR_SWAPPED_TODO_STORE = new ExtendedPropertyDefinition(0x0E2C, MapiPropertyType.Binary);
                TestSenderFlag.SetExtendedProperty(PR_SWAPPED_TODO_DATA,HexStringToByteArray("010000007900..."));
                TestSenderFlag.SetExtendedProperty(PR_SWAPPED_TODO_STORE,HexStringToByteArray("00000000...0"));
                TestSenderFlag.SendAndSaveCopy();

    If you never sending the message that process won't happen.

    Cheers
    Glen

    Thursday, November 28, 2013 6:40 AM
  • Hi Glen,

    thank you for your reply. Yes, I know that I have to send the mail, to swap the sender flag into the primary followup properties. But that doesn´t work too. So I tried only to save a mail and check whether the sender flag will be set. :) This musst be work too, right?

    No thats the problem I dont get any errors, the new mail will be saved at the draft folder or will be send, but the sender flag (which i stored at the todo_data property) will not be stored. I only get an Exception when I try to load the todoData property from a draft message where I have stored a sender flag. Thats confusing me, and i think i am doing something wrong. Maybe the byte array of sender flag data is wrong?

    Can you send me an example for a working hexString from todoData and todoStore properties? That would be amazing. 

    Thank you,

    Tobi

    Here are my code where i get the exeption after save a mail with sender flag and then try to read it:

    exchangeMail, is the mail i have saved with sender flag to draft folder.

    final ExtendedPropertyDefinition senderFollowUp = new ExtendedPropertyDefinition(0x0E2D,
    MapiPropertyType.Binary);

    exchangeService.loadPropertiesForItem(exchangeMail, new PropertySet(senderFollowUp));

    Then I get connection not established exception. 

    Thursday, November 28, 2013 8:48 AM
  • >> Then I get connection not established exception

    That's a bug in Java API, I'm not a JAVA person so I can't help have a look other fixes people have posted http://social.msdn.microsoft.com/Forums/office/en-US/4c271609-40be-4450-ae7c-3ecff6deae87/ewsjava-identifier-converted-but-appointment-does-not-bind?forum=exchangesvrdevelopment

    To generate the correct data formats in C# this works for me

            static String GetStoreId(String emEmailAddress, ExchangeService service) {
                String rtReturnString = "";
                AutodiscoverService adAutoDiscoverService1 = new AutodiscoverService(ExchangeVersion.Exchange2010_SP2);
                adAutoDiscoverService1.Credentials = service.Credentials;
                adAutoDiscoverService1.EnableScpLookup = false;
                adAutoDiscoverService1.RedirectionUrlValidationCallback = adAutoDiscoCallBack;
                adAutoDiscoverService1.PreAuthenticate = true;
                adAutoDiscoverService1.KeepAlive = false;
                GetUserSettingsResponse adResponse = adAutoDiscoverService1.GetUserSettings(emEmailAddress, (new UserSettingName[2] { UserSettingName.UserDN, UserSettingName.InternalRpcClientServer }));
                if (adResponse.Settings.Count >= 2)
                {
                    String UserDN = (String)adResponse.Settings[UserSettingName.UserDN];
                    String ServerName = (String)adResponse.Settings[UserSettingName.InternalRpcClientServer];
                    String flags = "00000000";
                    String ProviderUID = "38A1BB1005E5101AA1BB08002B2A56C2";
                    String versionFlag = "0000";  
                    String DLLFileName = "454D534D44422E444C4C00000000";  
                    String WrappedFlags = "00000000";  
                    String WrappedProviderUID = "1B55FA20AA6611CD9BC800AA002FC45A";  
                    String WrappedType = "0C000000";
                    String StoredIdStringHex = flags + ProviderUID + versionFlag + DLLFileName + WrappedFlags + WrappedProviderUID + WrappedType + StringToHex(ServerName) + "00" + StringToHex(UserDN) + "00";
                    rtReturnString = StoredIdStringHex;
                }
                return rtReturnString;
            }
            static string StringToHex(string asciiString)
            {
                string hex = "";
                foreach (char c in asciiString)
                {
                    int tmp = c;
                    hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString()));
                }
                return hex;
            }
            static string StringToHexUnicode(string asciiString)
            {
                string hex = "";
                foreach (char c in asciiString)
                {
                    int tmp = c;
                    hex += String.Format("{0:x2}", (uint)System.Convert.ToUInt32(tmp.ToString())) + "00";
                }
                return hex;
            }
            static String GetPidTagSwappedToDoData(String FlagText) {
                String todoTimeFlagged  = "01000000";
                String PidLidFlagRequest = StringToHexUnicode(FlagText);
                //Pad Flag to 512 Bytes
                for (Int32 padCnt = PidLidFlagRequest.Length / 2; padCnt < 512; padCnt++) {
                    PidLidFlagRequest = PidLidFlagRequest + "00";
                }
    
                TimeSpan ts = new DateTime(2013,12,01,0,0,0,0,DateTimeKind.Utc) - new DateTime(1601, 1, 1, 0, 0, 0, 0, DateTimeKind.Utc);
                String HexDate = Convert.ToInt64(ts.TotalMinutes).ToString("X8");
                HexDate = HexDate.Substring(6, 2) + HexDate.Substring(4, 2) + HexDate.Substring(2, 2) + HexDate.Substring(0, 2);
                           
                String ulVersion = "01000000";
                String dwFlags = "79000000"; //dwToDoItem,rtmStartDate,rtmDueDate ,wszFlagTo ,fReminderSet 
                String dwToDoItem = todoTimeFlagged;
                String wszFlagTo = PidLidFlagRequest;
                String rtmStartDate = HexDate;
                String rtmDueDate = HexDate;
                String rtmReminder = "00000000";
                String fReminderSet = "00000000";
                return (ulVersion + dwFlags + dwToDoItem + wszFlagTo + rtmStartDate + rtmDueDate + rtmReminder + fReminderSet);
            }
    
                EmailMessage TestSenderFlag = new EmailMessage(service);
                TestSenderFlag.ToRecipients.Add("user@domain.com");
                TestSenderFlag.Subject = "test";
                TestSenderFlag.Body = new MessageBody("test");
                ExtendedPropertyDefinition PR_SWAPPED_TODO_DATA = new ExtendedPropertyDefinition(0x0E2D,MapiPropertyType.Binary);
                ExtendedPropertyDefinition PR_SWAPPED_TODO_STORE = new ExtendedPropertyDefinition(0x0E2C, MapiPropertyType.Binary);
                TestSenderFlag.SetExtendedProperty(PR_SWAPPED_TODO_DATA,HexStringToByteArray(GetPidTagSwappedToDoData("Follow this flag text")));
                TestSenderFlag.SetExtendedProperty(PR_SWAPPED_TODO_STORE,HexStringToByteArray(GetStoreId("mailbox@domain.com",service)));
                TestSenderFlag.SendAndSaveCopy();
    Cheers
    Glen
    Friday, November 29, 2013 6:24 AM