本文整理汇总了C#中MimeKit.IO.FilteredStream.Flush方法的典型用法代码示例。如果您正苦于以下问题:C# FilteredStream.Flush方法的具体用法?C# FilteredStream.Flush怎么用?C# FilteredStream.Flush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MimeKit.IO.FilteredStream
的用法示例。
在下文中一共展示了FilteredStream.Flush方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestBase64Encode
public void TestBase64Encode ()
{
using (var original = new MemoryStream ()) {
using (var file = File.OpenRead ("../../TestData/encoders/photo.b64"))
file.CopyTo (original, 4096);
using (var encoded = new MemoryStream ()) {
using (var filtered = new FilteredStream (encoded)) {
filtered.Add (EncoderFilter.Create (ContentEncoding.Base64));
using (var file = File.OpenRead ("../../TestData/encoders/photo.jpg"))
file.CopyTo (filtered, 4096);
filtered.Flush ();
}
var buf0 = original.GetBuffer ();
var buf1 = encoded.GetBuffer ();
int n = (int) original.Length;
Assert.AreEqual (original.Length, encoded.Length, "Encoded length is incorrect.");
for (int i = 0; i < n; i++)
Assert.AreEqual (buf0[i], buf1[i], "The byte at offset {0} does not match.", i);
}
}
}
示例2: WriteTo
/// <summary>
/// Writes the <see cref="MimeKit.MimePart"/> to the specified stream.
/// </summary>
/// <param name="options">The formatting options.</param>
/// <param name="stream">The stream.</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>
public override void WriteTo(FormatOptions options, Stream stream)
{
base.WriteTo (options, stream);
if (ContentObject == null)
return;
if (ContentObject.Encoding != encoding) {
if (encoding == ContentEncoding.UUEncode) {
var begin = string.Format ("begin 0644 {0}", FileName ?? "unknown");
var buffer = Encoding.UTF8.GetBytes (begin);
stream.Write (buffer, 0, buffer.Length);
stream.Write (options.NewLineBytes, 0, options.NewLineBytes.Length);
}
// transcode the content into the desired Content-Transfer-Encoding
using (var filtered = new FilteredStream (stream)) {
filtered.Add (EncoderFilter.Create (encoding));
filtered.Add (options.CreateNewLineFilter ());
ContentObject.DecodeTo (filtered);
filtered.Flush ();
}
if (encoding == ContentEncoding.UUEncode) {
var buffer = Encoding.ASCII.GetBytes ("end");
stream.Write (buffer, 0, buffer.Length);
stream.Write (options.NewLineBytes, 0, options.NewLineBytes.Length);
}
} else {
using (var filtered = new FilteredStream (stream)) {
filtered.Add (options.CreateNewLineFilter ());
ContentObject.WriteTo (filtered);
filtered.Flush ();
}
}
}
示例3: WriteTo
/// <summary>
/// Writes the message to the specified output stream.
/// </summary>
/// <remarks>
/// Writes the message to the output stream using the provided formatting options.
/// </remarks>
/// <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 void WriteTo (FormatOptions options, Stream stream, CancellationToken cancellationToken = default (CancellationToken))
{
if (options == null)
throw new ArgumentNullException ("options");
if (stream == null)
throw new ArgumentNullException ("stream");
if (version == null && Body != null && Body.Headers.Count > 0)
MimeVersion = new Version (1, 0);
if (Body != null) {
using (var filtered = new FilteredStream (stream)) {
filtered.Add (options.CreateNewLineFilter ());
foreach (var header in MergeHeaders ()) {
if (options.HiddenHeaders.Contains (header.Id))
continue;
filtered.Write (header.RawField, 0, header.RawField.Length, cancellationToken);
filtered.Write (new [] { (byte) ':' }, 0, 1, cancellationToken);
filtered.Write (header.RawValue, 0, header.RawValue.Length, cancellationToken);
}
filtered.Flush (cancellationToken);
}
var cancellable = stream as ICancellableStream;
if (cancellable != null) {
cancellable.Write (options.NewLineBytes, 0, options.NewLineBytes.Length, cancellationToken);
} else {
cancellationToken.ThrowIfCancellationRequested ();
stream.Write (options.NewLineBytes, 0, options.NewLineBytes.Length);
}
try {
Body.Headers.Suppress = true;
Body.WriteTo (options, stream, cancellationToken);
} finally {
Body.Headers.Suppress = false;
}
} else {
Headers.WriteTo (options, stream, cancellationToken);
}
}
示例4: Sign
//.........这里部分代码省略.........
/// <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);
break;
}
filtered.Flush ();
}
signature = stream.GenerateSignature ();
dkim.Value += Convert.ToBase64String (signature);
}
}
示例5: Create
/// <summary>
/// Creates a new <see cref="MultipartSigned"/>.
/// </summary>
/// <remarks>
/// Cryptographically signs the entity using the supplied signer in order
/// to generate a detached signature and then adds the entity along with
/// the detached signature data to a new multipart/signed part.
/// </remarks>
/// <returns>A new <see cref="MultipartSigned"/> instance.</returns>
/// <param name="ctx">The S/MIME context to use for signing.</param>
/// <param name="signer">The signer.</param>
/// <param name="entity">The entity to sign.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="ctx"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="signer"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="Org.BouncyCastle.Cms.CmsException">
/// An error occurred in the cryptographic message syntax subsystem.
/// </exception>
public static MultipartSigned Create (SecureMimeContext ctx, CmsSigner signer, MimeEntity entity)
{
if (ctx == null)
throw new ArgumentNullException ("ctx");
if (signer == null)
throw new ArgumentNullException ("signer");
if (entity == null)
throw new ArgumentNullException ("entity");
PrepareEntityForSigning (entity);
using (var memory = new MemoryBlockStream ()) {
using (var filtered = new FilteredStream (memory)) {
// Note: see rfc3156, section 3 - second note
filtered.Add (new ArmoredFromFilter ());
// Note: see rfc3156, section 5.4 (this is the main difference between rfc2015 and rfc3156)
filtered.Add (new TrailingWhitespaceFilter ());
// Note: see rfc2015 or rfc3156, section 5.1
filtered.Add (new Unix2DosFilter ());
entity.WriteTo (filtered);
filtered.Flush ();
}
memory.Position = 0;
// Note: we need to parse the modified entity structure to preserve any modifications
var parser = new MimeParser (memory, MimeFormat.Entity);
var parsed = parser.ParseEntity ();
memory.Position = 0;
// sign the cleartext content
var micalg = ctx.GetDigestAlgorithmName (signer.DigestAlgorithm);
var signature = ctx.Sign (signer, memory);
var signed = new MultipartSigned ();
// set the protocol and micalg Content-Type parameters
signed.ContentType.Parameters["protocol"] = ctx.SignatureProtocol;
signed.ContentType.Parameters["micalg"] = micalg;
// add the modified/parsed entity as our first part
signed.Add (parsed);
// add the detached signature as the second part
signed.Add (signature);
return signed;
}
}
示例6: DecodeTo
/// <summary>
/// Decodes the content stream into another stream.
/// </summary>
/// <remarks>
/// Uses the <see cref="Encoding"/> to decode the content stream to the output stream.
/// </remarks>
/// <param name="stream">The output stream.</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <exception cref="System.ArgumentNullException">
/// <paramref name="stream"/> is <c>null</c>.
/// </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 void DecodeTo(Stream stream, CancellationToken cancellationToken)
{
if (stream == null)
throw new ArgumentNullException ("stream");
using (var filtered = new FilteredStream (stream)) {
filtered.Add (DecoderFilter.Create (Encoding));
WriteTo (filtered, cancellationToken);
filtered.Flush ();
}
}
示例7: GetBestEncoding
/// <summary>
/// Calculates the most efficient content encoding given the specified constraint.
/// </summary>
/// <remarks>
/// If no <see cref="ContentObject"/> is set, <see cref="ContentEncoding.SevenBit"/> will be returned.
/// </remarks>
/// <returns>The most efficient content encoding.</returns>
/// <param name="constraint">The encoding constraint.</param>
/// <param name="maxLineLength">The maximum allowable length for a line (not counting the CRLF). Must be between <c>72</c> and <c>998</c> (inclusive).</param>
/// <param name="cancellationToken">A cancellation token.</param>
/// <exception cref="System.ArgumentOutOfRangeException">
/// <para><paramref name="maxLineLength"/> is not between <c>72</c> and <c>998</c> (inclusive).</para>
/// <para>-or-</para>
/// <para><paramref name="constraint"/> is not a valid value.</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 ContentEncoding GetBestEncoding (EncodingConstraint constraint, int maxLineLength, CancellationToken cancellationToken = default (CancellationToken))
{
if (ContentObject == null)
return ContentEncoding.SevenBit;
using (var measure = new MeasuringStream ()) {
using (var filtered = new FilteredStream (measure)) {
var filter = new BestEncodingFilter ();
filtered.Add (filter);
ContentObject.DecodeTo (filtered, cancellationToken);
filtered.Flush ();
return filter.GetBestEncoding (constraint, maxLineLength);
}
}
}
示例8: TestUUEncode
public void TestUUEncode ()
{
using (var original = new MemoryStream ()) {
using (var file = File.OpenRead ("../../TestData/encoders/photo.uu"))
file.CopyTo (original, 4096);
using (var encoded = new MemoryStream ()) {
var begin = Encoding.ASCII.GetBytes ("begin 644 photo.jpg");
var eol = FormatOptions.Default.NewLineBytes;
var end = Encoding.ASCII.GetBytes ("end");
encoded.Write (begin, 0, begin.Length);
encoded.Write (eol, 0, eol.Length);
using (var filtered = new FilteredStream (encoded)) {
filtered.Add (EncoderFilter.Create (ContentEncoding.UUEncode));
using (var file = File.OpenRead ("../../TestData/encoders/photo.jpg"))
file.CopyTo (filtered, 4096);
filtered.Flush ();
}
encoded.Write (end, 0, end.Length);
encoded.Write (eol, 0, eol.Length);
var buf0 = original.GetBuffer ();
var buf1 = encoded.GetBuffer ();
int n = (int) original.Length;
Assert.AreEqual (original.Length, encoded.Length, "Encoded length is incorrect.");
for (int i = 0; i < n; i++)
Assert.AreEqual (buf0[i], buf1[i], "The byte at offset {0} does not match.", i);
}
}
}
示例9: ExtractAttachments
static void ExtractAttachments (TnefReader reader, BodyBuilder builder)
{
var attachMethod = TnefAttachMethod.ByValue;
var filter = new BestEncodingFilter ();
var prop = reader.TnefPropertyReader;
MimePart attachment = null;
int outIndex, outLength;
TnefAttachFlags flags;
string[] mimeType;
byte[] attachData;
string text;
do {
if (reader.AttributeLevel != TnefAttributeLevel.Attachment)
break;
switch (reader.AttributeTag) {
case TnefAttributeTag.AttachRenderData:
attachMethod = TnefAttachMethod.ByValue;
attachment = new MimePart ();
break;
case TnefAttributeTag.Attachment:
if (attachment == null)
break;
while (prop.ReadNextProperty ()) {
switch (prop.PropertyTag.Id) {
case TnefPropertyId.AttachLongFilename:
attachment.FileName = prop.ReadValueAsString ();
break;
case TnefPropertyId.AttachFilename:
if (attachment.FileName == null)
attachment.FileName = prop.ReadValueAsString ();
break;
case TnefPropertyId.AttachContentLocation:
text = prop.ReadValueAsString ();
if (Uri.IsWellFormedUriString (text, UriKind.Absolute))
attachment.ContentLocation = new Uri (text, UriKind.Absolute);
else if (Uri.IsWellFormedUriString (text, UriKind.Relative))
attachment.ContentLocation = new Uri (text, UriKind.Relative);
break;
case TnefPropertyId.AttachContentBase:
text = prop.ReadValueAsString ();
attachment.ContentBase = new Uri (text, UriKind.Absolute);
break;
case TnefPropertyId.AttachContentId:
attachment.ContentId = prop.ReadValueAsString ();
break;
case TnefPropertyId.AttachDisposition:
text = prop.ReadValueAsString ();
if (attachment.ContentDisposition == null)
attachment.ContentDisposition = new ContentDisposition (text);
else
attachment.ContentDisposition.Disposition = text;
break;
case TnefPropertyId.AttachData:
var stream = prop.GetRawValueReadStream ();
var content = new MemoryStream ();
var guid = new byte[16];
if (attachMethod == TnefAttachMethod.EmbeddedMessage) {
var tnef = new TnefPart ();
foreach (var param in attachment.ContentType.Parameters)
tnef.ContentType.Parameters[param.Name] = param.Value;
if (attachment.ContentDisposition != null)
tnef.ContentDisposition = attachment.ContentDisposition;
attachment = tnef;
}
// read the GUID
stream.Read (guid, 0, 16);
// the rest is content
using (var filtered = new FilteredStream (content)) {
filtered.Add (filter);
stream.CopyTo (filtered, 4096);
filtered.Flush ();
}
content.Position = 0;
attachment.ContentTransferEncoding = filter.GetBestEncoding (EncodingConstraint.SevenBit);
attachment.ContentObject = new ContentObject (content);
filter.Reset ();
builder.Attachments.Add (attachment);
break;
case TnefPropertyId.AttachMethod:
attachMethod = (TnefAttachMethod) prop.ReadValueAsInt32 ();
break;
case TnefPropertyId.AttachMimeTag:
mimeType = prop.ReadValueAsString ().Split ('/');
if (mimeType.Length == 2) {
attachment.ContentType.MediaType = mimeType[0].Trim ();
attachment.ContentType.MediaSubtype = mimeType[1].Trim ();
}
break;
//.........这里部分代码省略.........
示例10: DkimHashBody
byte[] DkimHashBody (FormatOptions options, DkimSignatureAlgorithm signatureAlgorithm, DkimCanonicalizationAlgorithm bodyCanonicalizationAlgorithm, int maxLength)
{
using (var stream = new DkimHashStream (signatureAlgorithm, maxLength)) {
using (var filtered = new FilteredStream (stream)) {
DkimBodyFilter dkim;
if (bodyCanonicalizationAlgorithm == DkimCanonicalizationAlgorithm.Relaxed)
dkim = new DkimRelaxedBodyFilter ();
else
dkim = new DkimSimpleBodyFilter ();
filtered.Add (options.CreateNewLineFilter ());
filtered.Add (dkim);
if (Body != null) {
try {
Body.EnsureNewLine = compliance == RfcComplianceMode.Strict;
Body.Headers.Suppress = true;
Body.WriteTo (options, filtered, CancellationToken.None);
} finally {
Body.Headers.Suppress = false;
Body.EnsureNewLine = false;
}
}
filtered.Flush ();
if (!dkim.LastWasNewLine)
stream.Write (options.NewLineBytes, 0, options.NewLineBytes.Length);
}
return stream.GenerateHash ();
}
}
示例11: WriteTo
/// <summary>
/// Writes the message to the specified stream.
/// </summary>
/// <param name="options">The formatting options.</param>
/// <param name="stream">The stream.</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>
public void WriteTo(FormatOptions options, Stream stream)
{
if (options == null)
throw new ArgumentNullException ("options");
if (stream == null)
throw new ArgumentNullException ("stream");
if (!Headers.Contains ("Date"))
Date = DateTimeOffset.Now;
if (messageId == null)
MessageId = MimeUtils.GenerateMessageId ();
if (version == null && Body != null && Body.Headers.Count > 0)
MimeVersion = new Version (1, 0);
if (Body == null) {
Headers.WriteTo (stream);
stream.Write (options.NewLineBytes, 0, options.NewLineBytes.Length);
} else {
using (var filtered = new FilteredStream (stream)) {
filtered.Add (options.CreateNewLineFilter ());
foreach (var header in MergeHeaders ()) {
var name = Encoding.ASCII.GetBytes (header.Field);
filtered.Write (name, 0, name.Length);
filtered.WriteByte ((byte) ':');
filtered.Write (header.RawValue, 0, header.RawValue.Length);
}
filtered.Flush ();
}
options.WriteHeaders = false;
Body.WriteTo (options, stream);
}
}
示例12: TestImapClientGMail
public void TestImapClientGMail ()
{
var commands = new List<ImapReplayCommand> ();
commands.Add (new ImapReplayCommand ("", "gmail.greeting.txt"));
commands.Add (new ImapReplayCommand ("A00000000 CAPABILITY\r\n", "gmail.capability.txt"));
commands.Add (new ImapReplayCommand ("A00000001 AUTHENTICATE PLAIN AHVzZXJuYW1lAHBhc3N3b3Jk\r\n", "gmail.authenticate.txt"));
commands.Add (new ImapReplayCommand ("A00000002 NAMESPACE\r\n", "gmail.namespace.txt"));
commands.Add (new ImapReplayCommand ("A00000003 LIST \"\" \"INBOX\"\r\n", "gmail.list-inbox.txt"));
commands.Add (new ImapReplayCommand ("A00000004 XLIST \"\" \"*\"\r\n", "gmail.xlist.txt"));
commands.Add (new ImapReplayCommand ("A00000005 LIST \"\" \"%\"\r\n", "gmail.list-personal.txt"));
commands.Add (new ImapReplayCommand ("A00000006 CREATE UnitTests\r\n", "gmail.create-unittests.txt"));
commands.Add (new ImapReplayCommand ("A00000007 LIST \"\" UnitTests\r\n", "gmail.list-unittests.txt"));
commands.Add (new ImapReplayCommand ("A00000008 SELECT UnitTests (CONDSTORE)\r\n", "gmail.select-unittests.txt"));
for (int i = 0; i < 50; i++) {
using (var stream = new MemoryStream ()) {
using (var resource = GetResourceStream (string.Format ("common.message.{0}.msg", i))) {
using (var filtered = new FilteredStream (stream)) {
filtered.Add (new Unix2DosFilter ());
resource.CopyTo (filtered, 4096);
filtered.Flush ();
}
stream.Position = 0;
}
var message = MimeMessage.Load (stream);
long length = stream.Length;
string latin1;
stream.Position = 0;
using (var reader = new StreamReader (stream, Latin1))
latin1 = reader.ReadToEnd ();
var command = string.Format ("A{0:D8} APPEND UnitTests (\\Seen) ", i + 9);
command += "{" + length + "}\r\n";
commands.Add (new ImapReplayCommand (command, "gmail.go-ahead.txt"));
commands.Add (new ImapReplayCommand (latin1 + "\r\n", string.Format ("gmail.append.{0}.txt", i + 1)));
}
}
commands.Add (new ImapReplayCommand ("A00000059 UID SEARCH RETURN () CHARSET US-ASCII OR TO nsb CC nsb\r\n", "gmail.search.txt"));
commands.Add (new ImapReplayCommand ("A00000060 UID FETCH 1:3,5,7:9,11:14,26:29,31,34,41:43,50 (UID FLAGS INTERNALDATE RFC822.SIZE ENVELOPE BODY)\r\n", "gmail.search-summary.txt"));
commands.Add (new ImapReplayCommand ("A00000061 UID FETCH 1 (BODY.PEEK[])\r\n", "gmail.fetch.1.txt"));
commands.Add (new ImapReplayCommand ("A00000062 UID FETCH 2 (BODY.PEEK[])\r\n", "gmail.fetch.2.txt"));
commands.Add (new ImapReplayCommand ("A00000063 UID FETCH 3 (BODY.PEEK[])\r\n", "gmail.fetch.3.txt"));
commands.Add (new ImapReplayCommand ("A00000064 UID FETCH 5 (BODY.PEEK[])\r\n", "gmail.fetch.5.txt"));
commands.Add (new ImapReplayCommand ("A00000065 UID FETCH 7 (BODY.PEEK[])\r\n", "gmail.fetch.7.txt"));
commands.Add (new ImapReplayCommand ("A00000066 UID FETCH 8 (BODY.PEEK[])\r\n", "gmail.fetch.8.txt"));
commands.Add (new ImapReplayCommand ("A00000067 UID FETCH 9 (BODY.PEEK[])\r\n", "gmail.fetch.9.txt"));
commands.Add (new ImapReplayCommand ("A00000068 UID FETCH 11 (BODY.PEEK[])\r\n", "gmail.fetch.11.txt"));
commands.Add (new ImapReplayCommand ("A00000069 UID FETCH 12 (BODY.PEEK[])\r\n", "gmail.fetch.12.txt"));
commands.Add (new ImapReplayCommand ("A00000070 UID FETCH 13 (BODY.PEEK[])\r\n", "gmail.fetch.13.txt"));
commands.Add (new ImapReplayCommand ("A00000071 UID FETCH 14 (BODY.PEEK[])\r\n", "gmail.fetch.14.txt"));
commands.Add (new ImapReplayCommand ("A00000072 UID FETCH 26 (BODY.PEEK[])\r\n", "gmail.fetch.26.txt"));
commands.Add (new ImapReplayCommand ("A00000073 UID FETCH 27 (BODY.PEEK[])\r\n", "gmail.fetch.27.txt"));
commands.Add (new ImapReplayCommand ("A00000074 UID FETCH 28 (BODY.PEEK[])\r\n", "gmail.fetch.28.txt"));
commands.Add (new ImapReplayCommand ("A00000075 UID FETCH 29 (BODY.PEEK[])\r\n", "gmail.fetch.29.txt"));
commands.Add (new ImapReplayCommand ("A00000076 UID FETCH 31 (BODY.PEEK[])\r\n", "gmail.fetch.31.txt"));
commands.Add (new ImapReplayCommand ("A00000077 UID FETCH 34 (BODY.PEEK[])\r\n", "gmail.fetch.34.txt"));
commands.Add (new ImapReplayCommand ("A00000078 UID FETCH 41 (BODY.PEEK[])\r\n", "gmail.fetch.41.txt"));
commands.Add (new ImapReplayCommand ("A00000079 UID FETCH 42 (BODY.PEEK[])\r\n", "gmail.fetch.42.txt"));
commands.Add (new ImapReplayCommand ("A00000080 UID FETCH 43 (BODY.PEEK[])\r\n", "gmail.fetch.43.txt"));
commands.Add (new ImapReplayCommand ("A00000081 UID FETCH 50 (BODY.PEEK[])\r\n", "gmail.fetch.50.txt"));
commands.Add (new ImapReplayCommand ("A00000082 UID STORE 1:3,5,7:9,11:14,26:29,31,34,41:43,50 FLAGS (\\Answered \\Seen)\r\n", "gmail.set-flags.txt"));
commands.Add (new ImapReplayCommand ("A00000083 UID STORE 1:3,5,7:9,11:14,26:29,31,34,41:43,50 -FLAGS.SILENT (\\Answered)\r\n", "gmail.remove-flags.txt"));
commands.Add (new ImapReplayCommand ("A00000084 UID STORE 1:3,5,7:9,11:14,26:29,31,34,41:43,50 +FLAGS.SILENT (\\Deleted)\r\n", "gmail.add-flags.txt"));
commands.Add (new ImapReplayCommand ("A00000085 UNSELECT\r\n", "gmail.unselect-unittests.txt"));
commands.Add (new ImapReplayCommand ("A00000086 DELETE UnitTests\r\n", "gmail.delete-unittests.txt"));
commands.Add (new ImapReplayCommand ("A00000087 LOGOUT\r\n", "gmail.logout.txt"));
using (var client = new ImapClient ()) {
try {
client.ReplayConnect ("localhost", new ImapReplayStream (commands, false), CancellationToken.None);
} catch (Exception ex) {
Assert.Fail ("Did not expect an exception in Connect: {0}", ex);
}
Assert.IsTrue (client.IsConnected, "Client failed to connect.");
Assert.AreEqual (GMailInitialCapabilities, client.Capabilities);
Assert.AreEqual (4, client.AuthenticationMechanisms.Count);
Assert.IsTrue (client.AuthenticationMechanisms.Contains ("XOAUTH"), "Expected SASL XOAUTH auth mechanism");
Assert.IsTrue (client.AuthenticationMechanisms.Contains ("XOAUTH2"), "Expected SASL XOAUTH2 auth mechanism");
Assert.IsTrue (client.AuthenticationMechanisms.Contains ("PLAIN"), "Expected SASL PLAIN auth mechanism");
Assert.IsTrue (client.AuthenticationMechanisms.Contains ("PLAIN-CLIENTTOKEN"), "Expected SASL PLAIN-CLIENTTOKEN auth mechanism");
try {
var credentials = new NetworkCredential ("username", "password");
// Note: Do not try XOAUTH2
client.AuthenticationMechanisms.Remove ("XOAUTH2");
client.Authenticate (credentials, CancellationToken.None);
} catch (Exception ex) {
Assert.Fail ("Did not expect an exception in Authenticate: {0}", ex);
}
Assert.AreEqual (GMailAuthenticatedCapabilities, client.Capabilities);
//.........这里部分代码省略.........
示例13: Convert
/// <summary>
/// Converts the contents of <paramref name="source"/> from the <see cref="InputFormat"/> to the
/// <see cref="OutputFormat"/> and writes the resulting text to <paramref name="destination"/>.
/// </summary>
/// <remarks>
/// Converts the contents of <paramref name="source"/> from the <see cref="InputFormat"/> to the
/// <see cref="OutputFormat"/> and writes the resulting text to <paramref name="destination"/>.
/// </remarks>
/// <param name="source">The source stream.</param>
/// <param name="destination">The destination stream.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="source"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="destination"/> is <c>null</c>.</para>
/// </exception>
public void Convert (Stream source, Stream destination)
{
if (source == null)
throw new ArgumentNullException ("source");
if (destination == null)
throw new ArgumentNullException ("destination");
using (var filtered = new FilteredStream (destination)) {
filtered.Add (this);
source.CopyTo (filtered, 4096);
filtered.Flush ();
}
}
示例14: ExtractMapiProperties
private void ExtractMapiProperties(TnefReader reader, MimeMessage message, BodyBuilder builder)
{
var tnefPropertyReader = reader.TnefPropertyReader;
while (tnefPropertyReader.ReadNextProperty())
{
switch (tnefPropertyReader.PropertyTag.Id)
{
case TnefPropertyId.RtfCompressed:
var memoryStream = new MemoryStream();
if (tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.String8 || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Unicode || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Binary)
{
var textPart = new TextPart("rtf");
textPart.ContentType.Name = "body.rtf";
RtfCompressedToRtf rtfCompressedToRtf = new RtfCompressedToRtf();
//var memoryStream = new MemoryStream();
using (var filteredStream = new FilteredStream(memoryStream))
{
filteredStream.Add(rtfCompressedToRtf);
using (Stream rawValueReadStream = tnefPropertyReader.GetRawValueReadStream())
{
rawValueReadStream.CopyTo(filteredStream, 4096);
filteredStream.Flush();
}
}
textPart.ContentObject = new ContentObject(memoryStream, ContentEncoding.Default);
memoryStream.Position = 0L;
builder.Attachments.Add(textPart);
continue;
}
memoryStream.Dispose();
continue;
case TnefPropertyId.BodyHtml:
if (tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.String8 || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Unicode || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Binary)
{
var textPart = new TextPart("html");
textPart.ContentType.Name = "body.html";
textPart.Text = tnefPropertyReader.ReadValueAsString();
builder.Attachments.Add(textPart);
continue;
}
continue;
case TnefPropertyId.InternetMessageId:
if (tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.String8 || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Unicode)
{
message.MessageId = tnefPropertyReader.ReadValueAsString();
continue;
}
continue;
case TnefPropertyId.Subject:
if (tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.String8 || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Unicode)
{
message.Subject = tnefPropertyReader.ReadValueAsString();
continue;
}
continue;
case TnefPropertyId.Body:
if (tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.String8 || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Unicode || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Binary)
{
var textPart = new TextPart("plain");
textPart.ContentType.Name = "body.txt";
textPart.Text = tnefPropertyReader.ReadValueAsString();
builder.Attachments.Add(textPart);
continue;
}
continue;
case TnefPropertyId.ConversationTopic:
if (tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.String8 || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Unicode)
{
message.Subject = tnefPropertyReader.ReadValueAsString();
continue;
}
continue;
case TnefPropertyId.SenderName:
if (tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.String8 || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Unicode)
{
var sender = new MailboxAddress(string.Empty, tnefPropertyReader.ReadValueAsString());
message.Sender = sender;
}
continue;
case (TnefPropertyId)Mapi.ID.PR_PRIMARY_SEND_ACCOUNT:
if (tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.String8 || tnefPropertyReader.PropertyTag.ValueTnefType == TnefPropertyType.Unicode)
{
var senderEmail = new MailboxAddress(string.Empty, tnefPropertyReader.ReadValueAsString());
message.Sender = senderEmail;
}
continue;
default:
try
{
tnefPropertyReader.ReadValue();
continue;
//.........这里部分代码省略.........
示例15: Create
/// <summary>
/// Creates a new <see cref="MultipartEncrypted"/>.
/// </summary>
/// <remarks>
/// Encrypts the entity to the specified recipients, encapsulating the result in a
/// new multipart/encrypted part.
/// </remarks>
/// <returns>A new <see cref="MimeKit.Cryptography.MultipartEncrypted"/> instance containing
/// the encrypted version of the specified entity.</returns>
/// <param name="ctx">The OpenPGP cryptography context to use for encrypting.</param>
/// <param name="recipients">The recipients for the encrypted entity.</param>
/// <param name="entity">The entity to sign and encrypt.</param>
/// <exception cref="System.ArgumentNullException">
/// <para><paramref name="ctx"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="recipients"/> is <c>null</c>.</para>
/// <para>-or-</para>
/// <para><paramref name="entity"/> is <c>null</c>.</para>
/// </exception>
/// <exception cref="System.ArgumentException">
/// One or more of the recipient keys cannot be used for encrypting.
/// </exception>
public static MultipartEncrypted Create (OpenPgpContext ctx, IEnumerable<PgpPublicKey> recipients, MimeEntity entity)
{
if (ctx == null)
throw new ArgumentNullException ("ctx");
if (recipients == null)
throw new ArgumentNullException ("recipients");
if (entity == null)
throw new ArgumentNullException ("entity");
using (var memory = new MemoryStream ()) {
using (var filtered = new FilteredStream (memory)) {
filtered.Add (new Unix2DosFilter ());
PrepareEntityForEncrypting (entity);
entity.WriteTo (filtered);
filtered.Flush ();
}
memory.Position = 0;
var encrypted = new MultipartEncrypted ();
encrypted.ContentType.Parameters["protocol"] = ctx.EncryptionProtocol;
// add the protocol version part
encrypted.Add (new ApplicationPgpEncrypted ());
// add the encrypted entity as the second part
encrypted.Add (ctx.Encrypt (recipients, memory));
return encrypted;
}
}