예제 #1
0
파일: create.cs 프로젝트: bacome/imapclient
        private async Task <cMailbox> ZCreateAsync(cMailboxName pMailboxName, bool pAsFutureParent, cTrace.cContext pParentContext)
        {
            var lContext = pParentContext.NewMethod(nameof(cIMAPClient), nameof(ZCreateAsync), pMailboxName, pAsFutureParent);

            if (mDisposed)
            {
                throw new ObjectDisposedException(nameof(cIMAPClient));
            }

            var lSession = mSession;

            if (lSession == null || !lSession.IsConnected)
            {
                throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotConnected);
            }

            if (pMailboxName == null)
            {
                throw new ArgumentNullException(nameof(pMailboxName));
            }

            using (var lToken = mCancellationManager.GetToken(lContext))
            {
                var lMC            = new cMethodControl(mTimeout, lToken.CancellationToken);
                var lMailboxHandle = await lSession.CreateAsync(lMC, pMailboxName, pAsFutureParent, lContext).ConfigureAwait(false);

                return(new cMailbox(this, lMailboxHandle));
            }
        }
예제 #2
0
파일: create.cs 프로젝트: bacome/imapclient
        /// <summary>
        /// Creates a new mailbox on the connected server.
        /// </summary>
        /// <param name="pMailboxName">The mailbox name to use.</param>
        /// <param name="pAsFutureParent">Indicates to the server that you intend to create child mailboxes in the new mailbox.</param>
        /// <returns></returns>
        /// <remarks>
        /// <para>
        /// Some servers exhibit unusual behaviour when the mailbox name includes 'unusual' characters (e.g. '/' when it isn't the delimiter).
        /// Observed behaviours are;
        /// <list type="bullet">
        /// An <item>'OK' reply, but the mailbox created has a truncated name.</item>
        /// </list>
        /// </para>
        /// <para>
        /// Some servers exhibit unusual behaviour when <paramref name="pAsFutureParent"/> is <see langword="true"/> despite this appearing to be in violation of RFC 3501 section 6.3.3.
        /// Observed behaviours are;
        /// <list type="bullet">
        /// <item>An 'OK' reply and a mailbox created with the name specified (correct behaviour according to RFC 3501).</item>
        /// <item>A 'NO' reply and no mailbox created.</item>
        /// <item>An 'OK [CANNOT]' reply and no mailbox created.</item>
        /// <item>An 'OK' reply and a mailbox created with the name specified, but the mailbox has the \NoSelect flag set (so the mailbox can't be used to store messages).</item>
        /// </list>
        /// </para>
        /// </remarks>
        public cMailbox Create(cMailboxName pMailboxName, bool pAsFutureParent = false)
        {
            var lContext = mRootContext.NewMethod(nameof(cIMAPClient), nameof(Create));
            var lTask    = ZCreateAsync(pMailboxName, pAsFutureParent, lContext);

            mSynchroniser.Wait(lTask, lContext);
            return(lTask.Result);
        }
예제 #3
0
                public iMailboxHandle Create(cMailboxName pMailboxName, cTrace.cContext pParentContext)
                {
                    var lContext = pParentContext.NewMethod(nameof(cMailboxCache), nameof(Create), pMailboxName);
                    var lItem    = ZItem(pMailboxName);

                    lItem.SetJustCreated(lContext);
                    return(lItem);
                }
예제 #4
0
파일: base.cs 프로젝트: bacome/imapclient
 public iMailboxHandle GetMailboxHandle(cMailboxName pMailboxName)
 {
     if (mMailboxCache == null)
     {
         throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotEnabled);
     }
     return(mMailboxCache.GetHandle(pMailboxName));
 }
예제 #5
0
파일: rename.cs 프로젝트: bacome/imapclient
        internal cMailbox Rename(iMailboxHandle pMailboxHandle, cMailboxName pMailboxName)
        {
            var lContext = mRootContext.NewMethod(nameof(cIMAPClient), nameof(Rename));
            var lTask    = ZRenameAsync(pMailboxHandle, pMailboxName, lContext);

            mSynchroniser.Wait(lTask, lContext);
            return(lTask.Result);
        }
예제 #6
0
                private cMailboxCacheItem ZItem(cMailboxName pMailboxName)
                {
                    if (pMailboxName == null)
                    {
                        throw new ArgumentNullException(nameof(pMailboxName));
                    }
                    if (!mCommandPartFactory.TryAsMailbox(pMailboxName.Path, pMailboxName.Delimiter, out var lCommandPart, out var lEncodedMailboxPath))
                    {
                        throw new ArgumentOutOfRangeException(nameof(pMailboxName));
                    }
                    var lItem = mDictionary.GetOrAdd(lEncodedMailboxPath, new cMailboxCacheItem(mSynchroniser, this, lEncodedMailboxPath));

                    lItem.MailboxName            = pMailboxName;
                    lItem.MailboxNameCommandPart = lCommandPart;
                    return(lItem);
                }
예제 #7
0
                public List <iMailboxHandle> GetHandles(List <cMailboxName> pMailboxNames)
                {
                    if (pMailboxNames == null)
                    {
                        return(null);
                    }

                    List <iMailboxHandle> lMailboxHandles = new List <iMailboxHandle>();

                    pMailboxNames.Sort();

                    cMailboxName lLastMailboxName = null;

                    foreach (var lMailboxName in pMailboxNames)
                    {
                        if (lMailboxName != lLastMailboxName)
                        {
                            lMailboxHandles.Add(ZItem(lMailboxName));
                            lLastMailboxName = lMailboxName;
                        }
                    }

                    return(lMailboxHandles);
                }
