本文整理汇总了C#中MimeKit.ParserOptions类的典型用法代码示例。如果您正苦于以下问题:C# ParserOptions类的具体用法?C# ParserOptions怎么用?C# ParserOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ParserOptions类属于MimeKit命名空间,在下文中一共展示了ParserOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: MimeEntityConstructorArgs
internal MimeEntityConstructorArgs (ParserOptions options, ContentType ctype, IEnumerable<Header> headers, bool toplevel)
{
ParserOptions = options;
IsTopLevel = toplevel;
ContentType = ctype;
Headers = headers;
}
示例2: ParserOptions
static ParserOptions()
{
Default = new ParserOptions ();
Default.EnableRfc2047Workarounds = true;
Default.RespectContentLength = false;
Default.CharsetEncoding = Encoding.Default;
}
示例3: MimeMessage
internal MimeMessage (ParserOptions options, IEnumerable<Header> headers)
{
addresses = new Dictionary<string, InternetAddressList> (StringComparer.OrdinalIgnoreCase);
Headers = new HeaderList (options);
// initialize our address lists
foreach (var name in StandardAddressHeaders) {
var list = new InternetAddressList ();
list.Changed += InternetAddressListChanged;
addresses.Add (name, list);
}
references = new MessageIdList ();
references.Changed += ReferencesChanged;
inreplyto = null;
Headers.Changed += HeadersChanged;
// add all of our message headers...
foreach (var header in headers) {
if (header.Field.StartsWith ("Content-", StringComparison.OrdinalIgnoreCase))
continue;
Headers.Add (header);
}
}
示例4: Header
/// <summary>
/// Initializes a new instance of the <see cref="MimeKit.Header"/> class.
/// </summary>
/// <remarks>
/// Creates a new message or entity header for the specified field and
/// value pair. The encoding is used to determine which charset to use
/// when encoding the value according to the rules of rfc2047.
/// </remarks>
/// <param name="charset">The charset that should be used to encode the
/// header value.</param>
/// <param name="id">The header identifier.</param>
/// <param name="value">The value of the header.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="charset"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="value"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="id"/> is not a valid <see cref="HeaderId"/>.
/// </exception>
public Header (Encoding charset, HeaderId id, string value)
{
if (charset == null)
throw new ArgumentNullException ("charset");
if (id == HeaderId.Unknown)
throw new ArgumentOutOfRangeException ("id");
if (value == null)
throw new ArgumentNullException ("value");
Options = ParserOptions.Default.Clone ();
Field = id.ToHeaderName ();
Id = id;
SetValue (charset, value);
}
示例5: Header
/// <summary>
/// Initializes a new instance of the <see cref="MimeKit.Header"/> class.
/// </summary>
/// <remarks>
/// Creates a new message or entity header for the specified field and
/// value pair. The encoding is used to determine which charset to use
/// when encoding the value according to the rules of rfc2047.
/// </remarks>
/// <param name="encoding">The character encoding that should be used to
/// encode the header value.</param>
/// <param name="id">The header identifier.</param>
/// <param name="value">The value of the header.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="encoding"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="value"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <paramref name="id"/> is not a valid <see cref="HeaderId"/>.
/// </exception>
public Header (Encoding encoding, HeaderId id, string value)
{
if (encoding == null)
throw new ArgumentNullException ("encoding");
if (id == HeaderId.Unknown)
throw new ArgumentOutOfRangeException ("id");
if (value == null)
throw new ArgumentNullException ("value");
Options = ParserOptions.Default.Clone ();
Field = id.ToHeaderName ();
Id = id;
rawField = Encoding.ASCII.GetBytes (Field);
SetValue (encoding, value);
}
示例6: TryParse
/// <summary>
/// Tries to parse the given input buffer into a new <see cref="MimeKit.ContentType"/> instance.
/// </summary>
/// <returns><c>true</c>, if the content type was successfully parsed, <c>false</c> otherwise.</returns>
/// <param name="options">The parser options.</param>
/// <param name="buffer">The input buffer.</param>
/// <param name="startIndex">The starting index of the input buffer.</param>
/// <param name="type">The parsed content type.</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 ContentType type)
{
if (options == null)
throw new ArgumentNullException ("options");
if (buffer == null)
throw new ArgumentNullException ("buffer");
if (startIndex < 0 || startIndex >= buffer.Length)
throw new ArgumentOutOfRangeException ("startIndex");
int index = startIndex;
return TryParse (options, buffer, ref index, buffer.Length, false, out type);
}
示例7: TryParseGroup
static bool TryParseGroup(ParserOptions options, byte[] text, int startIndex, ref int index, int endIndex, string name, int codepage, bool throwOnError, out InternetAddress address)
{
Encoding encoding = Encoding.GetEncoding (codepage);
List<InternetAddress> members;
address = null;
// skip over the ':'
index++;
if (index >= endIndex) {
if (throwOnError)
throw new ParseException (string.Format ("Incomplete address group at offset {0}", startIndex), startIndex, index);
return false;
}
if (InternetAddressList.TryParse (options, text, ref index, endIndex, true, throwOnError, out members))
address = new GroupAddress (encoding, name, members);
else
address = new GroupAddress (encoding, name);
if (index >= endIndex || text[index] != (byte) ';') {
if (throwOnError)
throw new ParseException (string.Format ("Expected to find ';' at offset {0}", index), startIndex, index);
while (index < endIndex && text[index] != (byte) ';')
index++;
} else {
index++;
}
return true;
}
示例8: EncodeDkimSignatureHeader
static byte[] EncodeDkimSignatureHeader (ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
{
var encoded = new StringBuilder ();
int lineLength = field.Length + 1;
var token = new StringBuilder ();
int index = 0;
while (index < value.Length) {
while (index < value.Length && IsWhiteSpace (value[index]))
index++;
int startIndex = index;
string name;
while (index < value.Length && value[index] != '=') {
if (!IsWhiteSpace (value[index]))
token.Append (value[index]);
index++;
}
name = value.Substring (startIndex, index - startIndex);
while (index < value.Length && value[index] != ';') {
if (!IsWhiteSpace (value[index]))
token.Append (value[index]);
index++;
}
if (index < value.Length && value[index] == ';') {
token.Append (';');
index++;
}
if (lineLength + token.Length + 1 > format.MaxLineLength || name == "bh" || name == "b") {
encoded.Append (format.NewLine);
encoded.Append ('\t');
lineLength = 1;
} else {
encoded.Append (' ');
lineLength++;
}
if (token.Length > format.MaxLineLength) {
switch (name) {
case "z":
EncodeDkimHeaderList (format, encoded, ref lineLength, token.ToString (), '|');
break;
case "h":
EncodeDkimHeaderList (format, encoded, ref lineLength, token.ToString (), ':');
break;
default:
EncodeDkimLongValue (format, encoded, ref lineLength, token.ToString ());
break;
}
} else {
encoded.Append (token.ToString ());
lineLength += token.Length;
}
token.Length = 0;
}
encoded.Append (format.NewLine);
return charset.GetBytes (encoded.ToString ());
}
示例9: TryParse
/// <summary>
/// Tries to parse the given input buffer into a new <see cref="MimeKit.InternetAddress"/> instance.
/// </summary>
/// <remarks>
/// Parses a single <see cref="MailboxAddress"/> or <see cref="GroupAddress"/>. If the buffer contains
/// more data, 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="address">The parsed 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>
public static bool TryParse(ParserOptions options, byte[] buffer, out InternetAddress address)
{
if (options == null)
throw new ArgumentNullException ("options");
if (buffer == null)
throw new ArgumentNullException ("buffer");
int endIndex = buffer.Length;
int index = 0;
if (!TryParse (options, buffer, ref index, endIndex, false, out address))
return false;
if (!ParseUtils.SkipCommentsAndWhiteSpace (buffer, ref index, endIndex, false)) {
address = null;
return false;
}
if (index != endIndex) {
address = null;
return false;
}
return true;
}
示例10: Load
/// <summary>
/// Load a <see cref="MimeMessage"/> from the specified stream.
/// </summary>
/// <remarks>
/// <para>Loads a <see cref="MimeMessage"/> from the given stream, using the
/// specified <see cref="ParserOptions"/>.</para>
/// <para>If <paramref name="persistent"/> is <c>true</c> and <paramref name="stream"/> is seekable, then
/// the <see cref="MimeParser"/> will not copy the content of <see cref="MimePart"/>s into memory. Instead,
/// it will use a <see cref="MimeKit.IO.BoundStream"/> to reference a substream of <paramref name="stream"/>.
/// This has the potential to not only save mmeory usage, but also improve <see cref="MimeParser"/>
/// performance.</para>
/// </remarks>
/// <returns>The parsed message.</returns>
/// <param name="options">The parser options.</param>
/// <param name="stream">The stream.</param>
/// <param name="persistent"><c>true</c> if the stream is persistent; otherwise <c>false</c>.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="options"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="stream"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.FormatException">
/// There was an error parsing the entity.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
public static MimeMessage Load (ParserOptions options, Stream stream, bool persistent, CancellationToken cancellationToken = default (CancellationToken))
{
if (options == null)
throw new ArgumentNullException ("options");
if (stream == null)
throw new ArgumentNullException ("stream");
var parser = new MimeParser (options, stream, MimeFormat.Entity, persistent);
return parser.ParseMessage (cancellationToken);
}
示例11: Parse
/// <summary>
/// Parses the given text into a new <see cref="MimeKit.InternetAddress"/> instance.
/// </summary>
/// <remarks>
/// Parses a single <see cref="MailboxAddress"/> or <see cref="GroupAddress"/>. If the text contains
/// more data, then parsing will fail.
/// </remarks>
/// <returns>The parsed <see cref="MimeKit.InternetAddress"/>.</returns>
/// <param name="options">The parser options to use.</param>
/// <param name="text">The text.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="options"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="text"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="MimeKit.ParseException">
/// <paramref name="text"/> could not be parsed.
/// </exception>
public static InternetAddress Parse(ParserOptions options, string text)
{
if (options == null)
throw new ArgumentNullException ("options");
if (text == null)
throw new ArgumentNullException ("text");
var buffer = Encoding.UTF8.GetBytes (text);
int endIndex = buffer.Length;
InternetAddress address;
int index = 0;
TryParse (options, buffer, ref index, endIndex, true, out address);
ParseUtils.SkipCommentsAndWhiteSpace (buffer, ref index, endIndex, true);
if (index != endIndex)
throw new ParseException (string.Format ("Unexpected token at offset {0}", index), index, index);
return address;
}
示例12: EncodeUnstructuredHeader
static byte[] EncodeUnstructuredHeader (ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
{
if (format.International) {
var folded = Fold (format, field, value);
return Encoding.UTF8.GetBytes (folded);
}
var encoded = Rfc2047.EncodeText (format, charset, value);
return Rfc2047.FoldUnstructuredHeader (format, field, encoded);
}
示例13: EncodeContentType
static byte[] EncodeContentType (ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
{
var contentType = ContentType.Parse (options, value);
var encoded = contentType.Encode (format, charset);
return Encoding.UTF8.GetBytes (encoded);
}
示例14: EncodeContentDisposition
static byte[] EncodeContentDisposition (ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
{
var disposition = ContentDisposition.Parse (options, value);
var encoded = disposition.Encode (format, charset);
return Encoding.UTF8.GetBytes (encoded);
}
示例15: EncodeReferencesHeader
static byte[] EncodeReferencesHeader (ParserOptions options, FormatOptions format, Encoding charset, string field, string value)
{
var encoded = new StringBuilder ();
int lineLength = field.Length + 1;
int count = 0;
foreach (var reference in MimeUtils.EnumerateReferences (value)) {
if (count > 0 && lineLength + reference.Length + 3 > format.MaxLineLength) {
encoded.Append (format.NewLine);
encoded.Append ('\t');
lineLength = 1;
count = 0;
} else {
encoded.Append (' ');
lineLength++;
}
encoded.Append ('<').Append (reference).Append ('>');
lineLength += reference.Length + 2;
count++;
}
encoded.Append (format.NewLine);
return charset.GetBytes (encoded.ToString ());
}