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 <UniqueId> > StoreAsync(IList <UniqueId> uids, ulong?modseq, IList <Annotation> annotations, bool doAsync, CancellationToken cancellationToken) { if (uids == null) { throw new ArgumentNullException(nameof(uids)); } 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 (uids.Count == 0 || annotations.Count == 0) { return(new UniqueId[0]); } var builder = new StringBuilder("UID STORE %s "); var values = new List <object> (); UniqueIdSet modified = null; 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(); foreach (var ic in Engine.QueueCommands(cancellationToken, this, command, uids, args)) { await Engine.RunAsync(ic, doAsync).ConfigureAwait(false); ProcessResponseCodes(ic, null); if (ic.Response != ImapCommandResponse.Ok) { throw ImapCommandException.Create("STORE", ic); } if (modseq.HasValue) { var rc = ic.RespCodes.OfType <ModifiedResponseCode> ().FirstOrDefault(); if (rc != null) { if (modified != null) { modified.AddRange(rc.UidSet); } else { modified = rc.UidSet; } } } } if (modified == null) { return(new UniqueId[0]); } return(modified); }