Esempio n. 1
0
        private async void cmdConnect_Click(object sender, EventArgs e)
        {
            if (!ValidateChildren(ValidationConstraints.Enabled))
            {
                return;
            }

            try
            {
                mClient.SetServer(txtHost.Text.Trim(), int.Parse(txtPort.Text), chkSSL.Checked);

                if (rdoCredNone.Checked)
                {
                    mClient.SetNoCredentials();
                }
                else
                {
                    eTLSRequirement lTLSRequirement;
                    if (rdoTLSIndifferent.Checked)
                    {
                        lTLSRequirement = eTLSRequirement.indifferent;
                    }
                    else if (rdoTLSRequired.Checked)
                    {
                        lTLSRequirement = eTLSRequirement.required;
                    }
                    else
                    {
                        lTLSRequirement = eTLSRequirement.disallowed;
                    }

                    if (rdoCredAnon.Checked)
                    {
                        mClient.SetAnonymousCredentials(txtTrace.Text.Trim(), lTLSRequirement, chkTryIfNotAdvertised.Checked);
                    }
                    else
                    {
                        mClient.SetPlainCredentials(txtUserId.Text.Trim(), txtPassword.Text.Trim(), lTLSRequirement, chkTryIfNotAdvertised.Checked);
                    }
                }

                fMailboxCacheDataItems lMailboxCacheData = 0;
                if (chkCacheSubscribed.Checked)
                {
                    lMailboxCacheData |= fMailboxCacheDataItems.subscribed;
                }
                if (chkCacheChildren.Checked)
                {
                    lMailboxCacheData |= fMailboxCacheDataItems.children;
                }
                if (chkCacheSpecialUse.Checked)
                {
                    lMailboxCacheData |= fMailboxCacheDataItems.specialuse;
                }
                if (chkCacheMessageCount.Checked)
                {
                    lMailboxCacheData |= fMailboxCacheDataItems.messagecount;
                }
                if (chkCacheRecentCount.Checked)
                {
                    lMailboxCacheData |= fMailboxCacheDataItems.recentcount;
                }
                if (chkCacheUIDNext.Checked)
                {
                    lMailboxCacheData |= fMailboxCacheDataItems.uidnext;
                }
                if (chkCacheUIDValidity.Checked)
                {
                    lMailboxCacheData |= fMailboxCacheDataItems.uidvalidity;
                }
                if (chkCacheUnseenCount.Checked)
                {
                    lMailboxCacheData |= fMailboxCacheDataItems.unseencount;
                }
                if (chkCacheHighestModSeq.Checked)
                {
                    lMailboxCacheData |= fMailboxCacheDataItems.highestmodseq;
                }

                mClient.MailboxCacheDataItems = lMailboxCacheData;

                fCapabilities lKnownCapabilities = 0;

                if (chkIgnoreStartTLS.Checked)
                {
                    lKnownCapabilities |= fCapabilities.starttls;
                }
                if (chkIgnoreEnable.Checked)
                {
                    lKnownCapabilities |= fCapabilities.enable;
                }
                if (chkIgnoreUTF8.Checked)
                {
                    lKnownCapabilities |= fCapabilities.utf8accept | fCapabilities.utf8only;
                }
                if (chkIgnoreId.Checked)
                {
                    lKnownCapabilities |= fCapabilities.id;
                }
                if (chkIgnoreNamespace.Checked)
                {
                    lKnownCapabilities |= fCapabilities.namespaces;
                }

                if (chkIgnoreMailboxReferrals.Checked)
                {
                    lKnownCapabilities |= fCapabilities.mailboxreferrals;
                }
                if (chkIgnoreListExtended.Checked)
                {
                    lKnownCapabilities |= fCapabilities.listextended;
                }
                if (chkIgnoreListStatus.Checked)
                {
                    lKnownCapabilities |= fCapabilities.liststatus;
                }
                if (chkIgnoreSpecialUse.Checked)
                {
                    lKnownCapabilities |= fCapabilities.specialuse;
                }

                if (chkIgnoreCondStore.Checked)
                {
                    lKnownCapabilities |= fCapabilities.condstore;
                }
                if (chkIgnoreQResync.Checked)
                {
                    lKnownCapabilities |= fCapabilities.qresync;
                }

                if (chkIgnoreLiteralPlus.Checked)
                {
                    lKnownCapabilities |= fCapabilities.literalplus | fCapabilities.literalminus;
                }
                if (chkIgnoreBinary.Checked)
                {
                    lKnownCapabilities |= fCapabilities.binary;
                }
                if (chkIgnoreIdle.Checked)
                {
                    lKnownCapabilities |= fCapabilities.idle;
                }
                if (chkIgnoreSASLIR.Checked)
                {
                    lKnownCapabilities |= fCapabilities.sasl_ir;
                }

                if (chkIgnoreESearch.Checked)
                {
                    lKnownCapabilities |= fCapabilities.esearch;
                }
                if (chkIgnoreSort.Checked)
                {
                    lKnownCapabilities |= fCapabilities.sort;
                }
                if (chkIgnoreSortDisplay.Checked)
                {
                    lKnownCapabilities |= fCapabilities.sortdisplay;
                }
                //if (chkIgnoreThreadOrderedSubject.Checked) lKnownCapabilities |= fCapabilities.threadorderedsubject;
                //if (chkIgnoreThreadReferences.Checked) lKnownCapabilities |= fCapabilities.threadreferences;
                if (chkIgnoreESort.Checked)
                {
                    lKnownCapabilities |= fCapabilities.esort;
                }

                mClient.IgnoreCapabilities = lKnownCapabilities;

                mClient.MailboxReferrals = chkMailboxReferrals.Checked;

                mClient.NetworkWriteConfiguration = new cBatchSizerConfiguration(int.Parse(txtNWMin.Text), int.Parse(txtNWMax.Text), int.Parse(txtNWMaxTime.Text), int.Parse(txtNWInitial.Text));

                await mClient.ConnectAsync();
            }
            catch (Exception ex)
            {
                if (!IsDisposed)
                {
                    MessageBox.Show(this, $"Connect error\n{ex}");
                }
            }
        }