MailKit.Net.Imap.ImapCommandException.Create C# (CSharp) Метод

Create() статический приватный Метод

Create a new ImapCommandException based on the specified command name and ImapCommand state.
Create a new ImapCommandException based on the specified command name and ImapCommand state.
static private Create ( string command, ImapCommand ic ) : ImapCommandException
command string The command name.
ic ImapCommand The command state.
Результат ImapCommandException
		internal static ImapCommandException Create (string command, ImapCommand ic)
		{
			var result = ic.Response.ToString ().ToUpperInvariant ();
			string message, reason = null;

			if (string.IsNullOrEmpty (ic.ResponseText)) {
				for (int i = ic.RespCodes.Count - 1; i >= 0; i--) {
					if (ic.RespCodes[i].IsError && !string.IsNullOrEmpty (ic.RespCodes[i].Message)) {
						reason = ic.RespCodes[i].Message;
						break;
					}
				}
			} else {
				reason = ic.ResponseText;
			}

			if (!string.IsNullOrEmpty (reason))
				message = string.Format ("The IMAP server replied to the '{0}' command with a '{1}' response: {2}", command, result, reason);
			else
				message = string.Format ("The IMAP server replied to the '{0}' command with a '{1}' response.", command, result);

			return ic.Exception != null ? new ImapCommandException (ic.Response, reason, message, ic.Exception) : new ImapCommandException (ic.Response, reason, message);
		}

Usage Example

Пример #1
0
        async Task <IList <int> > StoreAsync(IList <int> indexes, ulong?modseq, IList <Annotation> annotations, bool doAsync, CancellationToken cancellationToken)
        {
            if (indexes == null)
            {
                throw new ArgumentNullException(nameof(indexes));
            }

            if (modseq.HasValue && !SupportsModSeq)
            {
                throw new NotSupportedException("The ImapFolder does not support mod-sequences.");
            }

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

            CheckState(true, true);

            if (AnnotationAccess == AnnotationAccess.None)
            {
                throw new NotSupportedException("The ImapFolder does not support annotations.");
            }

            if (indexes.Count == 0 || annotations.Count == 0)
            {
                return(new int[0]);
            }

            var set     = ImapUtils.FormatIndexSet(indexes);
            var builder = new StringBuilder("STORE ");
            var values  = new List <object> ();

            builder.AppendFormat("{0} ", set);

            if (modseq.HasValue)
            {
                builder.AppendFormat(CultureInfo.InvariantCulture, "(UNCHANGEDSINCE {0}) ", modseq.Value);
            }

            ImapUtils.FormatAnnotations(builder, annotations, values, true);
            builder.Append("\r\n");

            var command = builder.ToString();
            var args    = values.ToArray();

            var ic = Engine.QueueCommand(cancellationToken, this, command, args);

            await Engine.RunAsync(ic, doAsync).ConfigureAwait(false);

            ProcessResponseCodes(ic, null);

            if (ic.Response != ImapCommandResponse.Ok)
            {
                throw ImapCommandException.Create("STORE", ic);
            }

            return(GetUnmodified(ic, modseq));
        }
All Usage Examples Of MailKit.Net.Imap.ImapCommandException::Create