예제 #1
0
        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);
            }
        }
예제 #2
0
        public PreFormActionResponse Execute(OwaContext owaContext, out ApplicationElement applicationElement, out string type, out string state, out string action)
        {
            if (owaContext == null)
            {
                throw new ArgumentNullException("owaContext");
            }
            HttpContext httpContext = owaContext.HttpContext;
            UserContext userContext = owaContext.UserContext;
            HttpRequest request     = httpContext.Request;

            applicationElement = ApplicationElement.Item;
            type   = string.Empty;
            action = string.Empty;
            state  = string.Empty;
            if (!Utilities.IsPostRequest(request))
            {
                return(userContext.LastClientViewState.ToPreFormActionResponse());
            }
            PreFormActionResponse preFormActionResponse = new PreFormActionResponse();

            if (owaContext.FormsRegistryContext.Action == null)
            {
                throw new OwaInvalidRequestException("Action is missing");
            }
            string        formParameter = Utilities.GetFormParameter(request, "hidid", true);
            StoreObjectId storeObjectId = Utilities.CreateStoreObjectId(userContext.MailboxSession, formParameter);
            string        action2;

            if ((action2 = owaContext.FormsRegistryContext.Action) != null)
            {
                if (!(action2 == "Mail"))
                {
                    if (!(action2 == "MeetingRequest"))
                    {
                        if (action2 == "Delete")
                        {
                            goto IL_1E9;
                        }
                        if (!(action2 == "AddRcpt"))
                        {
                            goto IL_33E;
                        }
                        AddressBook.Mode mode = AddressBookHelper.TryReadAddressBookMode(request, AddressBook.Mode.None);
                        if (mode != AddressBook.Mode.EditMessage && mode != AddressBook.Mode.EditMeetingResponse && mode != AddressBook.Mode.EditCalendar)
                        {
                            throw new OwaInvalidRequestException("Not in edit mode");
                        }
                        string        queryStringParameter = Utilities.GetQueryStringParameter(request, "id", false);
                        StoreObjectId itemId = null;
                        if (!string.IsNullOrEmpty(queryStringParameter))
                        {
                            itemId = Utilities.CreateStoreObjectId(userContext.MailboxSession, queryStringParameter);
                        }
                        string            queryStringParameter2 = Utilities.GetQueryStringParameter(request, "chk", false);
                        RecipientItemType type2 = (RecipientItemType)RequestParser.TryGetIntValueFromQueryString(request, "rw", 1);
                        using (Item item = AddressBookHelper.GetItem(userContext, mode, itemId, queryStringParameter2))
                        {
                            Participant participant = Utilities.CreateParticipantFromQueryString(userContext, request);
                            if (participant != null)
                            {
                                AddressBookHelper.AddParticipantToItem(item, type2, participant);
                                CalendarItemBase calendarItemBase = item as CalendarItemBase;
                                if (calendarItemBase != null)
                                {
                                    EditCalendarItemHelper.CreateUserContextData(userContext, calendarItemBase);
                                }
                                else if (item is MessageItem)
                                {
                                    AddressBookHelper.SaveItem(item);
                                }
                            }
                            return(AddressBookHelper.RedirectToEdit(userContext, item, mode));
                        }
                        goto IL_33E;
                    }
                }
                else
                {
                    using (MessageItem messageItem = MessageItem.Create(userContext.MailboxSession, userContext.DraftsFolderId))
                    {
                        messageItem[ItemSchema.ConversationIndexTracking] = true;
                        AddressBookHelper.AddContactsToDraft(messageItem, RecipientItemType.To, userContext, new string[]
                        {
                            storeObjectId.ToBase64String()
                        });
                        preFormActionResponse.AddParameter("id", messageItem.Id.ObjectId.ToBase64String());
                        preFormActionResponse.ApplicationElement = ApplicationElement.Item;
                        preFormActionResponse.Type   = "IPM.Note";
                        preFormActionResponse.Action = "Open";
                        preFormActionResponse.State  = "Draft";
                        return(preFormActionResponse);
                    }
                }
                using (CalendarItemBase calendarItemBase2 = EditCalendarItemHelper.CreateDraft(userContext, userContext.CalendarFolderId))
                {
                    calendarItemBase2.IsMeeting = true;
                    AddressBookHelper.AddContactsToDraft(calendarItemBase2, RecipientItemType.To, userContext, new string[]
                    {
                        storeObjectId.ToBase64String()
                    });
                    preFormActionResponse.Action             = "Open";
                    preFormActionResponse.ApplicationElement = ApplicationElement.Item;
                    preFormActionResponse.Type = calendarItemBase2.ClassName;
                    EditCalendarItemHelper.CreateUserContextData(userContext, calendarItemBase2);
                    return(preFormActionResponse);
                }
IL_1E9:
                string formParameter2 = Utilities.GetFormParameter(request, "hidcmdpst", true);
                if (formParameter2 == "d")
                {
                    Utilities.DeleteItems(userContext, DeleteItemFlags.SoftDelete, new StoreId[]
                    {
                        storeObjectId
                    });
                }
                else
                {
                    if (!(formParameter2 == "m"))
                    {
                        throw new OwaInvalidRequestException("Unknown delete command");
                    }
                    Utilities.DeleteItems(userContext, DeleteItemFlags.MoveToDeletedItems, new StoreId[]
                    {
                        storeObjectId
                    });
                }
                userContext.ForceNewSearch = true;
                preFormActionResponse      = userContext.LastClientViewState.ToPreFormActionResponse();
                return(preFormActionResponse);
            }
IL_33E:
            throw new OwaInvalidRequestException("Invalid action for readcontact preformaction");
        }
