public static void AddContactsToDraft(Item draft, RecipientItemType type, UserContext userContext, params string[] ids) { if (draft == null) { throw new ArgumentNullException("draft"); } if (userContext == null) { throw new ArgumentNullException("usercontext"); } if (ids == null || ids.Length == 0) { throw new ArgumentException("ids is null or empty.", "ids"); } Participant participant = null; RecipientCache recipientCache = AutoCompleteCache.TryGetCache(OwaContext.Current.UserContext); int i = 0; while (i < ids.Length) { StoreObjectId storeObjectId = Utilities.CreateStoreObjectId(userContext.MailboxSession, ids[i]); if (storeObjectId.ObjectType == StoreObjectType.DistributionList) { using (DistributionList item = Utilities.GetItem <DistributionList>(userContext, storeObjectId, new PropertyDefinition[] { StoreObjectSchema.DisplayName })) { participant = item.GetAsParticipant(); goto IL_113; } goto IL_9B; } goto IL_9B; IL_113: if (participant != null) { if (recipientCache != null && userContext.UserOptions.AddRecipientsToAutoCompleteCache) { string participantProperty = Utilities.GetParticipantProperty <string>(participant, ParticipantSchema.SmtpAddress, null); recipientCache.AddEntry(participant.DisplayName, participantProperty, participant.EmailAddress, string.Empty, participant.RoutingType, AddressOrigin.Store, 0, storeObjectId.ToBase64String(), ((StoreParticipantOrigin)participant.Origin).EmailAddressIndex); } AddressBookHelper.AddParticipantToItem(draft, type, participant); participant = null; } i++; continue; IL_9B: using (Contact item2 = Utilities.GetItem <Contact>(userContext, storeObjectId, AddressBookHelper.contactsProperties)) { foreach (KeyValuePair <EmailAddressIndex, Participant> keyValuePair in item2.EmailAddresses) { if (keyValuePair.Value != null && !string.IsNullOrEmpty(keyValuePair.Value.EmailAddress)) { participant = keyValuePair.Value; break; } } } goto IL_113; } if (recipientCache != null && recipientCache.IsDirty) { recipientCache.Commit(true); } CalendarItemBase calendarItemBase = draft as CalendarItemBase; if (calendarItemBase != null) { EditCalendarItemHelper.CreateUserContextData(userContext, calendarItemBase); return; } if (draft is MessageItem) { AddressBookHelper.SaveItem(draft); } }