Beispiel #1
0
        /// <summary>
        /// Enumerates the message-id references such as those that can be found in
        /// the In-Reply-To or References header.
        /// </summary>
        /// <remarks>
        /// Incrementally parses Message-Ids (such as those from a References header
        /// in a MIME message) from the supplied buffer starting at the given index
        /// and spanning across the specified number of bytes.
        /// </remarks>
        /// <returns>The references.</returns>
        /// <param name="buffer">The raw byte buffer to parse.</param>
        /// <param name="startIndex">The index into the buffer to start parsing.</param>
        /// <param name="length">The length of the buffer to parse.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="buffer"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="startIndex"/> and <paramref name="length"/> do not specify
        /// a valid range in the byte array.
        /// </exception>
        public static IEnumerable <string> EnumerateReferences(byte[] buffer, int startIndex, int length)
        {
            ParseUtils.ValidateArguments(buffer, startIndex, length);

            int endIndex = startIndex + length;
            int index    = startIndex;

            do
            {
                if (!ParseUtils.SkipCommentsAndWhiteSpace(buffer, ref index, endIndex, false))
                {
                    break;
                }

                if (index >= endIndex)
                {
                    break;
                }

                if (buffer[index] == '<')
                {
                    if (ParseUtils.TryParseMsgId(buffer, ref index, endIndex, true, false, out string msgid))
                    {
                        yield return(msgid);
                    }
                }
                else if (!ParseUtils.SkipWord(buffer, ref index, endIndex, false))
                {
                    index++;
                }
            } while (index < endIndex);

            yield break;
        }
Beispiel #2
0
        /// <summary>
        /// Parses a Message-Id header value.
        /// </summary>
        /// <remarks>
        /// Parses the Message-Id value, returning the addr-spec portion of the msg-id token.
        /// </remarks>
        /// <returns>The addr-spec portion of the msg-id token.</returns>
        /// <param name="buffer">The raw byte buffer to parse.</param>
        /// <param name="startIndex">The index into the buffer to start parsing.</param>
        /// <param name="length">The length of the buffer to parse.</param>
        /// <exception cref="System.ArgumentNullException">
        /// <paramref name="buffer"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="System.ArgumentOutOfRangeException">
        /// <paramref name="startIndex"/> and <paramref name="length"/> do not specify
        /// a valid range in the byte array.
        /// </exception>
        public static string ParseMessageId(byte[] buffer, int startIndex, int length)
        {
            ParseUtils.ValidateArguments(buffer, startIndex, length);

            int    endIndex = startIndex + length;
            int    index    = startIndex;
            string msgid;

            ParseUtils.TryParseMsgId(buffer, ref index, endIndex, false, false, out msgid);

            return(msgid);
        }