本文整理汇总了C#中MimeKit.ContentType.Encode方法的典型用法代码示例。如果您正苦于以下问题:C# ContentType.Encode方法的具体用法?C# ContentType.Encode怎么用?C# ContentType.Encode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MimeKit.ContentType
的用法示例。
在下文中一共展示了ContentType.Encode方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Load
/// <summary>
/// Load a <see cref="MimeEntity"/> from the specified content stream.
/// </summary>
/// <remarks>
/// This method is mostly meant for use with APIs such as <see cref="System.Net.HttpWebResponse"/>
/// where the headers are parsed separately from the content.
/// </remarks>
/// <returns>The parsed MIME entity.</returns>
/// <param name="options">The parser options.</param>
/// <param name="contentType">The Content-Type of the stream.</param>
/// <param name="content">The content stream.</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="contentType"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="content"/> 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 MimeEntity Load (ParserOptions options, ContentType contentType, Stream content, CancellationToken cancellationToken = default (CancellationToken))
{
if (options == null)
throw new ArgumentNullException ("options");
if (contentType == null)
throw new ArgumentNullException ("contentType");
if (content == null)
throw new ArgumentNullException ("content");
var format = FormatOptions.Default.Clone ();
format.NewLineFormat = NewLineFormat.Dos;
var encoded = contentType.Encode (format, Encoding.UTF8);
var header = string.Format ("Content-Type:{0}\r\n", encoded);
var chained = new ChainedStream ();
chained.Add (new MemoryStream (Encoding.UTF8.GetBytes (header), false));
chained.Add (content);
return Load (options, chained, cancellationToken);
}
示例2: TestEncodingOfLongParamValues2047
public void TestEncodingOfLongParamValues2047 ()
{
const string expected = " text/plain; charset=utf-8; name=\"=?iso-8859-1?b?5eXl5eXl?=\n\t=?iso-8859-1?b?5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5eXl5Q==?=\"\n";
var format = FormatOptions.Default.Clone ();
format.ParameterEncodingMethod = ParameterEncodingMethod.Rfc2047;
format.NewLineFormat = NewLineFormat.Unix;
var type = new ContentType ("text", "plain");
type.Parameters.Add ("charset", "utf-8");
type.Parameters.Add ("name", new string ('å', 40));
var encoded = type.Encode (format, Encoding.UTF8);
Assert.AreEqual (expected, encoded, "Encoded Content-Type does not match: {0}", expected);
}
示例3: TestEncodingOfLongParamValues
public void TestEncodingOfLongParamValues ()
{
const string expected = " text/plain; charset=utf-8;\n\tname*0*=iso-8859-1''%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5;\n\tname*1*=%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5%E5\n";
var format = FormatOptions.Default.Clone ();
format.NewLineFormat = NewLineFormat.Unix;
var type = new ContentType ("text", "plain");
type.Parameters.Add ("charset", "utf-8");
type.Parameters.Add ("name", new string ('å', 40));
var encoded = type.Encode (format, Encoding.UTF8);
Assert.AreEqual (expected, encoded, "Encoded Content-Type does not match: {0}", expected);
}
示例4: TestEncodingOfParamValues2047
public void TestEncodingOfParamValues2047 ()
{
const string expected = " text/plain; charset=iso-8859-1;\n\tname=\"=?iso-8859-1?q?Kristoffer_Br=E5nemyr?=\"\n";
var format = FormatOptions.Default.Clone ();
format.ParameterEncodingMethod = ParameterEncodingMethod.Rfc2047;
format.NewLineFormat = NewLineFormat.Unix;
var type = new ContentType ("text", "plain");
type.Parameters.Add ("charset", "iso-8859-1");
type.Parameters.Add ("name", "Kristoffer Brånemyr");
var encoded = type.Encode (format, Encoding.UTF8);
Assert.AreEqual (expected, encoded, "Encoded Content-Type does not match: {0}", expected);
}
示例5: TestBreakingOfLongParamValues2047
public void TestBreakingOfLongParamValues2047 ()
{
const string expected = " text/plain; charset=iso-8859-1; name=\"=?us-ascii?q?this_is_?=\n\t=?us-ascii?q?a_really_really_long_filename_that_should_force_MimeKit_to_?=\n\t=?us-ascii?q?break_it_apart_-_yay!=2Ehtml?=\"\n";
var format = FormatOptions.Default.Clone ();
format.ParameterEncodingMethod = ParameterEncodingMethod.Rfc2047;
format.NewLineFormat = NewLineFormat.Unix;
var type = new ContentType ("text", "plain");
type.Parameters.Add ("charset", "iso-8859-1");
type.Parameters.Add ("name", "this is a really really long filename that should force MimeKit to break it apart - yay!.html");
var encoded = type.Encode (format, Encoding.UTF8);
Assert.AreEqual (expected, encoded, "Encoded Content-Type does not match: {0}", expected);
}
示例6: TestBreakingOfLongParamValues
public void TestBreakingOfLongParamValues ()
{
const string expected = " text/plain; charset=iso-8859-1;\n\tname*0=\"this is a really really long filename that should force MimeKit to b\";\n\tname*1=\"reak it apart - yay!.html\"\n";
var format = FormatOptions.Default.Clone ();
format.NewLineFormat = NewLineFormat.Unix;
var type = new ContentType ("text", "plain");
type.Parameters.Add ("charset", "iso-8859-1");
type.Parameters.Add ("name", "this is a really really long filename that should force MimeKit to break it apart - yay!.html");
var encoded = type.Encode (format, Encoding.UTF8);
Assert.AreEqual (expected, encoded, "Encoded Content-Type does not match: {0}", expected);
}