public static FormatIndexSet ( IList |
||
indexes | IList |
The indexes. |
return | string |
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)); }
async Task <IList <int> > StoreAsync(IList <int> indexes, IStoreLabelsRequest request, bool doAsync, CancellationToken cancellationToken) { if (indexes == null) { throw new ArgumentNullException(nameof(indexes)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if ((Engine.Capabilities & ImapCapabilities.GMailExt1) == 0) { throw new NotSupportedException("The IMAP server does not support the Google Mail extensions."); } CheckState(true, true); if (indexes.Count == 0) { return(new int[0]); } string action; switch (request.Action) { case StoreAction.Add: if (request.Labels == null || request.Labels.Count == 0) { return(new int[0]); } action = request.Silent ? "+X-GM-LABELS.SILENT" : "+X-GM-LABELS"; break; case StoreAction.Remove: if (request.Labels == null || request.Labels.Count == 0) { return(new int[0]); } action = request.Silent ? "-X-GM-LABELS.SILENT" : "-X-GM-LABELS"; break; default: action = request.Silent ? "X-GM-LABELS.SILENT" : "X-GM-LABELS"; break; } var set = ImapUtils.FormatIndexSet(Engine, indexes); var @params = string.Empty; if (request.UnchangedSince.HasValue) { @params = string.Format(CultureInfo.InvariantCulture, " (UNCHANGEDSINCE {0})", request.UnchangedSince.Value); } var args = new List <object> (); var list = LabelListToString(request.Labels, args); var format = string.Format("STORE {0}{1} {2} {3}\r\n", set, @params, action, list); var ic = Engine.QueueCommand(cancellationToken, this, format, args.ToArray()); await Engine.RunAsync(ic, doAsync).ConfigureAwait(false); ProcessResponseCodes(ic, null); if (ic.Response != ImapCommandResponse.Ok) { throw ImapCommandException.Create("STORE", ic); } return(GetUnmodified(ic, request.UnchangedSince)); }
async Task <IList <int> > StoreAsync(IList <int> indexes, IStoreFlagsRequest request, bool doAsync, CancellationToken cancellationToken) { if (indexes == null) { throw new ArgumentNullException(nameof(indexes)); } if (request == null) { throw new ArgumentNullException(nameof(request)); } if (request.UnchangedSince.HasValue && !supportsModSeq) { throw new NotSupportedException("The ImapFolder does not support mod-sequences."); } CheckState(true, true); if (indexes.Count == 0) { return(new int[0]); } int numKeywords = request.Keywords != null ? request.Keywords.Count : 0; string action; switch (request.Action) { case StoreAction.Add: if ((request.Flags & SettableFlags) == 0 && numKeywords == 0) { return(new int[0]); } action = request.Silent ? "+FLAGS.SILENT" : "+FLAGS"; break; case StoreAction.Remove: if ((request.Flags & SettableFlags) == 0 && numKeywords == 0) { return(new int[0]); } action = request.Silent ? "-FLAGS.SILENT" : "-FLAGS"; break; default: action = request.Silent ? "FLAGS.SILENT" : "FLAGS"; break; } var flaglist = ImapUtils.FormatFlagsList(request.Flags & PermanentFlags, request.Keywords != null ? request.Keywords.Count : 0); var keywordList = request.Keywords != null?request.Keywords.ToArray() : new object[0]; var set = ImapUtils.FormatIndexSet(Engine, indexes); var @params = string.Empty; if (request.UnchangedSince.HasValue) { @params = string.Format(CultureInfo.InvariantCulture, " (UNCHANGEDSINCE {0})", request.UnchangedSince.Value); } var format = string.Format("STORE {0}{1} {2} {3}\r\n", set, @params, action, flaglist); var ic = Engine.QueueCommand(cancellationToken, this, format, keywordList); await Engine.RunAsync(ic, doAsync).ConfigureAwait(false); ProcessResponseCodes(ic, null); if (ic.Response != ImapCommandResponse.Ok) { throw ImapCommandException.Create("STORE", ic); } return(GetUnmodified(ic, request.UnchangedSince)); }