private void EditMailbox(string userPrincipalName, string mailboxPlanName)
        {
            // Hide all panels except edit panel
            panelDisableMailbox.Visible = false;
            panelEnableUsers.Visible = false;
            panelMailboxes.Visible = false;

            // Show edit panel
            panelEditMailbox.Visible = true;

            // Now get the mailbox information
            ExchCmds powershell = null;
            try
            {
                // Refresh plans again otherwise the jQuery won't work
                GetMailboxPlans();

                // Get list of forwarding addresses
                GetForwardingAddresses();

                // Initilize 
                powershell = new ExchCmds(Config.ExchangeURI, Config.Username, Config.Password, Config.ExchangeConnectionType, Config.PrimaryDC);

                // Get user object
                MailboxUser user = powershell.Get_Mailbox(userPrincipalName);

                // Set plan information
                logger.DebugFormat("Setting mailbox plan...");
                ddlEditMailboxPlan.SelectedIndex = ddlEditMailboxPlan.Items.IndexOf(ddlEditMailboxPlan.Items.FindByText(mailboxPlanName));

                // Populate information
                logger.DebugFormat("Setting mailbox plan...");
                hfUserPrincipalName.Value = userPrincipalName;
                hfDistinguishedName.Value = user.DistinguishedName;
                txtDisplayName.Text = user.DisplayName;
                txtEditPrimaryEmail.Text = user.PrimarySmtpAddress.Split('@')[0];
                ddlEditPrimaryEmailDomain.SelectedValue = user.PrimarySmtpAddress.Split('@')[1];
                cbDeliverToMailboxAndFoward.Checked = user.DeliverToMailboxAndForward;

                // Get activesync policy
                logger.DebugFormat("Checking for activesync policy");
                if (string.IsNullOrEmpty(user.ActiveSyncMailboxPolicy))
                    ddlActiveSyncPlanEditMailbox.SelectedIndex = 0;
                else
                {
                    ListItem item = ddlActiveSyncPlanEditMailbox.Items.FindByText(user.ActiveSyncMailboxPolicy);
                    if (item != null)
                        ddlActiveSyncPlanEditMailbox.SelectedIndex = ddlActiveSyncPlanEditMailbox.Items.IndexOf(item);
                    else
                        ddlActiveSyncPlanEditMailbox.SelectedIndex = 0;
                }

                //
                // Populate any forwarding address
                //
                logger.DebugFormat("Checking for forwarding address");
                if (!string.IsNullOrEmpty(user.ForwardingAddress))
                {
                    logger.DebugFormat("Forwarding address is {0}", user.ForwardingAddress);
                    string upper = user.ForwardingAddress.ToUpper();

                    var item = ddlForwardTo.Items.Cast<ListItem>().Where(i => i.Value.ToUpper() == upper).FirstOrDefault();
                    if (item != null)
                        ddlForwardTo.SelectedValue = item.Value;
                }
                else
                    ddlForwardTo.SelectedIndex = 0;

                // Set current mailbox size
                currentMailboxSize = user.MailboxSizeInMB;

                //
                // Set the email aliases
                //
                txtAddEmailAlias.Text = string.Empty;
                emailAliases = new List<BaseEmailAliases>();
                if (user.EmailAliases != null)
                {
                    foreach (string email in user.EmailAliases)
                    {
                        emailAliases.Add(new BaseEmailAliases() { emailAddress = email });
                    }
                }

                // Add to ViewState
                ViewState["CPEmailAliases"] = emailAliases;


                //
                // Populate the mailbox permissions for FullAccess
                //
                hfFullAccessOriginal.Value = string.Empty;
                foreach (MailboxPermissions m in user.FullAccessPermissions)
                {
                    ListItem item = lstFullAccessPermissions.Items.FindByValue(m.SamAccountName);
                    if (item != null)
                    {
                        int index = lstFullAccessPermissions.Items.IndexOf(item);
                        lstFullAccessPermissions.Items[index].Selected = true;

                        // Add to our hidden value field for a list of original values
                        hfFullAccessOriginal.Value += m.SamAccountName + ",";
                    }
                }
                this.logger.Debug("Full access permissions for " + user.UserPrincipalName + " when loaded is: " + hfFullAccessOriginal.Value);

                //
                // Populate the mailbox permissions for SendAs
                //
                hfSendAsOriginal.Value = string.Empty;
                foreach (MailboxPermissions m in user.SendAsPermissions)
                {
                    ListItem item = lstSendAsPermissions.Items.FindByValue(m.SamAccountName);
                    if (item != null)
                    {
                        int index = lstSendAsPermissions.Items.IndexOf(item);
                        lstSendAsPermissions.Items[index].Selected = true;

                        // Add to our hidden value field for a list of original values
                        hfSendAsOriginal.Value += m.SamAccountName + ",";
                    }
                }
                this.logger.Debug("Send-As permissions for " + user.UserPrincipalName + " when loaded is: " + hfSendAsOriginal.Value);

                // Bind gridview
                gridEmailAliases.DataSource = emailAliases;
                gridEmailAliases.DataBind();
            }
            catch (Exception ex)
            {
                notification1.SetMessage(controls.notification.MessageType.Error, ex.ToString());

                // Reset view
                GetMailboxUsers();
            }
            finally
            {
                if (powershell != null)
                    powershell.Dispose();
            }
        }