예제 #3
0
        public static void AddRecipientsToDraft(string[] ids, Item draft, RecipientItemType type, UserContext userContext)
        {
            if (draft == null)
            {
                throw new ArgumentNullException("draft");
            }
            MessageItem      messageItem      = draft as MessageItem;
            CalendarItemBase calendarItemBase = draft as CalendarItemBase;

            if (messageItem == null && calendarItemBase == null)
            {
                throw new ArgumentException("The draft should be a MessageItem or a CalendarItemBase while it is now a " + draft.GetType().Name);
            }
            if (userContext == null)
            {
                throw new ArgumentNullException("usercontext");
            }
            if (ids == null || ids.Length == 0)
            {
                throw new ArgumentException("ids is null or empty.", "ids");
            }
            IRecipientSession recipientSession = Utilities.CreateADRecipientSession(ConsistencyMode.IgnoreInvalid, userContext);
            SortBy            sortBy           = new SortBy(ADRecipientSchema.DisplayName, SortOrder.Descending);
            RecipientCache    recipientCache   = AutoCompleteCache.TryGetCache(OwaContext.Current.UserContext);

            for (int i = 0; i < ids.Length; i++)
            {
                Guid          guidFromBase64String = Utilities.GetGuidFromBase64String(ids[i]);
                QueryFilter   filter = new ComparisonFilter(ComparisonOperator.Equal, ADObjectSchema.Guid, guidFromBase64String);
                ADRecipient[] array  = recipientSession.Find(null, QueryScope.SubTree, filter, sortBy, 1);
                if (array != null && array.Length != 0)
                {
                    Participant participant = new Participant(array[0]);
                    if (participant != null)
                    {
                        AddressBookHelper.AddParticipantToItem(draft, type, participant);
                        int recipientFlags = 0;
                        if (draft is CalendarItem && DirectoryAssistance.IsADRecipientRoom(array[0]))
                        {
                            recipientFlags = 2;
                        }
                        if (recipientCache != null && userContext.UserOptions.AddRecipientsToAutoCompleteCache)
                        {
                            string participantProperty = Utilities.GetParticipantProperty <string>(participant, ParticipantSchema.SmtpAddress, null);
                            recipientCache.AddEntry(array[0].DisplayName, participantProperty, array[0].LegacyExchangeDN, string.Empty, "EX", AddressOrigin.Directory, recipientFlags, null, EmailAddressIndex.None);
                        }
                    }
                }
            }
            if (recipientCache != null && recipientCache.IsDirty)
            {
                recipientCache.Commit(true);
            }
            if (messageItem != null)
            {
                AddressBookHelper.SaveItem(draft);
                return;
            }
            if (calendarItemBase != null)
            {
                EditCalendarItemHelper.CreateUserContextData(userContext, calendarItemBase);
            }
        }