本文整理汇总了C#中MimeKit.FormatOptions.Clone方法的典型用法代码示例。如果您正苦于以下问题:C# FormatOptions.Clone方法的具体用法?C# FormatOptions.Clone怎么用?C# FormatOptions.Clone使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MimeKit.FormatOptions
的用法示例。
在下文中一共展示了FormatOptions.Clone方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ImapLiteral
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapLiteral"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="MailKit.Net.Imap.ImapLiteral"/>.
/// </remarks>
/// <param name="options">The formatting options.</param>
/// <param name="literal">The literal.</param>
/// <param name="action">The progress update action.</param>
public ImapLiteral (FormatOptions options, object literal, Action<int> action = null)
{
format = options.Clone ();
format.NewLineFormat = NewLineFormat.Dos;
update = action;
if (literal is MimeMessage) {
Type = ImapLiteralType.MimeMessage;
} else if (literal is Stream) {
Type = ImapLiteralType.Stream;
} else if (literal is string) {
literal = Encoding.UTF8.GetBytes ((string) literal);
Type = ImapLiteralType.String;
} else if (literal is byte[]) {
Type = ImapLiteralType.String;
} else {
throw new ArgumentException ("Unknown literal type");
}
Literal = literal;
}
示例2: Append
/// <summary>
/// Appends the specified messages to the folder.
/// </summary>
/// <remarks>
/// Appends the specified messages to the folder and returns the UniqueIds assigned to the messages.
/// </remarks>
/// <returns>The UIDs of the appended messages, if available; otherwise an empty array.</returns>
/// <param name="options">The formatting options.</param>
/// <param name="messages">The list of messages to append to the folder.</param>
/// <param name="flags">The message flags to use for each of the messages.</param>
/// <param name="dates">The received dates to use for each of the messages.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="progress">The progress reporting mechanism.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="options"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="messages"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="flags"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="dates"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <para>One or more of the <paramref name="messages"/> is null.</para>
/// <para>-or-</para>
/// <para>The number of messages, flags, and dates do not match.</para>
/// </exception>
/// <exception cref="System.ObjectDisposedException">
/// The <see cref="ImapClient"/> has been disposed.
/// </exception>
/// <exception cref="ServiceNotConnectedException">
/// The <see cref="ImapClient"/> is not connected.
/// </exception>
/// <exception cref="ServiceNotAuthenticatedException">
/// The <see cref="ImapClient"/> is not authenticated.
/// </exception>
/// <exception cref="System.InvalidOperationException">
/// Internationalized formatting was requested but has not been enabled.
/// </exception>
/// <exception cref="FolderNotFoundException">
/// The <see cref="ImapFolder"/> does not exist.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.NotSupportedException">
/// Internationalized formatting was requested but is not supported by the server.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
/// <exception cref="ImapProtocolException">
/// The server's response contained unexpected tokens.
/// </exception>
/// <exception cref="ImapCommandException">
/// The server replied with a NO or BAD response.
/// </exception>
public override IList<UniqueId> Append (FormatOptions options, IList<MimeMessage> messages, IList<MessageFlags> flags, IList<DateTimeOffset> dates, CancellationToken cancellationToken = default (CancellationToken), ITransferProgress progress = null)
{
if (options == null)
throw new ArgumentNullException ("options");
if (messages == null)
throw new ArgumentNullException ("messages");
for (int i = 0; i < messages.Count; i++) {
if (messages[i] == null)
throw new ArgumentException ("One or more of the messages is null.");
}
if (flags == null)
throw new ArgumentNullException ("flags");
if (dates == null)
throw new ArgumentNullException ("dates");
if (messages.Count != flags.Count || messages.Count != dates.Count)
throw new ArgumentException ("The number of messages, the number of flags, and the number of dates must be equal.");
CheckState (false, false);
if (options.International && (Engine.Capabilities & ImapCapabilities.UTF8Accept) == 0)
throw new NotSupportedException ("The IMAP server does not support the UTF8 extension.");
var format = options.Clone ();
format.NewLineFormat = NewLineFormat.Dos;
if ((Engine.Capabilities & ImapCapabilities.UTF8Only) == ImapCapabilities.UTF8Only)
format.International = true;
if (format.International && !Engine.UTF8Enabled)
throw new InvalidOperationException ("The UTF8 extension has not been enabled.");
if (messages.Count == 0)
return new UniqueId[0];
if ((Engine.Capabilities & ImapCapabilities.MultiAppend) != 0) {
var ic = QueueMultiAppend (format, messages, flags, dates, cancellationToken, progress);
Engine.Wait (ic);
//.........这里部分代码省略.........
示例3: Verify
/// <summary>
/// Verify the specified DKIM-Signature header.
/// </summary>
/// <remarks>
/// Verifies the specified DKIM-Signature header.
/// </remarks>
/// <param name="options">The formatting options.</param>
/// <param name="dkimSignature">The DKIM-Signature header.</param>
/// <param name="publicKeyLocator">The public key locator service.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="options"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="dkimSignature"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="publicKeyLocator"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <paramref name="dkimSignature"/> is not a DKIM-Signature header.
/// </exception>
/// <exception cref="System.FormatException">
/// The DKIM-Signature header value is malformed.
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
bool Verify (FormatOptions options, Header dkimSignature, IDkimPublicKeyLocator publicKeyLocator, CancellationToken cancellationToken = default (CancellationToken))
{
if (options == null)
throw new ArgumentNullException ("options");
if (dkimSignature == null)
throw new ArgumentNullException ("dkimSignature");
if (dkimSignature.Id != HeaderId.DkimSignature)
throw new ArgumentException ("The dkimSignature parameter MUST be a DKIM-Signature header.", "dkimSignature");
if (publicKeyLocator == null)
throw new ArgumentNullException ("publicKeyLocator");
var parameters = ParseDkimSignature (dkimSignature.Value);
DkimCanonicalizationAlgorithm headerAlgorithm, bodyAlgorithm;
DkimSignatureAlgorithm signatureAlgorithm;
AsymmetricKeyParameter key;
string d, s, q, h, bh, b;
int maxLength;
ValidateDkimSignatureParameters (parameters, out signatureAlgorithm, out headerAlgorithm, out bodyAlgorithm,
out d, out s, out q, out h, out bh, out b, out maxLength);
key = publicKeyLocator.LocatePublicKey (q, d, s, cancellationToken);
options = options.Clone ();
options.NewLineFormat = NewLineFormat.Dos;
// first check the body hash (if that's invalid, then the entire signature is invalid)
var hash = Convert.ToBase64String (DkimHashBody (options, signatureAlgorithm, bodyAlgorithm, maxLength));
if (hash != bh)
return false;
using (var stream = new DkimSignatureStream (DkimGetDigestSigner (signatureAlgorithm, key))) {
using (var filtered = new FilteredStream (stream)) {
filtered.Add (options.CreateNewLineFilter ());
DkimWriteHeaders (options, h.Split (':'), headerAlgorithm, filtered);
// now include the DKIM-Signature header that we are verifying,
// but only after removing the "b=" signature value.
var header = GetSignedDkimSignatureHeader (dkimSignature);
switch (headerAlgorithm) {
case DkimCanonicalizationAlgorithm.Relaxed:
DkimWriteHeaderRelaxed (options, filtered, header);
break;
default:
DkimWriteHeaderSimple (options, filtered, header);
break;
}
filtered.Flush ();
}
return stream.VerifySignature (b);
}
}
示例4: Sign
/// <summary>
/// Digitally sign the message using a DomainKeys Identified Mail (DKIM) signature.
/// </summary>
/// <remarks>
/// Digitally signs the message using a DomainKeys Identified Mail (DKIM) signature.
/// </remarks>
/// <param name="options">The formatting options.</param>
/// <param name="signer">The DKIM signer.</param>
/// <param name="headers">The list of header fields to sign.</param>
/// <param name="headerCanonicalizationAlgorithm">The header canonicalization algorithm.</param>
/// <param name="bodyCanonicalizationAlgorithm">The body canonicalization algorithm.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="options"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="signer"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="headers"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// <para><paramref name="headers"/> does not contain the 'From' header.</para>
/// <para>-or-</para>
/// <para><paramref name="headers"/> contains one or more of the following headers: Return-Path,
/// Received, Comments, Keywords, Bcc, Resent-Bcc, or DKIM-Signature.</para>
/// </exception>
void Sign (FormatOptions options, DkimSigner signer, IList<HeaderId> headers, DkimCanonicalizationAlgorithm headerCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple, DkimCanonicalizationAlgorithm bodyCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple)
{
if (options == null)
throw new ArgumentNullException ("options");
if (signer == null)
throw new ArgumentNullException ("signer");
if (headers == null)
throw new ArgumentNullException ("headers");
if (!headers.Contains (HeaderId.From))
throw new ArgumentException ("The list of headers to sign MUST include the 'From' header.");
var fields = new string[headers.Count];
for (int i = 0; i < headers.Count; i++) {
if (DkimShouldNotInclude.Contains (headers[i]))
throw new ArgumentException (string.Format ("The list of headers to sign SHOULD NOT include the '{0}' header.", headers[i].ToHeaderName ()));
fields[i] = headers[i].ToHeaderName ().ToLowerInvariant ();
}
if (version == null && Body != null && Body.Headers.Count > 0)
MimeVersion = new Version (1, 0);
Prepare (EncodingConstraint.SevenBit, 78);
var t = DateTime.Now - DateUtils.UnixEpoch;
var value = new StringBuilder ("v=1");
byte[] signature, hash;
Header dkim;
options = options.Clone ();
options.NewLineFormat = NewLineFormat.Dos;
switch (signer.SignatureAlgorithm) {
case DkimSignatureAlgorithm.RsaSha256:
value.Append ("; a=rsa-sha256");
break;
default:
value.Append ("; a=rsa-sha1");
break;
}
value.AppendFormat ("; d={0}; s={1}", signer.Domain, signer.Selector);
value.AppendFormat ("; c={0}/{1}",
headerCanonicalizationAlgorithm.ToString ().ToLowerInvariant (),
bodyCanonicalizationAlgorithm.ToString ().ToLowerInvariant ());
if (!string.IsNullOrEmpty (signer.QueryMethod))
value.AppendFormat ("; q={0}", signer.QueryMethod);
if (!string.IsNullOrEmpty (signer.AgentOrUserIdentifier))
value.AppendFormat ("; i={0}", signer.AgentOrUserIdentifier);
value.AppendFormat ("; t={0}", (long) t.TotalSeconds);
using (var stream = new DkimSignatureStream (DkimGetDigestSigner (signer.SignatureAlgorithm, signer.PrivateKey))) {
using (var filtered = new FilteredStream (stream)) {
filtered.Add (options.CreateNewLineFilter ());
// write the specified message headers
DkimWriteHeaders (options, fields, headerCanonicalizationAlgorithm, filtered);
value.AppendFormat ("; h={0}", string.Join (":", fields.ToArray ()));
hash = DkimHashBody (options, signer.SignatureAlgorithm, bodyCanonicalizationAlgorithm, -1);
value.AppendFormat ("; bh={0}", Convert.ToBase64String (hash));
value.Append ("; b=");
dkim = new Header (HeaderId.DkimSignature, value.ToString ());
Headers.Insert (0, dkim);
switch (headerCanonicalizationAlgorithm) {
case DkimCanonicalizationAlgorithm.Relaxed:
DkimWriteHeaderRelaxed (options, filtered, dkim);
break;
default:
DkimWriteHeaderSimple (options, filtered, dkim);
//.........这里部分代码省略.........
示例5: Send
void Send (FormatOptions options, MimeMessage message, MailboxAddress sender, IList<MailboxAddress> recipients, CancellationToken cancellationToken, ITransferProgress progress)
{
CheckDisposed ();
if (!IsConnected)
throw new ServiceNotConnectedException ("The SmtpClient is not connected.");
var format = options.Clone ();
format.International = format.International || sender.IsInternational || recipients.Any (x => x.IsInternational);
format.HiddenHeaders.Add (HeaderId.ContentLength);
format.HiddenHeaders.Add (HeaderId.ResentBcc);
format.HiddenHeaders.Add (HeaderId.Bcc);
format.NewLineFormat = NewLineFormat.Dos;
if (format.International && (Capabilities & SmtpCapabilities.UTF8) == 0)
throw new NotSupportedException ("The SMTP server does not support the SMTPUTF8 extension.");
if (format.International && (Capabilities & SmtpCapabilities.EightBitMime) == 0)
throw new NotSupportedException ("The SMTP server does not support the 8BITMIME extension.");
// prepare the message
if ((Capabilities & SmtpCapabilities.BinaryMime) != 0)
message.Prepare (EncodingConstraint.None, MaxLineLength);
else if ((Capabilities & SmtpCapabilities.EightBitMime) != 0)
message.Prepare (EncodingConstraint.EightBit, MaxLineLength);
else
message.Prepare (EncodingConstraint.SevenBit, MaxLineLength);
// figure out which SMTP extensions we need to use
var visitor = new ContentTransferEncodingVisitor (capabilities);
visitor.Visit (message);
var extensions = visitor.SmtpExtensions;
if (format.International)
extensions |= SmtpExtension.UTF8;
try {
// Note: if PIPELINING is supported, MailFrom() and RcptTo() will
// queue their commands instead of sending them immediately.
MailFrom (message, sender, extensions, cancellationToken);
var unique = new HashSet<string> (StringComparer.OrdinalIgnoreCase);
foreach (var recipient in recipients) {
if (unique.Add (recipient.Address))
RcptTo (message, recipient, cancellationToken);
}
// Note: if PIPELINING is supported, this will flush all outstanding
// MAIL FROM and RCPT TO commands to the server and then process all
// of their responses.
FlushCommandQueue (sender, recipients, cancellationToken);
if ((extensions & SmtpExtension.BinaryMime) != 0)
Bdat (format, message, cancellationToken, progress);
else
Data (format, message, cancellationToken, progress);
} catch (ServiceNotAuthenticatedException) {
// do not disconnect
throw;
} catch (SmtpCommandException) {
Reset (cancellationToken);
throw;
} catch {
Disconnect ();
throw;
}
}