/// <summary> /// Parses an untagged ID response. /// </summary> /// <param name="engine">The IMAP engine.</param> /// <param name="ic">The IMAP command.</param> /// <param name="index">The index.</param> public static void ParseImplementation(ImapEngine engine, ImapCommand ic, int index) { var token = engine.ReadToken(ic.CancellationToken); var implementation = new ImapImplementation(); ic.UserData = implementation; if (token.Type == ImapTokenType.Nil) { return; } if (token.Type != ImapTokenType.OpenParen) { throw ImapEngine.UnexpectedToken(token, false); } token = engine.PeekToken(ic.CancellationToken); while (token.Type != ImapTokenType.CloseParen) { var property = ImapUtils.ReadStringToken(engine, ic.CancellationToken); var value = ImapUtils.ReadNStringToken(engine, false, ic.CancellationToken); implementation.Properties[property] = value; token = engine.PeekToken(ic.CancellationToken); } // read the ')' token engine.ReadToken(ic.CancellationToken); }
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)); }
/// <summary> /// Initializes a new instance of the <see cref="T:MailKit.Net.Imap.ImapEvent.MessageNew"/> class. /// </summary> /// <remarks> /// Initializes a new instance of the <see cref="T:MailKit.Net.Imap.ImapEvent.MessageNew"/> class. /// </remarks> /// <param name="items">The message summary items to automatically retrieve for new messages.</param> /// <param name="headers">Additional message headers to retrieve for new messages.</param> public MessageNew(MessageSummaryItems items, HashSet <string> headers) : this(items) { this.headers = ImapUtils.GetUniqueHeaders(headers); }
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); }
async Task <IList <UniqueId> > StoreAsync(IList <UniqueId> uids, IStoreFlagsRequest request, bool doAsync, CancellationToken cancellationToken) { if (uids == null) { throw new ArgumentNullException(nameof(uids)); } 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 (uids.Count == 0) { return(new UniqueId[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 UniqueId[0]); } action = request.Silent ? "+FLAGS.SILENT" : "+FLAGS"; break; case StoreAction.Remove: if ((request.Flags & SettableFlags) == 0 && numKeywords == 0) { return(new UniqueId[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]; UniqueIdSet unmodified = null; var @params = string.Empty; if (request.UnchangedSince.HasValue) { @params = string.Format(CultureInfo.InvariantCulture, " (UNCHANGEDSINCE {0})", request.UnchangedSince.Value); } var command = string.Format("UID STORE %s{0} {1} {2}\r\n", @params, action, flaglist); foreach (var ic in Engine.QueueCommands(cancellationToken, this, command, uids, keywordList)) { await Engine.RunAsync(ic, doAsync).ConfigureAwait(false); ProcessResponseCodes(ic, null); if (ic.Response != ImapCommandResponse.Ok) { throw ImapCommandException.Create("STORE", ic); } ProcessUnmodified(ic, ref unmodified, request.UnchangedSince); } if (unmodified == null) { return(new UniqueId[0]); } return(unmodified); }
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 keywordList = request.Keywords != null?request.Keywords.ToArray() : new object[0]; var command = new StringBuilder("STORE "); ImapUtils.FormatIndexSet(Engine, command, indexes); command.Append(' '); if (request.UnchangedSince.HasValue) { command.Append("(UNCHANGEDSINCE "); command.Append(request.UnchangedSince.Value.ToString(CultureInfo.InvariantCulture)); command.Append(") "); } command.Append(action); command.Append(' '); ImapUtils.FormatFlagsList(command, request.Flags & PermanentFlags, request.Keywords != null ? request.Keywords.Count : 0); command.Append("\r\n"); var ic = Engine.QueueCommand(cancellationToken, this, command.ToString(), 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)); }