예제 #8
0
 public cResponseDataListMailbox(cMailboxName pMailboxName, fListFlags pFlags, bool pHasSubscribedChildren)
 {
     MailboxName           = pMailboxName;
     Flags                 = pFlags;
     HasSubscribedChildren = pHasSubscribedChildren;
 }
예제 #9
0
파일: create.cs 프로젝트: bacome/imapclient
        /// <summary>
        /// Ansynchronously creates a new mailbox on the connected server.
        /// </summary>
        /// <param name="pMailboxName">The mailbox name to use.</param>
        /// <param name="pAsFutureParent">Indicates to the server that you intend to create child mailboxes in the new mailbox.</param>
        /// <returns></returns>
        /// <inheritdoc cref="Create(cMailboxName, bool)" select="remarks"/>
        public Task <cMailbox> CreateAsync(cMailboxName pMailboxName, bool pAsFutureParent = false)
        {
            var lContext = mRootContext.NewMethod(nameof(cIMAPClient), nameof(CreateAsync));

            return(ZCreateAsync(pMailboxName, pAsFutureParent, lContext));
        }
예제 #10
0
파일: rename.cs 프로젝트: bacome/imapclient
        internal Task <cMailbox> RenameAsync(iMailboxHandle pMailboxHandle, cMailboxName pMailboxName)
        {
            var lContext = mRootContext.NewMethod(nameof(cIMAPClient), nameof(RenameAsync));

            return(ZRenameAsync(pMailboxHandle, pMailboxName, lContext));
        }
예제 #11
0
 public cRenameCommandHook(cMailboxCache pCache, cMailboxCacheItem pItem, cMailboxName pMailboxName)
 {
     mCache       = pCache ?? throw new ArgumentNullException(nameof(pCache));
     mItem        = pItem; // may be null if we are renaming the inbox
     mMailboxName = pMailboxName ?? throw new ArgumentNullException(nameof(pMailboxName));
 }
예제 #12
0
            public async Task <iMailboxHandle> RenameAsync(cMethodControl pMC, iMailboxHandle pMailboxHandle, cMailboxName pMailboxName, cTrace.cContext pParentContext)
            {
                var lContext = pParentContext.NewMethod(nameof(cSession), nameof(RenameAsync), pMC, pMailboxHandle, pMailboxName);

                if (mDisposed)
                {
                    throw new ObjectDisposedException(nameof(cSession));
                }
                if (_ConnectionState != eConnectionState.notselected && _ConnectionState != eConnectionState.selected)
                {
                    throw new InvalidOperationException(kInvalidOperationExceptionMessage.NotConnected);
                }
                if (pMailboxHandle == null)
                {
                    throw new ArgumentNullException(nameof(pMailboxHandle));
                }
                if (pMailboxName == null)
                {
                    throw new ArgumentNullException(nameof(pMailboxName));
                }

                var lItem = mMailboxCache.CheckHandle(pMailboxHandle);

                if (!mCommandPartFactory.TryAsMailbox(pMailboxName.Path, pMailboxName.Delimiter, out var lMailboxCommandPart, out _))
                {
                    throw new ArgumentOutOfRangeException(nameof(pMailboxName));
                }

                using (var lBuilder = new cCommandDetailsBuilder())
                {
                    if (!_Capabilities.QResync)
                    {
                        lBuilder.Add(await mSelectExclusiveAccess.GetBlockAsync(pMC, lContext).ConfigureAwait(false)); // block select if mailbox-data delivered during the command would be ambiguous
                    }
                    lBuilder.Add(await mMSNUnsafeBlock.GetBlockAsync(pMC, lContext).ConfigureAwait(false));            // this command is msnunsafe

                    lBuilder.Add(kRenameCommandPart, lItem.MailboxNameCommandPart, cCommandPart.Space, lMailboxCommandPart);

                    if (pMailboxHandle.MailboxName.IsInbox)
                    {
                        lItem = null;                                     // renaming the inbox has special behaviour
                    }
                    var lHook = new cRenameCommandHook(mMailboxCache, lItem, pMailboxName);
                    lBuilder.Add(lHook);

                    var lResult = await mPipeline.ExecuteAsync(pMC, lBuilder.EmitCommandDetails(), lContext).ConfigureAwait(false);

                    if (lResult.ResultType == eCommandResultType.ok)
                    {
                        lContext.TraceInformation("rename success");
                        return(lHook.MailboxHandle);
                    }

                    if (lResult.ResultType == eCommandResultType.no)
                    {
                        throw new cUnsuccessfulCompletionException(lResult.ResponseText, 0, lContext);
                    }
                    throw new cProtocolErrorException(lResult, 0, lContext);
                }
            }
예제 #13
0
 public iMailboxHandle GetHandle(cMailboxName pMailboxName) => ZItem(pMailboxName);
예제 #14
0
파일: lsub.cs 프로젝트: bacome/imapclient
 public cResponseDataLSub(cMailboxName pMailboxName, bool pSubscribed)
 {
     MailboxName = pMailboxName;
     Subscribed  = pSubscribed;
 }
예제 #15
0
파일: create.cs 프로젝트: bacome/imapclient
 public cCreateCommandHook(cMailboxCache pCache, cMailboxName pMailboxName)
 {
     mCache       = pCache ?? throw new ArgumentNullException(nameof(pCache));
     mMailboxName = pMailboxName ?? throw new ArgumentNullException(nameof(pMailboxName));
 }