本文整理汇总了C#中MimeKit.FormatOptions类的典型用法代码示例。如果您正苦于以下问题:C# FormatOptions类的具体用法?C# FormatOptions怎么用?C# FormatOptions使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
FormatOptions类属于MimeKit命名空间,在下文中一共展示了FormatOptions类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: FormatOptions
static FormatOptions()
{
Default = new FormatOptions ();
Default.MaxLineLength = 72;
Default.WriteHeaders = true;
if (Environment.NewLine.Length == 1)
Default.NewLineFormat = NewLineFormat.Unix;
else
Default.NewLineFormat = NewLineFormat.Dos;
}
示例2: WordBreak
static IEnumerable<BrokenWord> WordBreak (FormatOptions format, string word, int lineLength)
{
var chars = word.ToCharArray ();
int startIndex = 0;
lineLength = Math.Max (lineLength, 1);
while (startIndex < word.Length) {
int length = Math.Min (format.MaxLineLength - lineLength, word.Length);
if (char.IsSurrogatePair (word, startIndex + length - 1))
length--;
yield return new BrokenWord (chars, startIndex, length);
startIndex += length;
lineLength = 1;
}
yield break;
}
示例3: ImapCommand
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapCommand"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="MailKit.Net.Imap.ImapCommand"/>.
/// </remarks>
/// <param name="engine">The IMAP engine that will be sending the command.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="folder">The IMAP folder that the command operates on.</param>
/// <param name="options">The formatting options.</param>
/// <param name="format">The command format.</param>
/// <param name="args">The command arguments.</param>
public ImapCommand (ImapEngine engine, CancellationToken cancellationToken, ImapFolder folder, FormatOptions options, string format, params object[] args)
{
UntaggedHandlers = new Dictionary<string, ImapUntaggedHandler> ();
RespCodes = new List<ImapResponseCode> ();
CancellationToken = cancellationToken;
Response = ImapCommandResponse.None;
Status = ImapCommandStatus.Created;
Engine = engine;
Folder = folder;
using (var builder = new MemoryStream ()) {
var plus = (Engine.Capabilities & ImapCapabilities.LiteralPlus) != 0 ? "+" : string.Empty;
int argc = 0;
byte[] buf;
string str;
char c;
for (int i = 0; i < format.Length; i++) {
if (format[i] == '%') {
switch (format[++i]) {
case '%': // a literal %
builder.WriteByte ((byte) '%');
break;
case 'c': // a character
c = (char) args[argc++];
builder.WriteByte ((byte) c);
break;
case 'd': // an integer
str = ((int) args[argc++]).ToString ();
buf = Encoding.ASCII.GetBytes (str);
builder.Write (buf, 0, buf.Length);
break;
case 'u': // an unsigned integer
str = ((uint) args[argc++]).ToString ();
buf = Encoding.ASCII.GetBytes (str);
builder.Write (buf, 0, buf.Length);
break;
case 'F': // an ImapFolder
var utf7 = ((ImapFolder) args[argc++]).EncodedName;
AppendString (options, true, builder, utf7);
break;
case 'L':
var literal = new ImapLiteral (options, args[argc++], UpdateProgress);
var length = literal.Length;
totalSize += length;
if (options.International)
str = "UTF8 (~{" + length + plus + "}\r\n";
else
str = "{" + length + plus + "}\r\n";
buf = Encoding.ASCII.GetBytes (str);
builder.Write (buf, 0, buf.Length);
parts.Add (new ImapCommandPart (builder.ToArray (), literal));
builder.SetLength (0);
if (options.International)
builder.WriteByte ((byte) ')');
break;
case 'S': // a string which may need to be quoted or made into a literal
AppendString (options, true, builder, (string) args[argc++]);
break;
case 'Q': // similar to %S but string must be quoted at a minimum
AppendString (options, false, builder, (string) args[argc++]);
break;
case 's': // a safe atom string
buf = Encoding.ASCII.GetBytes ((string) args[argc++]);
builder.Write (buf, 0, buf.Length);
break;
default:
throw new FormatException ();
}
} else {
builder.WriteByte ((byte) format[i]);
}
}
parts.Add (new ImapCommandPart (builder.ToArray (), null));
}
}
示例4: Encode
internal abstract void Encode(FormatOptions options, StringBuilder builder, ref int lineLength);
示例5: 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);
//.........这里部分代码省略.........
示例6: WriteTo
/// <summary>
/// Writes the <see cref="MimeKit.MessagePart"/> to the output stream.
/// </summary>
/// <param name="options">The formatting options.</param>
/// <param name="stream">The output 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="stream"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.OperationCanceledException">
/// The operation was canceled via the cancellation token.
/// </exception>
/// <exception cref="System.IO.IOException">
/// An I/O error occurred.
/// </exception>
public override void WriteTo(FormatOptions options, Stream stream, CancellationToken cancellationToken)
{
base.WriteTo (options, stream, cancellationToken);
if (Message != null)
Message.WriteTo (options, stream, cancellationToken);
}
示例7: 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);
}
}
示例8: Clone
/// <summary>
/// Clones an instance of <see cref="MimeKit.FormatOptions"/>.
/// </summary>
public FormatOptions Clone()
{
var options = new FormatOptions ();
options.MaxLineLength = MaxLineLength;
options.NewLineFormat = NewLineFormat;
options.WriteHeaders = true;
return options;
}
示例9: 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);
}
示例10: 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);
}
}
示例11: 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);
}
示例12: 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);
}
示例13: Fold
internal static string Fold (FormatOptions format, string field, string value)
{
var folded = new StringBuilder (value.Length);
int lineLength = field.Length + 2;
int lastLwsp = -1;
folded.Append (' ');
var words = TokenizeText (value);
foreach (var word in words) {
if (IsWhiteSpace (word[0])) {
if (lineLength + word.Length > format.MaxLineLength) {
for (int i = 0; i < word.Length; i++) {
if (lineLength > format.MaxLineLength) {
folded.Append (format.NewLine);
lineLength = 0;
}
folded.Append (word[i]);
lineLength++;
}
} else {
lineLength += word.Length;
folded.Append (word);
}
lastLwsp = folded.Length - 1;
continue;
}
if (lastLwsp != -1 && lineLength + word.Length > format.MaxLineLength) {
folded.Insert (lastLwsp, format.NewLine);
lineLength = 1;
lastLwsp = -1;
}
if (word.Length > format.MaxLineLength) {
foreach (var broken in WordBreak (format, word, lineLength)) {
if (lineLength + broken.Length > format.MaxLineLength) {
folded.Append (format.NewLine);
folded.Append (' ');
lineLength = 1;
}
folded.Append (broken.Text, broken.StartIndex, broken.Length);
lineLength += broken.Length;
}
} else {
lineLength += word.Length;
folded.Append (word);
}
}
folded.Append (format.NewLine);
return folded.ToString ();
}
示例14: DkimWriteHeaders
void DkimWriteHeaders (FormatOptions options, IList<string> fields, DkimCanonicalizationAlgorithm headerCanonicalizationAlgorithm, Stream stream)
{
var counts = new Dictionary<string, int> ();
Header header;
for (int i = 0; i < fields.Count; i++) {
var name = fields[i].ToLowerInvariant ();
int index, count, n = 0;
if (!counts.TryGetValue (name, out count))
count = 0;
// Note: signers choosing to sign an existing header field that occurs more
// than once in the message (such as Received) MUST sign the physically last
// instance of that header field in the header block. Signers wishing to sign
// multiple instances of such a header field MUST include the header field
// name multiple times in the list of header fields and MUST sign such header
// fields in order from the bottom of the header field block to the top.
index = Headers.LastIndexOf (name);
// find the n'th header with this name
while (n < count && --index >= 0) {
if (Headers[index].Field.Equals (name, StringComparison.OrdinalIgnoreCase))
n++;
}
if (index < 0)
continue;
header = Headers[index];
switch (headerCanonicalizationAlgorithm) {
case DkimCanonicalizationAlgorithm.Relaxed:
DkimWriteHeaderRelaxed (options, stream, header);
break;
default:
DkimWriteHeaderSimple (options, stream, header);
break;
}
counts[name] = ++count;
}
}
示例15: FormatOptions
static FormatOptions ()
{
Default = new FormatOptions ();
}