本文整理汇总了C#中Portable.Text.Encoding类的典型用法代码示例。如果您正苦于以下问题:C# Portable.Text.Encoding类的具体用法?C# Portable.Text.Encoding怎么用?C# Portable.Text.Encoding使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Portable.Text.Encoding类属于命名空间,在下文中一共展示了Portable.Text.Encoding类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SaslMechanismLogin
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.Security.SaslMechanismLogin"/> class.
/// </summary>
/// <remarks>
/// Creates a new LOGIN SASL context.
/// </remarks>
/// <param name="uri">The URI of the service.</param>
/// <param name="encoding">The encoding to use for the user's credentials.</param>
/// <param name="credentials">The user's credentials.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="uri"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="encoding"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="credentials"/> is <c>null</c>.</para>
/// </exception>
public SaslMechanismLogin (Uri uri, Encoding encoding, ICredentials credentials) : base (uri, credentials)
{
if (encoding == null)
throw new ArgumentNullException (nameof (encoding));
this.encoding = encoding;
}
示例2: Pop3Command
public Pop3Command (CancellationToken cancellationToken, Pop3CommandHandler handler, Encoding encoding, string format, params object[] args)
{
Command = string.Format (format, args);
CancellationToken = cancellationToken;
Encoding = encoding;
Handler = handler;
}
示例3: InternetAddress
/// <summary>
/// Initializes a new instance of the <see cref="MimeKit.InternetAddress"/> class.
/// </summary>
/// <remarks>
/// Initializes the <see cref="Encoding"/> and <see cref="Name"/> properties of the internet address.
/// </remarks>
/// <param name="encoding">The character encoding to be used for encoding the name.</param>
/// <param name="name">The name of the mailbox or group.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="encoding"/> is <c>null</c>.
/// </exception>
protected InternetAddress(Encoding encoding, string name)
{
if (encoding == null)
throw new ArgumentNullException ("encoding");
Encoding = encoding;
Name = name;
}
示例4: MailboxAddress
/// <summary>
/// Initializes a new instance of the <see cref="MimeKit.MailboxAddress"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="MailboxAddress"/> with the specified name, address and route. The
/// specified text encoding is used when encoding the name according to the rules of rfc2047.
/// </remarks>
/// <param name="encoding">The character encoding to be used for encoding the name.</param>
/// <param name="name">The name of the mailbox.</param>
/// <param name="route">The route of the mailbox.</param>
/// <param name="address">The address of the mailbox.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="encoding"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="route"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="address"/> is <c>null</c>.</para>
/// </exception>
public MailboxAddress (Encoding encoding, string name, IEnumerable<string> route, string address) : base (encoding, name)
{
if (address == null)
throw new ArgumentNullException ("address");
Route = new DomainList (route);
Route.Changed += RouteChanged;
Address = address;
}
示例5: SmtpStream
static SmtpStream ()
{
UTF8 = Encoding.GetEncoding (65001, new EncoderExceptionFallback (), new DecoderExceptionFallback ());
try {
Latin1 = Encoding.GetEncoding (28591);
} catch (NotSupportedException) {
Latin1 = Encoding.GetEncoding (1252);
}
}
示例6: HtmlWriter
/// <summary>
/// Initializes a new instance of the <see cref="MimeKit.Text.HtmlWriter"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="HtmlWriter"/>.
/// </remarks>
/// <param name="stream">The output stream.</param>
/// <param name="encoding">The encoding to use for the output.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="stream"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="encoding"/> is <c>null</c>.</para>
/// </exception>
public HtmlWriter (Stream stream, Encoding encoding)
{
if (stream == null)
throw new ArgumentNullException ("stream");
if (encoding == null)
throw new ArgumentNullException ("encoding");
html = new StreamWriter (stream, encoding, 4096);
}
示例7: 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);
}
示例8: 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);
}
示例9: CharsetConvert
static byte[] CharsetConvert (Encoding charset, char[] word, int length, out int converted)
{
var encoder = charset.GetEncoder ();
int count = encoder.GetByteCount (word, 0, length, true);
var encoded = new byte[count];
converted = encoder.GetBytes (word, 0, length, encoded, 0, true);
return encoded;
}
示例10: EncodeText
/// <summary>
/// Encodes the unstructured text.
/// </summary>
/// <remarks>
/// Encodes the unstructured text according to the rules of rfc2047
/// using the specified charset encoding and formatting options.
/// </remarks>
/// <returns>The encoded text.</returns>
/// <param name="options">The formatting options</param>
/// <param name="charset">The charset encoding.</param>
/// <param name="text">The text to encode.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="options"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="charset"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="text"/> is <c>null</c>.</para>
/// </exception>
public static byte[] EncodeText (FormatOptions options, Encoding charset, string text)
{
if (options == null)
throw new ArgumentNullException ("options");
if (charset == null)
throw new ArgumentNullException ("charset");
if (text == null)
throw new ArgumentNullException ("text");
return Encode (options, charset, text, false);
}
示例11: EncodePhrase
/// <summary>
/// Encodes the phrase.
/// </summary>
/// <remarks>
/// Encodes the phrase according to the rules of rfc2047 using
/// the specified charset encoding and formatting options.
/// </remarks>
/// <returns>The encoded phrase.</returns>
/// <param name="options">The formatting options</param>
/// <param name="charset">The charset encoding.</param>
/// <param name="phrase">The phrase to encode.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="options"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="charset"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="phrase"/> is <c>null</c>.</para>
/// </exception>
public static byte[] EncodePhrase (FormatOptions options, Encoding charset, string phrase)
{
if (options == null)
throw new ArgumentNullException ("options");
if (charset == null)
throw new ArgumentNullException ("charset");
if (phrase == null)
throw new ArgumentNullException ("phrase");
return Encode (options, charset, phrase, true);
}
示例12: FormatRawValue
byte[] FormatRawValue (FormatOptions format, Encoding encoding)
{
switch (Id) {
case HeaderId.DispositionNotificationTo:
case HeaderId.ResentFrom:
case HeaderId.ResentBcc:
case HeaderId.ResentCc:
case HeaderId.ResentTo:
case HeaderId.From:
case HeaderId.Bcc:
case HeaderId.Cc:
case HeaderId.To:
return EncodeAddressHeader (Options, format, encoding, Field, textValue);
case HeaderId.Received:
return EncodeReceivedHeader (Options, format, encoding, Field, textValue);
case HeaderId.ResentMessageId:
case HeaderId.MessageId:
case HeaderId.ContentId:
return EncodeMessageIdHeader (Options, format, encoding, Field, textValue);
case HeaderId.References:
return EncodeReferencesHeader (Options, format, encoding, Field, textValue);
case HeaderId.ContentDisposition:
return EncodeContentDisposition (Options, format, encoding, Field, textValue);
case HeaderId.ContentType:
return EncodeContentType (Options, format, encoding, Field, textValue);
case HeaderId.DkimSignature:
return EncodeDkimSignatureHeader (Options, format, encoding, Field, textValue);
default:
return EncodeUnstructuredHeader (Options, format, encoding, Field, textValue);
}
}
示例13: Encode
static byte[] Encode (FormatOptions options, Encoding charset, string text, bool phrase)
{
var mode = phrase ? QEncodeMode.Phrase : QEncodeMode.Text;
var words = Merge (options, charset, GetRfc822Words (options, charset, text, phrase));
var str = new StringBuilder ();
int start, length;
Word prev = null;
byte[] encoded;
foreach (var word in words) {
// append the correct number of spaces between words...
if (prev != null && !(prev.Type == WordType.EncodedWord && word.Type == WordType.EncodedWord)) {
start = prev.StartIndex + prev.CharCount;
length = word.StartIndex - start;
str.Append (text, start, length);
}
switch (word.Type) {
case WordType.Atom:
str.Append (text, word.StartIndex, word.CharCount);
break;
case WordType.QuotedString:
AppendQuoted (str, text, word.StartIndex, word.CharCount);
break;
case WordType.EncodedWord:
if (prev != null && prev.Type == WordType.EncodedWord) {
// include the whitespace between these 2 words in the
// resulting rfc2047 encoded-word.
start = prev.StartIndex + prev.CharCount;
length = (word.StartIndex + word.CharCount) - start;
str.Append (phrase ? '\t' : ' ');
} else {
start = word.StartIndex;
length = word.CharCount;
}
switch (word.Encoding) {
case 0: // us-ascii
AppendEncodedWord (str, Encoding.ASCII, text, start, length, mode);
break;
case 1: // iso-8859-1
AppendEncodedWord (str, CharsetUtils.Latin1, text, start, length, mode);
break;
default: // custom charset
AppendEncodedWord (str, charset, text, start, length, mode);
break;
}
break;
}
prev = word;
}
encoded = new byte[str.Length];
for (int i = 0; i < str.Length; i++)
encoded[i] = (byte) str[i];
return encoded;
}
示例14: AuthenticateAsync
/// <summary>
/// Asynchronously authenticates using the specified user name and password.
/// </summary>
/// <remarks>
/// <para>If the server supports one or more SASL authentication mechanisms,
/// then the SASL mechanisms that both the client and server support are tried
/// in order of greatest security to weakest security. Once a SASL
/// authentication mechanism is found that both client and server support,
/// the credentials are used to authenticate.</para>
/// <para>If the server does not support SASL or if no common SASL mechanisms
/// can be found, then the default login command is used as a fallback.</para>
/// <note type="tip">To prevent the usage of certain authentication mechanisms,
/// simply remove them from the <see cref="AuthenticationMechanisms"/> hash set
/// before calling this method.</note>
/// </remarks>
/// <returns>An asynchronous task context.</returns>
/// <param name="encoding">The encoding to use for the user's credentials.</param>
/// <param name="userName">The user name.</param>
/// <param name="password">The password.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="encoding"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="userName"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="password"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="MailService"/> has been disposed.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// The <see cref="MailService"/> is not connected or is already authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="MailKit.Security.AuthenticationException">
/// Authentication using the supplied credentials has failed.
/// </exception>
/// <exception cref="MailKit.Security.SaslException">
/// A SASL authentication error occurred.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ProtocolException">
/// A protocol error occurred.
/// </exception>
public Task AuthenticateAsync (Encoding encoding, string userName, string password, CancellationToken cancellationToken = default (CancellationToken))
{
if (encoding == null)
throw new ArgumentNullException ("encoding");
if (userName == null)
throw new ArgumentNullException ("userName");
if (password == null)
throw new ArgumentNullException ("password");
var credentials = new NetworkCredential (userName, password);
return AuthenticateAsync (encoding, credentials, cancellationToken);
}
示例15: Authenticate
/// <summary>
/// Authenticates using the supplied credentials.
/// </summary>
/// <remarks>
/// <para>If the server supports one or more SASL authentication mechanisms,
/// then the SASL mechanisms that both the client and server support are tried
/// in order of greatest security to weakest security. Once a SASL
/// authentication mechanism is found that both client and server support,
/// the credentials are used to authenticate.</para>
/// <para>If the server does not support SASL or if no common SASL mechanisms
/// can be found, then the default login command is used as a fallback.</para>
/// <note type="tip">To prevent the usage of certain authentication mechanisms,
/// simply remove them from the <see cref="AuthenticationMechanisms"/> hash set
/// before calling this method.</note>
/// </remarks>
/// <param name="encoding">The encoding to use for the user's credentials.</param>
/// <param name="credentials">The user's credentials.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="encoding"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="credentials"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="MailService"/> has been disposed.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// The <see cref="MailService"/> is not connected or is already authenticated.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="MailKit.Security.AuthenticationException">
/// Authentication using the supplied credentials has failed.
/// </exception>
/// <exception cref="MailKit.Security.SaslException">
/// A SASL authentication error occurred.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ProtocolException">
/// A protocol error occurred.
/// </exception>
public abstract void Authenticate (Encoding encoding, ICredentials credentials, CancellationToken cancellationToken = default (CancellationToken));