Beispiel #1
0
        /// <summary>
        /// Sets the supplied e-mail address to be the primary e-mail address for receiving mail.
        /// Note: This e-mail address must already be associated with the account.
        /// If there is account currently has a primary e-mail address, it will be set as a secondary.
        /// </summary>
        /// <param name="emailAddress">The e-mail address to make primary.</param>
        /// <returns>Returns true if the e-mail address was made the primary, false if the e-mail address supplied was not already associated with the account,
        /// or the address could not be made primary for any reason.</returns>
        public bool SetPrimaryProxyAddress(string emailAddress)
        {
            // Check if an e-mail address was supplied.
            if (!string.IsNullOrWhiteSpace(emailAddress))
            {
                // An e-mail address was supplied.
                // Check if the e-mail is already associated with the account.
                if (EmailAddresses.Contains(emailAddress))
                {
                    // The e-mail address is associated with the account.
                    // Get the current primary address (if there is one).
                    string currentPrimary = PrimaryEmailAddress;

                    // Check that a current primary address was retrieved.
                    if (!string.IsNullOrWhiteSpace(currentPrimary))
                    {
                        // The current primary address was retrieved.
                        // Remove the current primary address from the account.
                        if (RemoveProxyAddress(currentPrimary))
                        {
                            // The primary was removed.
                            // Add the primary back as a normal e-mail address.
                            if (!AddProxyAddress(currentPrimary))
                            {
                                // There was an error adding the primary back.
                                return(false);
                            }
                        }
                    }

                    // Remove the e-mail address to promote it to primary.
                    if (RemoveProxyAddress(emailAddress))
                    {
                        // The address was removed.
                        // Add the e-mail address back as the primary.
                        return(AddProxyAddress(emailAddress, true));
                    }
                }
            }
            // An e-mail address was not supplied or there was an error setting the primary address.
            return(false);
        }