static string ValidateMessageId(string messageId) { var buffer = Encoding.UTF8.GetBytes(messageId); InternetAddress addr; int index = 0; if (!InternetAddress.TryParse(ParserOptions.Default, buffer, ref index, buffer.Length, false, out addr) || !(addr is MailboxAddress)) { throw new ArgumentException("Invalid Message-Id format.", "messageId"); } return(((MailboxAddress)addr).Address); }
/// <summary> /// Tries to parse the given text into a new <see cref="MimeKit.MailboxAddress"/> instance. /// </summary> /// <remarks> /// Parses a single <see cref="MailboxAddress"/>. If the the address is not a mailbox address or /// there is more than a single mailbox address, then parsing will fail. /// </remarks> /// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns> /// <param name="options">The parser options to use.</param> /// <param name="text">The text.</param> /// <param name="mailbox">The parsed mailbox address.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="text"/> is <c>null</c>. /// </exception> public static bool TryParse(ParserOptions options, string text, out MailboxAddress mailbox) { InternetAddress address; if (!InternetAddress.TryParse(options, text, out address)) { mailbox = null; return(false); } mailbox = address as MailboxAddress; return(mailbox != null); }
/// <summary> /// Tries to parse the given input buffer into a new <see cref="MimeKit.MailboxAddress"/> instance. /// </summary> /// <remarks> /// Parses a single <see cref="MailboxAddress"/>. If the the address is not a mailbox address or /// there is more than a single mailbox address, then parsing will fail. /// </remarks> /// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns> /// <param name="options">The parser options to use.</param> /// <param name="buffer">The input buffer.</param> /// <param name="startIndex">The starting index of the input buffer.</param> /// <param name="mailbox">The parsed mailbox address.</param> /// <exception cref="System.ArgumentNullException"> /// <para><paramref name="options"/> is <c>null</c>.</para> /// <para>-or-</para> /// <para><paramref name="buffer"/> is <c>null</c>.</para> /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="startIndex"/> is out of range. /// </exception> public static bool TryParse(ParserOptions options, byte[] buffer, int startIndex, out MailboxAddress mailbox) { InternetAddress address; if (!InternetAddress.TryParse(options, buffer, startIndex, out address)) { mailbox = null; return(false); } mailbox = address as MailboxAddress; return(mailbox != null); }
/// <summary> /// Tries to parse the given text into a new <see cref="MimeKit.GroupAddress"/> instance. /// </summary> /// <remarks> /// Parses a single <see cref="GroupAddress"/>. If the the address is not a group address or /// there is more than a single group address, then parsing will fail. /// </remarks> /// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns> /// <param name="options">The parser options to use.</param> /// <param name="text">The text.</param> /// <param name="group">The parsed group address.</param> /// <exception cref="System.ArgumentNullException"> /// <paramref name="text"/> is <c>null</c>. /// </exception> public static bool TryParse(ParserOptions options, string text, out GroupAddress group) { InternetAddress address; if (!InternetAddress.TryParse(options, text, out address)) { group = null; return(false); } group = address as GroupAddress; return(group != null); }
/// <summary> /// Tries to parse the given input buffer into a new <see cref="MimeKit.GroupAddress"/> instance. /// </summary> /// <remarks> /// Parses a single <see cref="GroupAddress"/>. If the the address is not a group address or /// there is more than a single group address, then parsing will fail. /// </remarks> /// <returns><c>true</c>, if the address was successfully parsed, <c>false</c> otherwise.</returns> /// <param name="options">The parser options to use.</param> /// <param name="buffer">The input buffer.</param> /// <param name="startIndex">The starting index of the input buffer.</param> /// <param name="group">The parsed group address.</param> /// <exception cref="System.ArgumentNullException"> /// <para><paramref name="options"/> is <c>null</c>.</para> /// <para>-or-</para> /// <para><paramref name="buffer"/> is <c>null</c>.</para> /// </exception> /// <exception cref="System.ArgumentOutOfRangeException"> /// <paramref name="startIndex"/> is out of range. /// </exception> public static bool TryParse(ParserOptions options, byte[] buffer, int startIndex, out GroupAddress group) { InternetAddress address; if (!InternetAddress.TryParse(options, buffer, startIndex, out address)) { group = null; return(false); } group = address as GroupAddress; return(group != null); }
static bool TryParse(ParserOptions options, byte[] text, ref int index, int endIndex, bool throwOnError, out GroupAddress group) { var flags = AddressParserFlags.AllowGroupAddress; InternetAddress address; if (throwOnError) flags |= AddressParserFlags.ThrowOnError; if (!InternetAddress.TryParse (options, text, ref index, endIndex, flags, out address)) { group = null; return false; } group = (GroupAddress) address; return true; }
internal static bool TryParse(ParserOptions options, byte[] text, ref int index, int endIndex, bool throwOnError, out MailboxAddress mailbox) { var flags = AddressParserFlags.AllowMailboxAddress; InternetAddress address; if (throwOnError) { flags |= AddressParserFlags.ThrowOnError; } if (!InternetAddress.TryParse(options, text, ref index, endIndex, flags, out address)) { mailbox = null; return(false); } mailbox = (MailboxAddress)address; return(true); }