Git Product home page Git Product logo

jstedfast / mimekit Goto Github PK

View Code? Open in Web Editor NEW
1.8K 90.0 360.0 36.44 MB

A .NET MIME creation and parser library with support for S/MIME, PGP, DKIM, TNEF and Unix mbox spools.

Home Page: http://www.mimekit.net

License: MIT License

C# 77.15% Shell 0.01% HTML 22.71% Batchfile 0.01% PowerShell 0.08% Rich Text Format 0.04% Dockerfile 0.01%
c-sharp email mime parser mime-parser mbox pgp smime dkim tnef

mimekit's Introduction

MimeKit

Package Latest Release Latest Build
MimeKit NuGet Badge MimeKit MyGet Badge MimeKit
MimeKitLite NuGet Badge MimeKitLite
Platform Build Status Code Coverage Static Analysis
Linux/Mac Build Status Code Coverage Static Analysis
Windows Build Status Code Coverage Static Analysis

What is MimeKit?

MimeKit is a C# library which may be used for the creation and parsing of messages using the Multipurpose Internet Mail Extension (MIME), as defined by numerous IETF specifications.

Donate

MimeKit is a personal open source project that I have put thousands of hours into perfecting with the goal of making it the very best MIME parser framework for .NET. I need your help to achieve this.

Donating helps pay for things such as web hosting, domain registration and licenses for developer tools such as a performance profiler, memory profiler, a static code analysis tool, and more. It also helps motivate me to continue working on the project.

Click here to lend your support to MimeKit by making a donation!

History

As a developer and user of email clients, I had come to realize that the vast majority of email client (and server) software had less-than-satisfactory MIME implementations. More often than not these email clients created broken MIME messages and/or would incorrectly try to parse a MIME message thus subtracting from the full benefits that MIME was meant to provide. MimeKit is meant to address this issue by following the MIME specification as closely as possible while also providing programmers with an extremely easy to use high-level API.

This led me, at first, to implement another MIME parser library called GMime which is implemented in C and later added a C# binding called GMime-Sharp.

Now that I typically find myself working in C# rather than lower level languages like C, I decided to begin writing a new parser in C# which would not depend on GMime. This would also allow me to have more flexibility in that I'd be able to use Generics and create a more .NET-compliant API.

Performance

While mainstream beliefs may suggest that C# can never be as fast as C, it turns out that with a bit of creative parser design and a few clever optimizations [1] [2], MimeKit's performance is actually on par with GMime.

Since GMime is pretty well-known as a high-performance native MIME parser and MimeKit more-or-less matches GMime's performance, it stands to reason that MimeKit is likely unsurpassed in performance in the .NET MIME parser space.

For a comparison, as I blogged here (I have since optimized MimeKit by at least another 30%), MimeKit is more than 25x faster than OpenPOP.NET, 75x faster than SharpMimeTools, and 65x faster than regex-based parsers. Even the commercial MIME parser offerings such as LimiLabs' Mail.dll and NewtonIdeas' Mime4Net cannot even come close to matching MimeKit's performance (they are both orders of magnitude slower than MimeKit).

For comparison purposes, I've published a MIME parser benchmark to make it easier for anyone else to compare the performance of MimeKit to their favourite MIME parser.

Here are the results:

Parsing startrek.msg (1000 iterations):
MimeKit:        0.6989221 seconds
OpenPop:        25.3056064 seconds
AE.Net.Mail:    17.5971438 seconds
MailSystem.NET: 26.3891218 seconds
MIMER:          76.4538978 seconds

Parsing xamarin3.msg (1000 iterations):
MimeKit:        3.4215505 seconds
OpenPop:        159.3308053 seconds
AE.Net.Mail:    132.3044291 seconds
MailSystem.NET: 133.5832078 seconds
MIMER:          784.433441 seconds

How does your MIME parser compare?

License Information

MIT License

Copyright (C) 2012-2024 .NET Foundation and Contributors

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.

Installing via NuGet

The easiest way to install MimeKit is via NuGet.

In Visual Studio's Package Manager Console, enter the following command:

Install-Package MimeKit

Getting the Source Code

First, you'll need to clone MimeKit from my GitHub repository. To do this using the command-line version of Git, you'll need to issue the following command in your terminal:

git clone --recursive https://github.com/jstedfast/MimeKit.git

If you are using TortoiseGit on Windows, you'll need to right-click in the directory where you'd like to clone MimeKit and select Git Clone... in the menu. Once you do that, you'll get the following dialog:

Download the source code using TortoiseGit

Fill in the areas outlined in red and then click OK. This will recursively clone MimeKit onto your local machine.

Updating the Source Code

Occasionally you might want to update your local copy of the source code if I have made changes to MimeKit since you downloaded the source code in the step above. To do this using the command-line version fo Git, you'll need to issue the following commands in your terminal within the MimeKit directory:

git pull
git submodule update

If you are using TortoiseGit on Windows, you'll need to right-click on the MimeKit directory and select Git Sync... in the menu. Once you do that, you'll need to click the Pull and Submodule Update buttons in the following dialog:

Update the source code using TortoiseGit

Building

In the top-level MimeKit directory, there are a number of solution files; they are:

  • MimeKit.sln - includes projects for .NET Framework 4.6.2/4.7/4.8, .NETStandard 2.0/2.1, .NET 6.0 as well as the unit tests.
  • MimeKitLite.sln - includes projects for the stripped-down versions of MimeKit that drop support for crypto.

Once you've opened the appropriate MimeKit solution file in Visual Studio, you can choose the Debug or Release build configuration and then build.

Both Visual Studio 2022 and Visual Studio 2019 should be able to build MimeKit without any issues, but older versions such as Visual Studio 2015 and 2017 will require modifications to the projects in order to build correctly. It has been reported that adding NuGet package references to Microsoft.Net.Compilers >= 3.6.0 and System.ValueTuple >= 4.5.0 will allow MimeKit to build successfully.

Note: The Release build will generate the xml API documentation, but the Debug build will not.

Using MimeKit

Parsing Messages

One of the more common operations that MimeKit is meant for is parsing email messages from arbitrary streams. There are two ways of accomplishing this task.

The first way is to use one of the Load methods on MimeMessage:

// Load a MimeMessage from a stream
var message = MimeMessage.Load (stream);

Or you can load a message from a file path:

// Load a MimeMessage from a file path
var message = MimeMessage.Load ("message.eml");

The second way is to use the MimeParser class. For the most part, using the MimeParser directly is not necessary unless you wish to parse a Unix mbox file stream. However, this is how you would do it:

// Load a MimeMessage from a stream
var parser = new MimeParser (stream, MimeFormat.Entity);
var message = parser.ParseMessage ();

For Unix mbox file streams, you would use the parser like this:

// Load every message from a Unix mbox
var parser = new MimeParser (stream, MimeFormat.Mbox);
while (!parser.IsEndOfStream) {
    var message = parser.ParseMessage ();

    // do something with the message
}

Getting the Body of a Message

A common misunderstanding about email is that there is a well-defined message body and then a list of attachments. This is not really the case. The reality is that MIME is a tree structure of content, much like a file system.

Luckily, MIME does define a set of general rules for how mail clients should interpret this tree structure of MIME parts. The Content-Disposition header is meant to provide hints to the receiving client as to which parts are meant to be displayed as part of the message body and which are meant to be interpreted as attachments.

The Content-Disposition header will generally have one of two values: inline or attachment.

The meaning of these values should be fairly obvious. If the value is attachment, then the content of said MIME part is meant to be presented as a file attachment separate from the core message. However, if the value is inline, then the content of that MIME part is meant to be displayed inline within the mail client's rendering of the core message body. If the Content-Disposition header does not exist, then it should be treated as if the value were inline.

Technically, every part that lacks a Content-Disposition header or that is marked as inline, then, is part of the core message body.

There's a bit more to it than that, though.

Modern MIME messages will often contain a multipart/alternative MIME container which will generally contain a text/plain and text/html version of the text that the sender wrote. The text/html version is typically formatted much closer to what the sender saw in his or her WYSIWYG editor than the text/plain version.

The reason for sending the message text in both formats is that not all mail clients are capable of displaying HTML.

The receiving client should only display one of the alternative views contained within the multipart/alternative container. Since alternative views are listed in order of least faithful to most faithful with what the sender saw in his or her WYSIWYG editor, the receiving client should walk over the list of alternative views starting at the end and working backwards until it finds a part that it is capable of displaying.

Example:

multipart/alternative
  text/plain
  text/html

As seen in the example above, the text/html part is listed last because it is the most faithful to what the sender saw in his or her WYSIWYG editor when writing the message.

To make matters even more complicated, sometimes modern mail clients will use a multipart/related MIME container instead of a simple text/html part in order to embed images and other content within the HTML.

Example:

multipart/alternative
  text/plain
  multipart/related
    text/html
    image/jpeg
    video/mp4
    image/png

In the example above, one of the alternative views is a multipart/related container which contains an HTML version of the message body that references the sibling video and images.

Now that you have a rough idea of how a message is structured and how to interpret various MIME entities, the next step is learning how to traverse the MIME tree using MimeKit.

Note: For your convenience, MimeKit's MimeMessage class has two properties that can help you get the text/plain or text/html version of the message body. These are TextBody and HtmlBody, respectively.

Keep in mind, however, that at least with the HtmlBody property, it may be that the HTML part is a child of a multipart/related, allowing it to refer to images and other types of media that are also contained within that multipart/related entity. This property is really only a convenience property and is not a really good substitute for traversing the MIME structure yourself so that you may properly interpret related content.

Traversing a MimeMessage

The MimeMessage.Body is the top-level MIME entity of the message. Generally, it will either be a TextPart or a Multipart.

As an example, if you wanted to rip out all of the attachments of a message, your code might look something like this:

var attachments = new List<MimePart> ();
var multiparts = new List<Multipart> ();
var iter = new MimeIterator (message);

// collect our list of attachments and their parent multiparts
while (iter.MoveNext ()) {
    var multipart = iter.Parent as Multipart;
    var part = iter.Current as MimePart;

    if (multipart != null && part != null && part.IsAttachment) {
        // keep track of each attachment's parent multipart
        multiparts.Add (multipart);
        attachments.Add (part);
    }
}

// now remove each attachment from its parent multipart...
for (int i = 0; i < attachments.Count; i++)
    multiparts[i].Remove (attachments[i]);

Quick and Dirty Enumeration of Message Body Parts

If you would rather skip the proper way of traversing a MIME tree, another option that MimeKit provides is a simple enumerator over the message's body parts in a flat (depth-first) list.

You can access this flat list via the BodyParts property, like so:

foreach (var part in message.BodyParts) {
   // do something
}

Another helper property on the MimeMessage class is the Attachments property which works much the same way as the BodyParts property except that it will only contain MIME parts which have a Content-Disposition header value that is set to attachment.

Getting the Decoded Content of a MIME Part

At some point, you're going to want to extract the decoded content of a MimePart (such as an image) and save it to disk or feed it to a UI control to display it.

Once you've found the MimePart object that you'd like to extract the content of, here's how you can save the decoded content to a file:

// This will get the name of the file as specified by the sending mail client.
// Note: this value *may* be null, so you'll want to handle that case in your code.
var fileName = part.FileName;

using (var stream = File.Create (fileName)) {
    part.Content.DecodeTo (stream);
}

You can also get access to the original raw content by "opening" the Content. This might be useful if you want to pass the content off to a UI control that can do its own loading from a stream.

using (var stream = part.Content.Open ()) {
    // At this point, you can now read from the stream as if it were the original,
    // raw content. Assuming you have an image UI control that could load from a
    // stream, you could do something like this:
    imageControl.Load (stream);
}

There are a number of useful filters that can be applied to a FilteredStream, so if you find this type of interface appealing, I suggest taking a look at the available filters in the MimeKit.IO.Filters namespace or even write your own! The possibilities are limited only by your imagination.

Creating a Simple Message

Creating MIME messages using MimeKit is really trivial.

var message = new MimeMessage ();
message.From.Add (new MailboxAddress ("Joey", "[email protected]"));
message.To.Add (new MailboxAddress ("Alice", "[email protected]"));
message.Subject = "How you doin?";

message.Body = new TextPart ("plain") {
    Text = @"Hey Alice,

What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.

Will you be my +1?

-- Joey
"
};

A TextPart is a leaf-node MIME part with a text media-type. The first argument to the TextPart constructor specifies the media-subtype, in this case, "plain". Another media subtype you are probably familiar with is the "html" subtype. Some other examples include "enriched", "rtf", and "csv".

The Text property is the easiest way to both get and set the string content of the MIME part.

Creating a Message with Attachments

Attachments are just like any other MimePart, the only difference is that they typically have a Content-Disposition header with a value of "attachment" instead of "inline" or no Content-Disposition header at all.

Typically, when a mail client adds attachments to a message, it will create a multipart/mixed part and add the text body part and all of the file attachments to the multipart/mixed.

Here's how you can do that with MimeKit:

var message = new MimeMessage ();
message.From.Add (new MailboxAddress ("Joey", "[email protected]"));
message.To.Add (new MailboxAddress ("Alice", "[email protected]"));
message.Subject = "How you doin?";

// create our message text, just like before (except don't set it as the message.Body)
var body = new TextPart ("plain") {
    Text = @"Hey Alice,

What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.

Will you be my +1?

-- Joey
"
};

// create an image attachment for the file located at path
var attachment = new MimePart ("image", "gif") {
    Content = new MimeContent (File.OpenRead (path), ContentEncoding.Default),
    ContentDisposition = new ContentDisposition (ContentDisposition.Attachment),
    ContentTransferEncoding = ContentEncoding.Base64,
    FileName = Path.GetFileName (path)
};

// now create the multipart/mixed container to hold the message text and the
// image attachment
var multipart = new Multipart ("mixed");
multipart.Add (body);
multipart.Add (attachment);

// now set the multipart/mixed as the message body
message.Body = multipart;

Of course, that is just a simple example. A lot of modern mail clients such as Outlook or Thunderbird will send out both a text/html and a text/plain version of the message text. To do this, you'd create a TextPart for the text/plain part and another TextPart for the text/html part and then add them to a multipart/alternative like so:

var attachment = CreateAttachment ();
var plain = CreateTextPlainPart ();
var html = CreateTextHtmlPart ();

// Note: it is important that the text/html part is added second, because it is the
// most expressive version and (probably) the most faithful to the sender's WYSIWYG 
// editor.
var alternative = new Multipart ("alternative");
alternative.Add (plain);
alternative.Add (html);

// now create the multipart/mixed container to hold the multipart/alternative
// and the image attachment
var multipart = new Multipart ("mixed");
multipart.Add (alternative);
multipart.Add (attachment);

// now set the multipart/mixed as the message body
message.Body = multipart;

Creating a Message Using a BodyBuilder (not Arnold Schwarzenegger)

If you are used to System.Net.Mail's API for creating messages, you will probably find using a BodyBuilder much more friendly than manually creating the tree of MIME parts. Here's how you could create a message body using a BodyBuilder:

var message = new MimeMessage ();
message.From.Add (new MailboxAddress ("Joey", "[email protected]"));
message.To.Add (new MailboxAddress ("Alice", "[email protected]"));
message.Subject = "How you doin?";

var builder = new BodyBuilder ();

// Set the plain-text version of the message text
builder.TextBody = @"Hey Alice,

What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.

Will you be my +1?

-- Joey
";

// generate a Content-Id for the image we'll be referencing
var contentId = MimeUtils.GenerateMessageId ();

// Set the html version of the message text
builder.HtmlBody = string.Format (@"<p>Hey Alice,<br>
<p>What are you up to this weekend? Monica is throwing one of her parties on
Saturday and I was hoping you could make it.<br>
<p>Will you be my +1?<br>
<p>-- Joey<br>
<center><img src=""cid:{0}"" alt=""selfie.jpg""></center>", contentId);

// Since selfie.jpg is referenced from the html text, we'll need to add it
// to builder.LinkedResources and then set the Content-Id header value
builder.LinkedResources.Add (@"C:\Users\Joey\Documents\Selfies\selfie.jpg");
builder.LinkedResources[0].ContentId = contentId;

// We may also want to attach a calendar event for Monica's party...
builder.Attachments.Add (@"C:\Users\Joey\Documents\party.ics");

// Now we just need to set the message body and we're done
message.Body = builder.ToMessageBody ();

Preparing to use MimeKit's S/MIME support

Before you can begin using MimeKit's S/MIME support, you will need to decide which database to use for certificate storage.

If you are targetting any of the Xamarin platforms (or Linux), you won't need to do anything (although you certainly can if you want to) because, by default, I've configured MimeKit to use the Mono.Data.Sqlite binding to SQLite.

If you are on any of the Windows platforms, however, you'll need to decide on whether to use one of the conveniently available backends such as the WindowsSecureMimeContext backend or the TemporarySecureMimeContext backend or else you'll need to pick a System.Data provider such as System.Data.SQLite to use with the DefaultSecureMimeContext base class.

If you opt for using the DefaultSecureMimeContext backend, you'll need to implement your own DefaultSecureMimeContext subclass. Luckily, it's very simple to do. Assuming you've chosen System.Data.SQLite, here's how you'd implement your own DefaultSecureMimeContext class:

using System.Data.SQLite;
using MimeKit.Cryptography;

using MyAppNamespace {
    class MySecureMimeContext : DefaultSecureMimeContext
    {
        public MySecureMimeContext () : base (OpenDatabase ("C:\\wherever\\certdb.sqlite"))
        {
        }

        static IX509CertificateDatabase OpenDatabase (string fileName)
        {
            var builder = new SQLiteConnectionStringBuilder ();
            builder.DateTimeFormat = SQLiteDateFormats.Ticks;
            builder.DataSource = fileName;

            if (!File.Exists (fileName))
                SQLiteConnection.CreateFile (fileName);

            var sqlite = new SQLiteConnection (builder.ConnectionString);
            sqlite.Open ();

            return new SqliteCertificateDatabase (sqlite, "password");
        }
    }
}

Now that you've implemented your own SecureMimeContext, you'll want to register it with MimeKit:

CryptographyContext.Register (typeof (MySecureMimeContext));

Now you are ready to encrypt, decrypt, sign and verify S/MIME messages!

Note: If you choose to use the WindowsSecureMimeContext or TemporarySecureMimeContext backend, you should register that class instead.

Preparing to use MimeKit's PGP/MIME support

Like with S/MIME support, you also need to register your own OpenPgpContext. Unlike S/MIME, however, you don't need to choose a database if you subclass GnuPGContext because it uses GnuPG's PGP keyrings to load and store public and private keys. If you choose to subclass GnuPGContext, the only thing you you need to do is implement a password callback method:

using MimeKit.Cryptography;

namespace MyAppNamespace {
    class MyGnuPGContext : GnuPGContext
    {
        public MyGnuPgContext () : base ()
        {
        }

        protected override string GetPasswordForKey (PgpSecretKey key)
        {
            // prompt the user (or a secure password cache) for the password for the specified secret key.
            return "password";
        }
    }
}

Once again, to register your OpenPgpContext, you can use the following code snippet:

CryptographyContext.Register (typeof (MyGnuPGContext));

Now you are ready to encrypt, decrypt, sign and verify PGP/MIME messages!

Encrypting Messages with S/MIME

S/MIME uses an application/pkcs7-mime MIME part to encapsulate encrypted content (as well as other things).

var joey = new MailboxAddress ("Joey", "[email protected]");
var alice = new MailboxAddress ("Alice", "[email protected]");

var message = new MimeMessage ();
message.From.Add (joey);
message.To.Add (alice);
message.Subject = "How you doin?";

// create our message body (perhaps a multipart/mixed with the message text and some
// image attachments, for example)
var body = CreateMessageBody ();

// now to encrypt our message body using our custom S/MIME cryptography context
using (var ctx = new MySecureMimeContext ()) {
    // Note: this assumes that "Alice" has an S/MIME certificate with an X.509
    // Subject Email identifier that matches her email address. If she doesn't,
    // try using a SecureMailboxAddress which allows you to specify the
    // fingerprint of her certificate to use for lookups.
    message.Body = ApplicationPkcs7Mime.Encrypt (ctx, message.To.Mailboxes, body);
}

Decrypting S/MIME Messages

As mentioned earlier, S/MIME uses an application/pkcs7-mime part with an "smime-type" parameter with a value of "enveloped-data" to encapsulate the encrypted content.

The first thing you must do is find the ApplicationPkcs7Mime part (see the section on traversing MIME parts).

if (entity is ApplicationPkcs7Mime) {
    var pkcs7 = (ApplicationPkcs7Mime) entity;

    if (pkcs7.SecureMimeType == SecureMimeType.EnvelopedData)
        return pkcs7.Decrypt ();
}

Encrypting Messages with PGP/MIME

Unlike S/MIME, PGP/MIME uses multipart/encrypted to encapsulate its encrypted data.

var joey = new MailboxAddress ("Joey", "[email protected]");
var alice = new MailboxAddress ("Alice", "[email protected]");

var message = new MimeMessage ();
message.From.Add (joey);
message.To.Add (alice);
message.Subject = "How you doin?";

// create our message body (perhaps a multipart/mixed with the message text and some
// image attachments, for example)
var body = CreateMessageBody ();

// now to encrypt our message body using our custom PGP/MIME cryptography context
using (var ctx = new MyGnuPGContext ()) {
    // Note: this assumes that "Alice" has a public PGP key that matches her email
    // address. If she doesn't, try using a SecureMailboxAddress which allows you
    // to specify the fingerprint of her public PGP key to use for lookups.
    message.Body = MultipartEncrypted.Encrypt (ctx, message.To.Mailboxes, body);
}

Decrypting PGP/MIME Messages

As mentioned earlier, PGP/MIME uses a multipart/encrypted part to encapsulate the encrypted content.

A multipart/encrypted contains exactly 2 parts: the first MimeEntity is the version information while the second MimeEntity is the actual encrypted content and will typically be an application/octet-stream.

The first thing you must do is find the MultipartEncrypted part (see the section on traversing MIME parts).

if (entity is MultipartEncrypted) {
    var encrypted = (MultipartEncrypted) entity;

    return encrypted.Decrypt ();
}

Digitally Signing Messages with S/MIME or PGP/MIME

Both S/MIME and PGP/MIME use a multipart/signed to contain the signed content and the detached signature data.

Here's how you might digitally sign a message using S/MIME:

var joey = new MailboxAddress ("Joey", "[email protected]");
var alice = new MailboxAddress ("Alice", "[email protected]");

var message = new MimeMessage ();
message.From.Add (joey);
message.To.Add (alice);
message.Subject = "How you doin?";

// create our message body (perhaps a multipart/mixed with the message text and some
// image attachments, for example)
var body = CreateMessageBody ();

// now to digitally sign our message body using our custom S/MIME cryptography context
using (var ctx = new MySecureMimeContext ()) {
    // Note: this assumes that "Joey" has an S/MIME signing certificate and private key
    // with an X.509 Subject Email identifier that matches Joey's email address.
    message.Body = MultipartSigned.Create (ctx, joey, DigestAlgorithm.Sha1, body);
}

For S/MIME, if you have a way for the user to configure which S/MIME certificate to use as their signing certificate, you could also do something more like this:

// now to digitally sign our message body using our custom S/MIME cryptography context
using (var ctx = new MySecureMimeContext ()) {
    var certificate = GetJoeysX509Certificate ();
    var signer = new CmsSigner (certificate);
    signer.DigestAlgorithm = DigestAlgorithm.Sha1;

    message.Body = MultipartSigned.Create (ctx, signer, body);
}

If you'd prefer to use PGP instead of S/MIME, things work almost exactly the same except that you would use an OpenPGP cryptography context. For example, you might use a subclass of the GnuPGContext that comes with MimeKit if you want to re-use the user's GnuPG keyrings (you can't use GnuPGContext directly because it has no way of prompting the user for their passphrase).

For the sake of this example, let's pretend that you've written a minimal subclass of MimeKit.Cryptography.GnuPGContext that only overrides the GetPassword() method and that this subclass is called MyGnuPGContext.

// now to digitally sign our message body using our custom OpenPGP cryptography context
using (var ctx = new MyGnuPGContext ()) {
    // Note: this assumes that "Joey" has a PGP key that matches his email address.
    message.Body = MultipartSigned.Create (ctx, joey, DigestAlgorithm.Sha1, body);
}

Just like S/MIME, however, you can also do your own PGP key lookups instead of relying on email addresses to match up with the user's private key.

// now to digitally sign our message body using our custom OpenPGP cryptography context
using (var ctx = new MyGnuPGContext ()) {
    var key = GetJoeysPrivatePgpKey ();
    message.Body = MultipartSigned.Create (ctx, key, DigestAlgorithm.Sha1, body);
}

Verifying S/MIME and PGP/MIME Digital Signatures

As mentioned earlier, both S/MIME and PGP/MIME typically use a multipart/signed part to contain the signed content and the detached signature data.

A multipart/signed contains exactly 2 parts: the first MimeEntity is the signed content while the second MimeEntity is the detached signature and, by default, will either be an ApplicationPgpSignature part or an ApplicationPkcs7Signature part (depending on whether the sending client signed using OpenPGP or S/MIME).

Because the multipart/signed part may have been signed by multiple signers, it is important to verify each of the digital signatures (one for each signer) that are returned by the MultipartSigned.Verify() method:

if (entity is MultipartSigned) {
    var signed = (MultipartSigned) entity;

    foreach (var signature in signed.Verify ()) {
        try {
            bool valid = signature.Verify ();

            // If valid is true, then it signifies that the signed content has not been
            // modified since this particular signer signed the content.
            //
            // However, if it is false, then it indicates that the signed content has
            // been modified.
        } catch (DigitalSignatureVerifyException) {
            // There was an error verifying the signature.
        }
    }
}

It should be noted, however, that while most S/MIME clients will use the preferred multipart/signed approach, it is possible that you may encounter an application/pkcs7-mime part with an "smime-type" parameter set to "signed-data". Luckily, MimeKit can handle this format as well:

if (entity is ApplicationPkcs7Mime) {
    var pkcs7 = (ApplicationPkcs7Mime) entity;

    if (pkcs7.SecureMimeType == SecureMimeType.SignedData) {
        // extract the original content and get a list of signatures
        MimeEntity extracted;

        // Note: if you are rendering the message, you'll want to render the
        // extracted mime part rather than the application/pkcs7-mime part.
        foreach (var signature in pkcs7.Verify (out extracted)) {
            try {
                bool valid = signature.Verify ();

                // If valid is true, then it signifies that the signed content has not
                // been modified since this particular signer signed the content.
                //
                // However, if it is false, then it indicates that the signed content
                // has been modified.
            } catch (DigitalSignatureVerifyException) {
                // There was an error verifying the signature.
            }
        }
    }
}

Signing Messages with DKIM

In addition to OpenPGP and S/MIME, MimeKit also supports DKIM signatures. To sign a message using DKIM, you'll first need a private key. In the following example, assume that the private key is saved in a file called privatekey.pem:

var headers = new HeaderId[] { HeaderId.From, HeaderId.Subject, HeaderId.Date };
var signer = new DkimSigner ("privatekey.pem", "example.com", "brisbane", DkimSignatureAlgorithm.RsaSha256) {
    HeaderCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple,
    BodyCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Simple,
    AgentOrUserIdentifier = "@eng.example.com",
    QueryMethod = "dns/txt",
};

// Prepare the message body to be sent over a 7bit transport (such as older versions of SMTP).
// Note: If the SMTP server you will be sending the message over supports the 8BITMIME extension,
// then you can use `EncodingConstraint.EightBit` instead.
message.Prepare (EncodingConstraint.SevenBit);

signer.Sign (message, headers);

As you can see, it's fairly straight forward.

Verifying DKIM Signatures

Verifying DKIM signatures is slightly more involved than creating them because you'll need to write a custom implementation of the IDkimPublicKeyLocator interface. Typically, this custom class will need to download the DKIM public keys via your chosen DNS library as they are requested by MimeKit during verification of DKIM signature headers.

Once you've implemented a custom IDkimPublicKeyLocator, verifying signatures is fairly trivial. Most of the work needed will be in the IDkimPublicKeyLocator implementation. As an example of how to implement this interface, here is one possible implementation using the Heijden.DNS library:

using System;
using System.IO;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;

using Heijden.DNS;

using Org.BouncyCastle.Crypto;

using MimeKit;
using MimeKit.Cryptography;

namespace DkimVerifierExample
{
    // Note: By using the DkimPublicKeyLocatorBase, we avoid having to parse the DNS TXT records
    // in order to get the public key ourselves.
    class DkimPublicKeyLocator : DkimPublicKeyLocatorBase
    {
        readonly Dictionary<string, AsymmetricKeyParameter> cache;
        readonly Resolver resolver;

        public DkimPublicKeyLocator ()
        {
            cache = new Dictionary<string, AsymmetricKeyParameter> ();

            resolver = new Resolver ("8.8.8.8") {
                TransportType = TransportType.Udp,
                UseCache = true,
                Retries = 3
            };
        }

        AsymmetricKeyParameter DnsLookup (string domain, string selector, CancellationToken cancellationToken)
        {
            var query = selector + "._domainkey." + domain;
            AsymmetricKeyParameter pubkey;

            // checked if we've already fetched this key
            if (cache.TryGetValue (query, out pubkey))
                return pubkey;

            // make a DNS query
            var response = resolver.Query (query, QType.TXT);
            var builder = new StringBuilder ();

            // combine the TXT records into 1 string buffer
            foreach (var record in response.RecordsTXT) {
                foreach (var text in record.TXT)
                    builder.Append (text);
            }

            var txt = builder.ToString ();

            // DkimPublicKeyLocatorBase provides us with this helpful method.
            pubkey = GetPublicKey (txt);

            cache.Add (query, pubkey);

            return pubkey;
        }

        public AsymmetricKeyParameter LocatePublicKey (string methods, string domain, string selector, CancellationToken cancellationToken = default (CancellationToken))
        {
            var methodList = methods.Split (new char[] { ':' }, StringSplitOptions.RemoveEmptyEntries);
            for (int i = 0; i < methodList.Length; i++) {
                if (methodList[i] == "dns/txt")
                    return DnsLookup (domain, selector, cancellationToken);
            }

            throw new NotSupportedException (string.Format ("{0} does not include any suported lookup methods.", methods));
        }

        public Task<AsymmetricKeyParameter> LocatePublicKeyAsync (string methods, string domain, string selector, CancellationToken cancellationToken = default (CancellationToken))
        {
            return Task.Run (() => {
                return LocatePublicKey (methods, domain, selector, cancellationToken);
            }, cancellationToken);
        }
    }

    class Program
    {
        public static void Main (string[] args)
        {
            if (args.Length == 0) {
                Help ();
                return;
            }

            for (int i = 0; i < args.Length; i++) {
                if (args[i] == "--help") {
                    Help ();
                    return;
                }
            }

            var locator = new DkimPublicKeyLocator ();
            var verifier = new DkimVerifier (locator);

            for (int i = 0; i < args.Length; i++) {
                if (!File.Exists (args[i])) {
                    Console.Error.WriteLine ("{0}: No such file.", args[i]);
                    continue;
                }

                Console.Write ("{0} -> ", args[i]);

                var message = MimeMessage.Load (args[i]);
                var index = message.Headers.IndexOf (HeaderId.DkimSignature);

                if (index == -1) {
                    Console.WriteLine ("NO SIGNATURE");
                    continue;
                }

                var dkim = message.Headers[index];

                if (verifier.Verify (message, dkim)) {
                    // the DKIM-Signature header is valid!
                    Console.ForegroundColor = ConsoleColor.Green;
                    Console.WriteLine ("VALID");
                    Console.ResetColor ();
                } else {
                    // the DKIM-Signature is invalid!
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine ("INVALID");
                    Console.ResetColor ();
                }
            }
        }

        static void Help ()
        {
            Console.WriteLine ("Usage is: DkimVerifier [options] [messages]");
            Console.WriteLine ();
            Console.WriteLine ("Options:");
            Console.WriteLine ("  --help               This help menu.");
        }
    }
}

Signing Messages with ARC

Signing with ARC is similar to DKIM but quite a bit more involved. In order to sign with ARC, you must first validate that the existing message is authentictic and produce an ARC-Authentication-Results header containing the methods that you used to authenticate the message as well as their results.

The abstract ArcSigner class provided by MimeKit will need to be subclassed before it can be used. An example subclass that provides 2 different implementations for generating the ARC-Authentication-Results header can be seen below:

using System;
using System.Linq;
using System.Threading;
using System.Threading.Tasks;
using System.Collections.Generic;

using MimeKit;
using MimeKit.Cryptography;

namespace ArcSignerExample
{
    class MyArcSigner : ArcSigner
    {
        public MyArcSigner (string fileName, string domain, string selector, DkimSigningAlgorithm algorithm = DkimSignatureAlgorithm.RsaSha256)
               : base (fileName, domain, selector, algorithm)
        {
        }

        /// <summary>
        /// Generate the ARC-Authentication-Results header.
        /// </summary>
        /// <remarks>
        /// The ARC-Authentication-Results header contains information detailing the results of
        /// authenticating/verifying the message via ARC, DKIM, SPF, etc.
        ///
        /// In the following implementation, we assume that all of these authentication results
        /// have already been determined by other mail software that has added some Authentication-Results
        /// headers containing this information.
        ///
        /// Note: This method is used when ArcSigner.Sign() is called instead of ArcSigner.SignAsync().
        /// </remarks>
        protected override AuthenticationResults GenerateArcAuthenticationResults (FormatOptions options, MimeMessage message, CancellationToken cancellationToken)
        {
            const string AuthenticationServiceIdentifier = "lists.example.com";

            var results = new AuthenticationResults (AuthenticationServiceIdentifier);

            for (int i = 0; i < message.Headers.Count; i++) {
                var header = message.Headers[i];

                if (header.Id != HeaderId.AuthenticationResults)
                    continue;

                if (!AuthenticationResults.TryParse (header.RawValue, out AuthenticationResults authres))
                    continue;

                if (authres.AuthenticationServiceIdentifier != AuthenticationServiceIdentifier)
                    continue;

                // Merge any authentication results that aren't already known.
                foreach (var result in authres.Results) {
                    if (!results.Results.Any (r => r.Method == result.Method))
                        results.Results.Add (result);
                }
            }

            return results;
        }

        /// <summary>
        /// Generate the ARC-Authentication-Results asynchronously.
        /// </summary>
        /// <remarks>
        /// The ARC-Authentication-Results header contains information detailing the results of
        /// authenticating/verifying the message via ARC, DKIM, SPF, etc.
        ///
        /// In the following implementation, we assume that we have to verify all of the various
        /// authentication methods ourselves.
        ///
        /// Note: This method is used when ArcSigner.SignAsync() is called instead of ArcSigner.Sign().
        /// </remarks>
        protected override async Task<AuthenticationResults> GenerateArcAuthenticationResultsAsync (FormatOptions options, MimeMessage message, CancellationToken cancellationToken)
        {
            const string AuthenticationServiceIdentifier = "lists.example.com";

            var results = new AuthenticationResults (AuthenticationServiceIdentifier);
            var locator = new DkimPublicKeyLocator (); // from the DKIM example above
            var dkimVerifier = new DkimVerifier (locator);
            var arcVerifier = new ArcVerifier (locator);
            AuthenticationMethodResult method;

            // Add the ARC authentication results
            try {
                var arc = await arcVerifier.VerifyAsync (message, cancellationToken);
                var result = arc.Chain.ToString ().ToLowerInvariant ();

                method = new AuthenticationMethodResult ("arc", result);
                results.Results.Add (method);
            } catch {
                // Likely a DNS error
                method = new AuthenticationMethodResult ("arc", "fail");
                method.Reason = "DNS error";
                results.Results.Add (method);
            }

            // Add authentication results for each DKIM signature
            foreach (var dkimHeader in message.Headers.Where (h => h.Id == HeaderId.DkimSignature)) {
                string result;

                try {
                    if (await dkimVerifier.VerifyAsync (message, cancellationToken)) {
                        result = "pass";
                    } else {
                        result = "fail";
                    }
                } catch {
                    result = "fail";
                }

                method = new AuthenticationMethodResult ("dkim", result);

                // Parse the DKIM-Signature header so that we can add some
                // properties to our method result.
                var params = dkimHeader.Value.Replace (" ", "").Split (new char[] { ';' });
                var i = params.FirstOrDefault (p => p.StartsWith ("i=", StringComparison.Ordinal));
                var b = params.FirstOrDefault (p => p.StartsWith ("b=", StringComparison.Ordinal));

                if (i != null)
                    method.Parameters.Add ("header.i", i.Substring (2));

                if (b != null)
                    method.Parameters.Add ("header.b", b.Substring (2, 8));

                results.Results.Add (method);
            }

            return results;
        }
    }
}

Once you have a custom ArcSigner class, the actual logic for signing is almost identical to DKIM.

Note: As with the DKIM signing example above, assume that the private key is saved in a file called privatekey.pem:

var headers = new HeaderId[] { HeaderId.From, HeaderId.Subject, HeaderId.Date };
var signer = new MyArcSigner ("privatekey.pem", "example.com", "brisbane", DkimSignatureAlgorithm.RsaSha256) {
    HeaderCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Relaxed,
    BodyCanonicalizationAlgorithm = DkimCanonicalizationAlgorithm.Relaxed,
    AgentOrUserIdentifier = "@eng.example.com"
};

// Prepare the message body to be sent over a 7bit transport (such as older versions of SMTP).
// Note: If the SMTP server you will be sending the message over supports the 8BITMIME extension,
// then you can use `EncodingConstraint.EightBit` instead.
message.Prepare (EncodingConstraint.SevenBit);

signer.Sign (message, headers); // or SignAsync

Verifying ARC Signatures

Just like with verifying DKIM signatures, you will need to implement the IDkimPublicKeyLocator interface. To see an example of how to implement this interface, see the DKIM signature verification example above.

The ArcVerifier works exactly the same as the DkimVerifier except that it is not necessary to provide a Header argument to the Verify or VerifyAsync method.

var verifier = new ArcVerifier (new DkimPublicKeyLocator ());
var results = await verifier.VerifyAsync (message);

// The Chain results are the only real important results.
Console.WriteLine ("ARC results: {0}", results.Chain);

Contributing

The first thing you'll need to do is fork MimeKit to your own GitHub repository. For instructions on how to do that, see the section titled Getting the Source Code.

If you use Visual Studio for Mac or MonoDevelop, all of the solution files are configured with the coding style used by MimeKit. If you use Visual Studio on Windows or some other editor, please try to maintain the existing coding style as best as you can.

Once you've got some changes that you'd like to submit upstream to the official MimeKit repository, send me a Pull Request and I will try to review your changes in a timely manner.

If you'd like to contribute but don't have any particular features in mind to work on, check out the issue tracker and look for something that might pique your interest!

Reporting Bugs

Have a bug or a feature request? Please open a new bug report or feature request.

Before opening a new issue, please search through any existing issues to avoid submitting duplicates. It may also be worth checking the FAQ for common questions that other developers have had.

If you are getting an exception from somewhere within MimeKit, don't just provide the Exception.Message string. Please include the Exception.StackTrace as well. The Message, by itself, is often useless.

Documentation

API documentation can be found at https://www.mimekit.net/docs.

A copy of the XML-formatted API reference documentation is also included in the NuGet package.

.NET Foundation

MimeKit is a .NET Foundation project.

This project has adopted the code of conduct defined by the Contributor Covenant to clarify expected behavior in our community. For more information, see the .NET Foundation Code of Conduct.

General .NET OSS discussions: .NET Foundation forums

mimekit's People

Contributors

aleks-ivanov avatar angelcolmenares avatar clairernovotny avatar d1mnewz avatar dependabot[bot] avatar fogzot avatar fredeil avatar fyodorklimenko avatar gitter-badger avatar hultqvist avatar humayun-ahmed avatar iamcarbon avatar jimbobsquarepants avatar jstedfast avatar jvitkauskas avatar kanekt avatar kingjan1999 avatar lisaj avatar marcbruins avatar migueldeicaza avatar naasking avatar orthographic-pedant avatar pekkah avatar peterdettman avatar princeoffoods avatar pvanhoof avatar rblackin avatar redth avatar swoga avatar vdaron avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mimekit's Issues

MimeKit.InternetAddress.TryParseMailbox fails with unknown CodePage

The main imap sample for MailKit fails with my email account. The error seems to come from the System.Text.GetEncoding for CodePage 51936, which is the codepage for Chinese Simplified (EUC). I guess mono doesnt seem to ship with i18n module which may have caused this to fail. Here is a full trace on Mac OSX:

Unhandled Exception:
System.NotSupportedException: CodePage 51936 not supported
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unknown>:0 
  at MimeKit.InternetAddress.TryParseMailbox (MimeKit.ParserOptions options, System.Byte[] text, Int32 startIndex, System.Int32& index, Int32 endIndex, System.String name, Int32 codepage, Boolean throwOnError, MimeKit.InternetAddress& address) [0x00000] in <filename unknown>:0 
  at MimeKit.InternetAddress.TryParse (MimeKit.ParserOptions options, System.Byte[] text, System.Int32& index, Int32 endIndex, Boolean throwOnError, MimeKit.InternetAddress& address) [0x00000] in <filename unknown>:0 
  at MimeKit.InternetAddressList.TryParse (MimeKit.ParserOptions options, System.Byte[] text, System.Int32& index, Int32 endIndex, Boolean isGroup, Boolean throwOnError, System.Collections.Generic.List`1& addresses) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeMessage.AddAddresses (MimeKit.Header header, MimeKit.InternetAddressList list) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeMessage.HeadersChanged (System.Object o, MimeKit.HeaderListChangedEventArgs e) [0x00000] in <filename unknown>:0 
  at MimeKit.HeaderList.OnChanged (MimeKit.Header header, HeaderListChangedAction action) [0x00000] in <filename unknown>:0 
  at MimeKit.HeaderList.Add (MimeKit.Header header) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeMessage..ctor (MimeKit.ParserOptions options, IEnumerable`1 headers) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeParser.ParseMessage (System.Byte* inbuf) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeParser.ParseMessage (CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeMessage.Load (MimeKit.ParserOptions options, System.IO.Stream stream, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeMessage.Load (System.IO.Stream stream, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
  at MailKit.Net.Imap.ImapFolder.GetMessage (Int32 index, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
  at TestClient.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 
[ERROR] FATAL UNHANDLED EXCEPTION: System.NotSupportedException: CodePage 51936 not supported
  at System.Text.Encoding.GetEncoding (Int32 codepage) [0x00000] in <filename unknown>:0 
  at MimeKit.InternetAddress.TryParseMailbox (MimeKit.ParserOptions options, System.Byte[] text, Int32 startIndex, System.Int32& index, Int32 endIndex, System.String name, Int32 codepage, Boolean throwOnError, MimeKit.InternetAddress& address) [0x00000] in <filename unknown>:0 
  at MimeKit.InternetAddress.TryParse (MimeKit.ParserOptions options, System.Byte[] text, System.Int32& index, Int32 endIndex, Boolean throwOnError, MimeKit.InternetAddress& address) [0x00000] in <filename unknown>:0 
  at MimeKit.InternetAddressList.TryParse (MimeKit.ParserOptions options, System.Byte[] text, System.Int32& index, Int32 endIndex, Boolean isGroup, Boolean throwOnError, System.Collections.Generic.List`1& addresses) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeMessage.AddAddresses (MimeKit.Header header, MimeKit.InternetAddressList list) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeMessage.HeadersChanged (System.Object o, MimeKit.HeaderListChangedEventArgs e) [0x00000] in <filename unknown>:0 
  at MimeKit.HeaderList.OnChanged (MimeKit.Header header, HeaderListChangedAction action) [0x00000] in <filename unknown>:0 
  at MimeKit.HeaderList.Add (MimeKit.Header header) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeMessage..ctor (MimeKit.ParserOptions options, IEnumerable`1 headers) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeParser.ParseMessage (System.Byte* inbuf) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeParser.ParseMessage (CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeMessage.Load (MimeKit.ParserOptions options, System.IO.Stream stream, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
  at MimeKit.MimeMessage.Load (System.IO.Stream stream, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
  at MailKit.Net.Imap.ImapFolder.GetMessage (Int32 index, CancellationToken cancellationToken) [0x00000] in <filename unknown>:0 
  at TestClient.Program.Main (System.String[] args) [0x00000] in <filename unknown>:0 

TNEF encoding / winmail.dat

Hello Jeff,

Is there any chance that support for decoding TNEF encoded messages will be added in the future or is this completely out of the scope of MimeKit?

Unseal Header and HeaderList

Header and/or HeaderList (probably both) need not to be sealed. I want to extend from HeaderList (probably), possibly also Header, in order to extend convenience properties to my application. Thank you...

WriteTo issue on a text/csv attachment

Hi Jeffrey,

I was giving MimeKit another shot today and it looks like you've made some great progress.

I was doing a small test run with a multipart/mixed containing a multipart/alternative (text/html & text/plain) and added a CSV file as attachment (text/csv). For some reason when I create the MimeMessage and use WriteTo, it discards the ContentDisposition set on the CSV file MimePart which also means the file won't be seen as an attachment. Only the ContentType is available in the headers when it's writing out the attachment.

When I changed the media/sub type to application/octet-stream then the ContentDisposition is included as expected.

Should all attachments media type be application/octet-stream? If not, I suspect the issue might be related to the 'text' media type.

Sorry I couldn't be of more help.

Kind regards,
Shelakel

MimeKit hangs when parsing specific emails

I am using MimeKit/MailKit to process hundreds of email replies daily that come from marketing emails. It works perfectly 99% of the time, but I have encountered several emails that hang MimeKit when it tries to parse the message. I have tracked this down to the ParseMessage function in the MimeParser, but I have no idea what is causing these messages to hang the parser. I can provide several emails that cause the parser to hang.

After decrypting I still get an ApplicationPkcs7Mime entity

Hi.

When I receive an email then I decrypt it using the TemporarySecureMimeContext like this:

private SecureMimeContext CreateSecureMimeContext(string certificateFilename, string certificatePassword)
        {
            var secureMimeContext = new TemporarySecureMimeContext();

            using (var stream = File.OpenRead(certificateFilename))
                secureMimeContext.Import(stream, certificatePassword);

            return secureMimeContext;
        }

var primarySecureMimeContext = CreateSecureMimeContext(certificateInfo.PrimaryCertificate,
                                                                       certificateInfo.PrimaryPassword);
                var primaryDecryptedEntity = entity.Decrypt(primarySecureMimeContext);
                EmailDistributer(primaryDecryptedEntity);

However the entity that is returned to EmailDistributer in this case is still an ApplicationPkcs7Mime even though it was decrypted correct. Am I missing a foreach here or something like that? Do you have any ideas?

It works for most mails, but a specific one is failing, which outlook can handle.

Issues encountered while testing out MIME message creation

Hi jstedfast,

I'm looking at using MimeKit for raw message creation for use for AWS SES SendRaw and similar API calls that allow sending 'raw e-mail' from multiple senders (SES, Mandrill, Sendgrid, Mailgun etc.).

Having read through most of the code, I must say the code is beautiful.

Here's some of the issues I've encountered constructing raw messages:

1. HeaderList - WriteTo

(https://github.com/jstedfast/MimeKit/blob/master/MimeKit/HeaderList.cs)

According to the RFC, a header value should end with \r\n. Currently the HeaderList appends all headers on one line.

2. InternetAddressList tests

The two following tests fail due to the escaping of the expected output, which can be fixed by folding with \r\n:

TestEncodingMailboxWithArabicName

=?utf-8?b?2YfZhCDYqtiq2YPZhNmFINin2YTZhNi62Kk=?=\r\n =?utf-8?b?INin2YTYpdmG2KzZhNmK2LLZitip?=\n =?utf-8?b?IC/Yp9mE2LnYsdio2YrYqdif?= [email protected]

TestEncodingMailboxWithJapaneseName

=?utf-8?b?54uC44Gj44Gf44GT44Gu5LiW44Gn54uC44GG44Gq44KJ5rCX?=\r\n =?utf-8?b?44Gv56K644GL44Gg44CC?= [email protected]

3. Base64Encoder is failing due to not large enough buffer allocated

At Multipart - GenerateBoundary (at Base64Encoder - Flush -> ValidateArguments); 32 bits is allocated to the output buffer but the estimated buffer length required is 73 bytes. I take it the 73 bytes is case specific, but still requires handling.

4. ContentObject - ContentEncoding

It doesn't make sense to specify the Content Transfer Encoding on the MimePart (as it applies to the content/body) as well as on the ContentObject (as ContentEncoding). It'd make more sense if the ContentObject contained the content and the ContentType as to supply parameters such as charset for text/*. Perhaps I'm wrong, but thought it worth mentioning.

5. Enable NuGet package restore

It would be nice if you could enable NuGet package restore so the necessary dependencies (ea. NUnit for the tests project) can be downloaded when building for the first time.

Overall it's looking great. I'll keep you updated with any issues I find.

Kind regards,
Shelakel

Allow multiple or pick the best alternate encoding for Content-Disposition parameters

Fixing issue #22 avoids crashing when parsing Content-Disposition headers sent by browsers when uploading content (e.g. multipart/form-data) but means that the first filename parameter is always chosen, which can be suboptimal.

Modern browsers will send a header like this:

Content-Disposition: ... filename=foo.txt; filename*=UTF-8''foo.txt; ...

The first parameter will be ASCII encoded, but the second may have a better encoding. Instead of blindly dropping subsequent parameters, they should either all be retained until parsing is complete and then pick the best one based on encoding, or replace previous parameters with subsequent ones.

At least in the case of browsers, the last option may work fine since they will always send the ASCII one first for compatibility.

It might be nice to retain everything though with the full name in the ParameterList and provide query logic to select by name or something.

I have a gist that fixed this specifically for the filename parameter before #22 was fixed:

https://gist.github.com/abock/91240f26ef40964fc388

See RFC 6266 Appendix D for recommended handling of filename parameters in Content-Disposition: http://tools.ietf.org/html/rfc6266#appendix-D

MimeKitLite (on NuGet) misses WP8 support

Thank you very much for this library. You've done a really good job by devloping framework. But I only need a very little subset of functionallity (stuff in Encoding and the Rfc2047 util, to encode MIME Headers) for my Windows Phone app.

While the NuGet package MimeKit supports Windows Universal packages, the MimeKitLite package doesn't. It would be great if you could fix that in the next release.

FIXME: validate the OnePass signatures

It should go like this i think.
Thats the way im doing it in an own decryption function.

if (onepassList != null && signatureList != null) {

        // There should be at least one OnePassSignature;
        PgpOnePassSignature ops = onepassList[0];
        // ops.KeyId contains the id of the key this data was signed with. 
        //One can get a public key via this id.
        PgpPublicKey key = ....
        // Init signature verification with the (found) public key.
        ops.InitVerify(key);
        // Update the one pass signature with decrypted data inside the memory stream.
        ops.Update(memory.ToArray());

        // Get the signature that was created when data was encrypted.
        PgpSignature firstSig = signatureList[0];

        //Verify (one pass) signature over the decrypted data against the "original" signature.
        if (!ops.Verify(firstSig))
                throw new Exception("Signature verification failed!");
}

sqllite.dll badimageformat

Hi jstedfast.

I do not really know whether this is an issue or a suggestion.
I have some trouble with switching between x64 and x86 because of the sqllite.dll. I have to run x86 on some projects in the solution, x64 on others and my unittest project has to cover them all. It is an issue, because it causes system.badimageformatexception quite often because of the sqllite.dll.
When I run it as x86 it works fine.

Is there any clever workaround?

System.BadImageFormatException : An attempt was made to load a program with an incorrect format. (Exception from HRESULT: 0x8007000B)
[18:46:59][Execute utest] at Mono.Data.Sqlite.UnsafeNativeMethods.sqlite3_open_v2(Byte[] utf8Filename, IntPtr& db, Int32 flags, IntPtr vfs)
[18:46:59][Execute utest] at Mono.Data.Sqlite.SQLite3.Open(String strFilename, SQLiteOpenFlagsEnum flags, Int32 maxPoolSize, Boolean usePool)
[18:46:59][Execute utest] at Mono.Data.Sqlite.SqliteConnection.Open()
[18:46:59][Execute utest] at MimeKit.Cryptography.DefaultSecureMimeContext..ctor(String fileName, String password)
[18:46:59][Execute utest] at MimeKit.Cryptography.CryptographyContext.Create(String protocol)
[18:46:59][Execute utest] at MimeKit.Cryptography.MultipartSigned.Verify()

Assigning the parsed "Content-Tranfer-Encoding" missing

Hello Jeffrey,

using your fine kit we have encountered a minor issue when decoding and writing streams out to disk. Thus we have changed the construction of MimePart in order to have a proper usage of ContentEncoding:

Your version:


public class MimePart : MimeEntity
{
static readonly string[] ContentTransferEncodings = new string[] {
null, "7bit", "8bit", "binary", "base64", "quoted-printable", "x-uuencode"
};
ContentEncoding encoding;
string content_md5;

    internal MimePart (ParserOptions options, ContentType type, IEnumerable<Header> headers, bool toplevel) : base (options, type, headers, toplevel)
    {
    }

Our changes:


public class MimePart : MimeEntity
{
private const string ENC_7BIT = "7bit";
private const string ENC_8BIT = "8bit";
private const string ENC_BINARY = "binary";
private const string ENC_BASE64 = "base64";
private const string ENC_QUOTED_PRINTABLE = "quoted-printable";
private const string ENC_UUENCODE = "x-uuencode";

    static readonly string[] ContentTransferEncodings = new string[] {
        null, ENC_7BIT, ENC_8BIT, ENC_BINARY, ENC_BASE64, ENC_QUOTED_PRINTABLE,ENC_UUENCODE
    };
    ContentEncoding encoding;
    string content_md5;

  ContentEncoding ParseEncoding(string enc_text)
  {
     ContentEncoding retval  =  ContentEncoding.Default;
     switch( enc_text.ToLowerInvariant() ){
        case ENC_7BIT:             retval = ContentEncoding.SevenBit;        break;
        case ENC_8BIT:             retval = ContentEncoding.EightBit;        break;
        case ENC_BINARY:           retval = ContentEncoding.Binary;          break;
        case ENC_BASE64:           retval = ContentEncoding.Base64;          break;
        case ENC_QUOTED_PRINTABLE: retval = ContentEncoding.QuotedPrintable; break;
        case ENC_UUENCODE:         retval = ContentEncoding.UUEncode;        break;
     }
     return retval;
  }

    internal MimePart (ParserOptions options, ContentType type, IEnumerable<Header> headers, bool toplevel) : base (options, type, headers, toplevel)
    {
     foreach(Header hd in Headers){
        if (String.Compare(hd.Field, "content-transfer-encoding", true) == 0){
           ContentTransferEncoding = ParseEncoding(hd.Value);
           break;
        }
     }
    }

Changing any construction has quite some impact, so we would like to ask you to take our changes for your code. That would make our maintenance easier, and you might even like our change.

Thanks in advance,
Cheers!

Header versus HeaderList versus MimeMessage

Hello, need a bit of help understanding Header and HeaderList.

There doesn't seem to be any formal even "POCO" exposure of otherwise "simple" Header fields, until a full message is parsed into MimeMessage.

As long as HeaderList is going to be maintained as a List, I think it would go better as an IDictionary< string, Header > with string being the name of the field, followed by its Header. I suppose I could ToDictionary the HeaderList, but it seems like there should be more of an interface.

A public or even internal extension method could work with a Header Value and make the appropriate conversion(s), for instance.

public static TValue GetHeaderValue<TValue>(this HeaderList header, string field, Func<string, TValue> getter)
{
    var value = header.FirstOrDefault(hl => hl.Field.Equals(field));
    return value == null ? default(TValue) : getter(value.Value);
}

Or something like that. Follow up post to, er, follow...

Add Importance flag to IMessageSummary

Hi,

Is it possible to add the Importance flag the the IMessageSummary.Envenlope? This is something you normally would like to retrieve before getting the complete message.

Create MimeKit.Lite Nuget Package

I'm using MimeKit for Papercut (http://papercut.codeplex.com) because it's fast and excellent. No reason to reinvent the wheel with something superior and MIT licensed out there...

But I don't need the encryption stuff.

If you don't have any interest, I don't mind doing it.

Thanks for the excellent lib.

EnumerateMimeParts recursion / Streamable attachments

I'm concerned on a couple of points: EnumerateMimeParts is recursive. Remember in school when you were taught (I assume you were) that every recursive solution also has an iterative solution? If you weren't, trust me, it's true. I might suggest a more iterative solution first.

Second, I am concerned that EnumerateMimeParts occurs multiple times depending on the property(ies) that are called. It doesn't need to be calculated any more than once, regardless the caller requesting the parts. The parts aren't changing between calls, after all... It's only "two" properties, BodyParts and Attachments, but you get the idea.

Then... What's the point of Attachments if they aren't streamable? The parts still need to be assembled and presented through a memory stream?

Thanks...

DateTime not parsing correctly

"Tue, 11 Feb 2014 22:27:10 +0100 (CET)" fails to parse, DateTimeOffset.TryParse returns false, and consequently the default DateTime.

Problem with Header - From encoding

Hi,
first of all, thanks for your great work!
With version 1.41.0.0 there seems to be a problem with header encoding of the From-field (With the Subject-Field this works). E.g. From= "a ... a [email protected]" you would expect you get something like:
"a ... a\r\n [email protected]" but you get:
"a ... a\r\n\[email protected]". So if you decode it, you get a different result: "a ... a\[email protected]"
In the previos version 1.38.0.0 this worked.

    [TestMethod]
    public void WordEncodingEncodeEncodeFromTest1()
    {
        string rowSubject = "Lukas Trรถtzmรผller <[email protected]>";
        string content = WordEncoding.EncodeFrom(rowSubject,
           Encoding.GetEncoding("ISO-8859-15"));

        Assert.IsTrue(76 > content.IndexOf('\n'));
        Assert.AreEqual(content, "Lukas =?iso-8859-1?b?VHL2dHpt/GxsZXI=?=\n <[email protected]>");

        content = content.Replace("\n", ""); 

        string result = WordEncoding.Decode(content);
        Assert.IsTrue(rowSubject == result);
    }

    public static string EncodeFrom(string from, Encoding inputEncoding)
    {
        if (string.IsNullOrEmpty(from)) return string.Empty;

        string strEnc = inputEncoding.WebName.ToUpper();
        Header header = new Header(Portable.Text.Encoding.GetEncoding(strEnc),
            "From", from);

        string encoded = ByteArrayToString(header.RawValue);
        encoded = encoded.Replace("\r\n", "\n").Trim();

        return encoded;
    }

    private static string ByteArrayToString(byte[] text)
    {
        StringBuilder builder = new StringBuilder();

        for (int i = 0; i < text.Length; i++)
            builder.Append((char)text[i]);

        return builder.ToString();
    }

Date case sensitive

Don't parse this:

Date: FRI, 30 NOV 2012 02:09:10 +0100

X-Mailer: Oracle Email Server SDK 9.0.5

media subtypes that contain a dot

I think there is a problem dealing with media sub types that contain a dot.

For example: application/vnd.visio is the media types for Visio files.

If I try to parse a message that contain a Visio file attachment, the resulting entity will have a content-type of application/octet-stream instead of application/vnd.visio.

Also, if I try to create a MimePart object with type application/vnd.visio, I will get an ArgumentException with message "Illegal characters in subtype".

Code:

MimeEntity entity = new MimePart("application", "vnd.visio") { IsAttachment = true, FileName = "file.vsd"};

InternetAddressList is missing ", " separator when encoded

When adding several addresses to an InternetAddressList the final output is not correctly separated.

Code:

        MimeMessage mm = new MimeMessage ();
        mm.Cc.Add(new MailboxAddress("Bob", "[email protected]"));
        mm.Cc.Add(new MailboxAddress("Bob", "[email protected]"));
        mm.Cc.Add(new MailboxAddress("Bob", "[email protected]"));
        mm.Cc.Add(new MailboxAddress("Bob", "[email protected]"));
        mm.Cc.Add(new MailboxAddress("Bob", "[email protected]"));
        mm.Cc.Add(new MailboxAddress("Bob", "[email protected]"));
        mm.Cc.Add(new MailboxAddress("Bob", "[email protected]"));
        mm.WriteTo (Console.OpenStandardOutput());

Similar result with To instead of Cc

Output:

One possible workaround is to add this before WriteTo which appear to generate correct output.

        mm.Headers [HeaderId.To] = mm.To.ToString ();

With workaround

SecureMimeContext uses incorrect OIDs for SHA Message Digest Algorithms

Sending signed content with SHA digests results in "unknown signature" errors on the clients I have tested with (Outlook, NIST S/MIME testing tools).

SecureMimeContext.GetDigestOid is using BouncyCastle's PkcsObjectIdentifiers.Sha256WithRsaEncryption.Id. That's a SignatureAlgorithm from RFC 3370 (Section 3), not a Digest Algorithm (those are in Section 2).

So the SHA-1 OID is there in RFC 3370 Section 2.1. It's 1.3.14.3.2.26. It can be found in BC's X509ObjectIdentifiers class.

    public static readonly DerObjectIdentifier IdSha1 = new DerObjectIdentifier("1.3.14.3.2.26");

The SHA-2 OIDs were defined in RFC 5754. They are in BC's NistObjectIdentifiers class.

    public static readonly DerObjectIdentifier IdSha256 = HashAlgs.Branch("1");
    public static readonly DerObjectIdentifier IdSha384 = HashAlgs.Branch("2");
    public static readonly DerObjectIdentifier IdSha512 = HashAlgs.Branch("3");
    public static readonly DerObjectIdentifier IdSha224 = HashAlgs.Branch("4");

Encoding of MimePart.FileName property

Hi Jeffrey, big thanks to all the work you are doing with Mime/MailKit, really nice piece of code. I have stumbled accross one (non-critical) issue. Upon receiving some messages via IMAP I'm saving attachments, but have localised filenames in MimePart.FileName, such as

"" รˆPP - ยพรกdost o akce""ptaci .""doc"

which should actually look like something

ลฝรกdost o akceptaci.doc

instead. server is Exchange in this case. Could it be something with encoding of the filename? Or am I doing something wrong?

Thanks, Tomas

Porable Class Library on NuGet

I've seen a Portable csproject in this repository. Is there any reason, why there ins't any portable version of this project on NuGet?

Issue decoding headers not properly rfc2047 encoded

Probably can't be considered a bug as such, but I wanted to hear your thoughts on it.

Consider an email with these headers:

Content-type: text/plain; charset=koi8-r
Subject: รคร…ร“ร‘ร”ร‹ร รกรŽร…ร‹ร„รร”รร— รครŽร‘

If subject is decoded using MimeKit, it's not "properly" decoded to: ะ”ะตััั‚ะบะฐ ะะฝะตะบะดะพั‚ะพะฒ ะ”ะฝั. From what I understand this is because the subject header is not properly rfc2047 encoded. Decoding using koi8-r decodes it properly.

I'm thinking one could decode the subject (or other headers) using the content-type charset, if set, if the header doesn't explicitly say what charset it's using?
But I suppose that's more of an IMAP client issue (that I'm incidentally working on) than a MimeKit issue? :)

SaslException when using nonTLS SMTP

I'm trying to use SMTP the old way (with the password in plain text et-al... :-/ ), and it gives me this exception:

[SaslException: Invalid SASL challenge from the server: Username:]
   MailKit.Security.DigestChallenge.Parse(String token) +1319
   MailKit.Security.SaslMechanismDigestMd5.Challenge(Byte[] token, Int32 startIndex, Int32 length) +276
   MailKit.Security.SaslMechanism.Challenge(String token) +54
   MailKit.Net.Smtp.SmtpClient.Authenticate(ICredentials credentials, CancellationToken cancellationToken) +604
   FsWeb.Controllers.BackOfficeController.SendEmail(MimeMessage msg) in C:\Users\knocte\documents\visual studio 2012\Projects\FSolar\src\ConclaveSolarWebWebAppApi\BackOfficeController.fs:38

I've verified like a thousand times that my username is correct, but MailKit insists in sending this error.

The code I'm using (F#) is:

            use client = new SmtpClient()
            let credentials =
                new NetworkCredential(ConfigurationManager.AppSettings.["SmtpUsername"],
                                      ConfigurationManager.AppSettings.["SmtpPassword"])
            let uri = new Uri (ConfigurationManager.AppSettings.["SmtpHost"])
            let cancelToken = new CancellationTokenSource()
            client.Connect(uri, cancelToken.Token)

            // Note: since we don't have an OAuth2 token, disable
            // the XOAUTH2 authentication mechanism.
            ignore(client.AuthenticationMechanisms.Remove ("XOAUTH2"))

            // Note: only needed if the SMTP server requires authentication
            client.Authenticate (credentials, cancelToken.Token);

            client.Send (msg, cancelToken.Token);
            client.Disconnect (true, cancelToken.Token);

This works well with a smtps:// host URI (like gmail), but not with a smtp:// one...

Sender is encoded without a line break

Example:
MimeMessage mm = new MimeMessage ();
mm.Sender = new MailboxAddress ("asd", "[email protected]");
mm.WriteTo (Console.OpenStandardOutput());

Output:

From: 
To: 
Date: Sat, 11 Jan 2014 19:32:04 +0100
Subject: 
Sender:asd <[email protected]>Message-Id: <635250658341716870.11868.0@purple>

My guess is that the issue is at the Sender property which does not add a newline to the RawValue.

mm.Headers[1].RawValue: 0x20 0x0A
mm.Headers[4].RawValue: ...... 0x62

The following appears to work(have not verified encoding)

mm.Headers[HeaderId.Sender] = new MailboxAddress ("aรฅรครถsd", "[email protected]").ToString();

NewLineFormat.Dos option converts all the '0A' of the attachment to '0D 0A'

I'm using MimeKit in my project. I'm using it to add support to SOAP wA, it means that I'm doing a HTTP POST of a multipart related MIME document so I'm sending a binary file (which is my attachment).
I'm using the option: NewLineFormat.Dos in my MultiPart message. After sending my request I noticed that the binary file is corrupted and this was because of the NewLineFormat.Dos that converts all the '0A' to '0D 0A' in hex.
I think the option must not affect the content of my binary. Do you have any solution?
thanks.

More tolerant address parsing?

I received a few emails with a From header similar to this (missing closing bracket):

From: =?UTF-8?Q?r_f=C3=BCr_At?= <[email protected]

Does it make sense to make the parsing more tolerant or is this case too special?

Parsing an empty multipart entity

I think that there is a bug in parsing empty multipart entities.

I have a mime message with the following structure:

  1. multipart/signed
    1.1 multipart/mixed
    1.1.1 multipart/alternative (no children)
    1.1.2 image/x-icon
    1.2 application/x-pkcs-signature

When I parse this message with MimtKit I get the following structure:

  1. multipart/signed
    1.1 multipart/mixed
    1.1.1 multipart/alternative
    1.1.1.1 image/x-icon
    1.2 application/x-pkcs-signature

The parser treats the icon attachment as a child of the multipart/alternative entity. While it should have treated it as its sibling.

I could not find a way to attach the mime file here. Let me know if you need it.

Split crypto support into a separate assembly

Crypto support brings a lot of unnecessary bloat (BouncyCastle + Mono.Data.Sqlite) if you're not writing a full blown mail client or something. I'm using MimeKit to handle multipart/form-data messages over HTTP and have no need for crypto.

It would be very nice to have a layout like:

  • MimeKit.dll (contains all of MimeKit with crypto)
  • MimeKit.Crypto.dll (contains only the crypto parts and references MimeKit.dll)

Or:

  • MimeKit.dll (contains all of MimeKit including crypto)
  • MimeKitLite.dll (contains all of MimeKit without crypto)

Two minor issues

Hi Jeffrey

Very nice work - elegant code and easy to use.

I'm using your framework to parse AS2 messages, and I've found two minor issues.

1) HeaderList.WriteTo
When calling WriteTo on the MimeEntity theres only one linebreak between the headers and the content - there should be two (an empty line). I've fixed this by adding an extra:
stream.Write(NewLine, 0, NewLine.Length);
in the WriteTo method of the MimeEntity class (so there is now two line-breaks)
I don't know if theres a better way or place to do this.

2) Wrong cut for the last boundary:
In line 784 of the Parser class you have:
// the last \r\n belongs to the boundary
if (content.Length > 0) {
if (input[inputIndex - 1] == (byte) '\r')
content.SetLength (content.Length - 2);
else
content.SetLength (content.Length - 1);
}

But input[inputIndex - 1] will never be \r
Instead I have done this:

// the last \r\n belongs to the boundary
if (content.Length > 0)
{
if (input[inputIndex - 2] == (byte)'\r' && input[inputIndex - 1] == (byte)'\n')
content.SetLength(content.Length - 2);
}

I have found those issues because I have to create a checksum (MIC) of the content-part. Therefore it has to be 100% identical with the input-stream.

Cannot decrypt without adding certificate to personal store

Hi.

When I attempt to decrypt an email using the WindowsSecureMimeContext it throws the exception:

System.Security.Cryptography.CryptographicException: The enveloped-data message does not contain the specified recipient.

   at System.Security.Cryptography.Pkcs.EnvelopedCms.DecryptContent(RecipientInfoCollection recipientInfos, X509Certificate2Collection extraStore)
   at System.Security.Cryptography.Pkcs.EnvelopedCms.Decrypt()
   at MimeKit.Cryptography.WindowsSecureMimeContext.Decrypt(Stream encryptedData)
   at MimeKit.Cryptography.ApplicationPkcs7Mime.Decrypt(SecureMimeContext ctx)
   at DC.Communications.Counterparties.BelVis.MailRecv.MailHandlers.BelVisMailHandler.HandleEncryptedMail(ApplicationPkcs7Mime entity) in c:\source\projects\DC.BelVis\trunk\DC.Communications.Counterparties.BelVis\DC.Communications.Counterparties.BelVis.MailRecv\MailHandlers\BelVisMailHandler.cs:line 179
   at DC.Communications.Counterparties.BelVis.MailRecv.MailHandlers.BelVisMailHandler.EmailDistributer(MimeEntity entity) in c:\source\projects\DC.BelVis\trunk\DC.Communications.Counterparties.BelVis\DC.Communications.Counterparties.BelVis.MailRecv\MailHandlers\BelVisMailHandler.cs:line 90
   at DC.Communications.Counterparties.BelVis.MailRecv.MailHandlers.BelVisMailHandler.ParseMimeContent(Byte[] content) in c:\source\projects\DC.BelVis\trunk\DC.Communications.Counterparties.BelVis\DC.Communications.Counterparties.BelVis.MailRecv\MailHandlers\BelVisMailHandler.cs:line 78
   at DC.Communications.Counterparties.BelVis.MailRecv.MailHandlers.BelVisMailHandler.HandleNewMail(IBelVisEmailMessage belVisEmailMessage) in c:\source\projects\DC.BelVis\trunk\DC.Communications.Counterparties.BelVis\DC.Communications.Counterparties.BelVis.MailRecv\MailHandlers\BelVisMailHandler.cs:line 45}

Which basically means, that it cannot find the certificate to use.
However I have imported the certificate:

var secureMimeContext = new WindowsSecureMimeContext();
var certificate = new X509Certificate2(certificateFilename,
                                                   certificatePassword);
var stream = new MemoryStream(certificate.GetRawCertData());
secureMimeContext.Import(stream, certificatePassword);
return secureMimeContext;

And a different way of importing:

var secureMimeContext = new WindowsSecureMimeContext();
var certificate = new X509Certificate2(certificateFilename,
                                                   certificatePassword);
var bouncyX509Certificate = Org.BouncyCastle.Security.DotNetUtilities.FromX509Certificate(certificate);
                secureMimeContext.Import(bouncyX509Certificate);

return secureMimeContext;

However none of them works.

I have tried to decrypt myself, which works great.
I load the certificate like this:

var certificateCollection = new X509Certificate2Collection(certificate);
var envelopedCms = new EnvelopedCms();
envelopedCms.Decode(data);
envelopedCms.Decrypt(certificateCollection);
return envelopedCms.ContentInfo.Content;

So I believe it is an issue, that it is so dependent on the certificate store.
Can you provide a fix or an idea on how to circumvent this issue?

Provide MimeEntity.Load with a contentType parameter

When using MimeKit for parsing HTTP content, the Content-Type header will have been removed from the stream already as part of the HTTP header parsing, leaving only the request body data in the stream to consume (at least in all sane/popular frameworks).

This is problematic because MimeKit needs this particular header when parsing. While easy to work around (especially thanks to ChainedStream to avoid copying the entire request body into memory first), it is very non-obvious what the problem is when one might first decide to mix HTTP and MimeKit.

I suggest an API overload for MimeEntity.Load:

MimeEntity.Load (request.InputStream, contentType: request.ContentType)

As a workaround, I have done the following in my production code for now:

var contentType = String.Format ("Content-Type: {0}\r\n\r\n", request.ContentType);
var chainedStream = new ChainedStream ();
chainedStream.Add (new MemoryStream (Encoding.UTF8.GetBytes (contentType)));
chainedStream.Add (request.InputStream);

var multipart = MimeEntity.Load (chainedStream) as Multipart;
...

Bug In Rfc2047 Decoder

There's a bug handling base 64 encoded names, here's a test case to illustrate the problem:

namespace UnitTests
{
    [TestFixture]
    public class Rfc2047Tests
    {
        [Test]
        public void CheckQEncodedName()
        {
            var input = "=?iso-8859-1?q?hola?=";

            var actual = Rfc2047.DecodeText(Encoding.ASCII.GetBytes(input));

            Assert.AreEqual("hola", actual);
        }

        [Test]
        public void CheckBEncodedName()
        {
            var encoding = "iso-8859-1";

            var input = "=?" + encoding + "?B?"
                        + Convert.ToBase64String(Encoding.GetEncoding(encoding).GetBytes("hola"))
                        + "?=";
            var actual = Rfc2047.DecodeText(Encoding.ASCII.GetBytes(input));

            Assert.AreEqual("hola", actual);
        }
    }
}

It looks like IF statement around line 353 in Rfc2047 needs to be changed to this (change the >= to >):

    if (inptr + 2 > inend) {
        // didn't find an end marker...
        inptr = word + 2;
        ascii = true;

        goto non_rfc2047;
    }

Question: Does verification of signerinfo check root?

Hi.

When I invoke Verify on a signature e.g.:

private void HandleMultipartSignedMail(MultipartSigned entity)
{
            foreach (var signature in entity.Verify())
            {
                try
                {
                    signature.Verify();
                }...

is it then verified that the root certificate, which the certificate used for signing is based on, is trusted?

I hope you are able to answer this :)

Cheers

Empty headers malformated when encoding

Hi there,

It appears that if the From or To headers don't have any entries, they are missing a line-feed after it is serialized. For example:

From: Test User <[email protected]>
To:Date: Thu, 26 Jun 2014 08:42:48 -0500
Subject: This is the subject
Message-Id: <aa9ab005-29e8-9ca2-0a0a-a1f3b8667d05@example>
Cc: Test User <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain; charset=utf-8

This is the body.

was generated by the code

MimeMessage message = new MimeMessage();
message.Date = DateTime.Now;
message.Subject = "This is the subject";
message.From.Add(new MailboxAddress("Test User", "[email protected]"));
message.Cc.Add(new MailboxAddress("Test User", "[email protected]"));

message.Body = new TextPart() { Text = "This is the body." };

using (MemoryStream ms = new MemoryStream())
{
    message.WriteTo(ms);

    string mimeEncoded = Encoding.ASCII.GetString(ms.ToArray());
    Console.WriteLine(mimeEncoded);
}

Parsing has been working great, though!

SQLite dependency causes version problems

The SQLite dependency causes problems for us because of versioning issues. Please place the SQLite stuff in a separate library (e.g. MimeKit.CertStore.SQLite.dll) and just use an interface in the core library (e.g. MimeKit.dll, ICertStore). This would have the nice side effect to allow custom certificate stores.

Argument out of range

Hi,

When I use the code below on an empty inbox I get the error Argument out of range on the line:
var result = client.Inbox.Fetch(0, -1, items);

    public IList<IMessageSummary> ListMessages
    {
        get
        {
            using (var client = new ImapClient())
            {
                client.Connect(Server, 993, true);
                client.AuthenticationMechanisms.Remove("XOAUTH");
                client.Authenticate(User, Password);
                client.Inbox.Open(FolderAccess.ReadOnly);

                const MessageSummaryItems items =
                    MessageSummaryItems.UniqueId | 
                    MessageSummaryItems.Envelope | 
                    MessageSummaryItems.MessageSize;

                var result = client.Inbox.Fetch(0, -1, items);
                client.Disconnect(true);
                return result;
            }
        }
    }

WriteTo writes 0 (NUL) values.

Hi again

I've just tested the changes with a "large" file (~11kb) - and it looks like that some values from the original stream/data are being replaced with 0 (NUL) when using the WriteTo method.

Below is a small test-project to reproduce the problem. I can't figure out where and why this happens...

    private static void TestCompleteMessage()
    {
        // Input for complete message
        var input = new byte[] { 67, 111, 110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 109, 117, 108, 116, 105, 112, 97, 114, 116, 47, 115, 105, 103, 110, 101, 100, 59, 32, 112, 114, 111, 116, 111, 99, 111, 108, 61, 34, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 112, 107, 99, 115, 55, 45, 115, 105, 103, 110, 97, 116, 117, 114, 101, 34, 59, 32, 109, 105, 99, 97, 108, 103, 61, 34, 115, 104, 97, 49, 34, 59, 13, 10, 32, 98, 111, 117, 110, 100, 97, 114, 121, 61, 34, 95, 53, 55, 54, 70, 67, 49, 49, 66, 45, 51, 52, 50, 57, 45, 52, 56, 67, 52, 45, 65, 51, 54, 57, 45, 56, 69, 51, 49, 67, 65, 50, 54, 57, 57, 53, 70, 95, 34, 13, 10, 13, 10, 45, 45, 95, 53, 55, 54, 70, 67, 49, 49, 66, 45, 51, 52, 50, 57, 45, 52, 56, 67, 52, 45, 65, 51, 54, 57, 45, 56, 69, 51, 49, 67, 65, 50, 54, 57, 57, 53, 70, 95, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 84, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 101, 100, 105, 102, 97, 99, 116, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 84, 114, 97, 110, 115, 102, 101, 114, 45, 69, 110, 99, 111, 100, 105, 110, 103, 58, 32, 98, 105, 110, 97, 114, 121, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 68, 101, 115, 99, 114, 105, 112, 116, 105, 111, 110, 58, 32, 98, 111, 100, 121, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 68, 105, 115, 112, 111, 115, 105, 116, 105, 111, 110, 58, 32, 97, 116, 116, 97, 99, 104, 109, 101, 110, 116, 59, 32, 102, 105, 108, 101, 110, 97, 109, 101, 61, 34, 49, 95, 76, 79, 82, 68, 32, 50, 54, 71, 32, 95, 50, 40, 52, 41, 32, 45, 32, 67, 111, 112, 121, 46, 120, 109, 108, 34, 13, 10, 13, 10, 60, 63, 120, 109, 108, 32, 118, 101, 114, 115, 105, 111, 110, 61, 34, 49, 46, 48, 34, 32, 101, 110, 99, 111, 100, 105, 110, 103, 61, 34, 117, 116, 102, 45, 56, 34, 63, 62, 13, 10, 60, 110, 115, 48, 58, 65, 83, 50, 95, 101, 110, 118, 101, 108, 111, 112, 101, 32, 120, 109, 108, 110, 115, 58, 110, 115, 48, 61, 34, 104, 116, 116, 112, 58, 47, 47, 101, 110, 101, 114, 103, 105, 110, 101, 116, 46, 100, 107, 47, 101, 100, 105, 103, 97, 115, 34, 62, 13, 10, 60, 83, 101, 110, 100, 101, 114, 73, 100, 62, 71, 83, 77, 83, 60, 47, 83, 101, 110, 100, 101, 114, 73, 100, 62, 10, 32, 32, 60, 82, 101, 99, 101, 105, 118, 101, 114, 73, 100, 62, 69, 73, 67, 95, 78, 69, 60, 47, 82, 101, 99, 101, 105, 118, 101, 114, 73, 100, 62, 13, 10, 32, 32, 60, 77, 101, 115, 115, 97, 103, 101, 73, 100, 62, 71, 83, 77, 83, 68, 69, 76, 79, 82, 68, 51, 50, 56, 49, 53, 53, 60, 47, 77, 101, 115, 115, 97, 103, 101, 73, 100, 62, 13, 10, 32, 32, 60, 98, 111, 100, 121, 62, 13, 10, 32, 32, 32, 32, 60, 68, 101, 108, 105, 118, 101, 114, 121, 79, 114, 100, 101, 114, 32, 82, 101, 108, 101, 97, 115, 101, 61, 34, 49, 34, 32, 86, 101, 114, 115, 105, 111, 110, 61, 34, 69, 71, 65, 83, 52, 48, 34, 32, 32, 120, 109, 108, 110, 115, 58, 120, 115, 105, 61, 34, 104, 116, 116, 112, 58, 47, 47, 119, 119, 119, 46, 119, 51, 46, 111, 114, 103, 47, 50, 48, 48, 49, 47, 88, 77, 76, 83, 99, 104, 101, 109, 97, 45, 105, 110, 115, 116, 97, 110, 99, 101, 34, 32, 120, 115, 105, 58, 110, 111, 78, 97, 109, 101, 115, 112, 97, 99, 101, 83, 99, 104, 101, 109, 97, 76, 111, 99, 97, 116, 105, 111, 110, 61, 34, 112, 50, 45, 51, 45, 100, 101, 108, 111, 114, 100, 46, 120, 115, 100, 34, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 73, 100, 101, 110, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 118, 61, 34, 68, 69, 76, 79, 82, 68, 51, 50, 56, 49, 53, 53, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 84, 121, 112, 101, 32, 118, 61, 34, 50, 54, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 114, 101, 97, 116, 105, 111, 110, 68, 97, 116, 101, 84, 105, 109, 101, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 57, 45, 51, 48, 84, 49, 50, 58, 51, 50, 58, 49, 53, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 86, 97, 108, 105, 100, 105, 116, 121, 80, 101, 114, 105, 111, 100, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 73, 115, 115, 117, 101, 114, 73, 100, 101, 110, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 88, 48, 48, 48, 48, 48, 48, 48, 48, 49, 48, 57, 54, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 73, 115, 115, 117, 101, 114, 82, 111, 108, 101, 32, 118, 61, 34, 90, 83, 79, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 82, 101, 99, 105, 112, 105, 101, 110, 116, 73, 100, 101, 110, 116, 105, 102, 105, 99, 97, 116, 105, 111, 110, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 49, 48, 88, 49, 48, 48, 49, 65, 49, 48, 48, 49, 65, 50, 52, 56, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 82, 101, 99, 105, 112, 105, 101, 110, 116, 82, 111, 108, 101, 32, 118, 61, 34, 90, 83, 79, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 48, 53, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 48, 56, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 51, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 50, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 51, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 49, 57, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 50, 51, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 49, 56, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 56, 49, 52, 57, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 49, 56, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 57, 56, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 52, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 49, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 48, 57, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 53, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 49, 52, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 49, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 54, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 48, 53, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 49, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 49, 56, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 51, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 49, 53, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 49, 56, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 52, 53, 57, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 55, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 50, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 50, 52, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 51, 55, 55, 55, 56, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 56, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 50, 54, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 49, 52, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 57, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 51, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 49, 57, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 49, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 50, 56, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 50, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 49, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 48, 55, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 48, 51, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 49, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 49, 54, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 49, 54, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 50, 53, 48, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 49, 51, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 51, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 49, 56, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 49, 49, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 49, 48, 53, 55, 57, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 49, 49, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 49, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 49, 50, 52, 50, 57, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 49, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 49, 54, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 49, 50, 49, 51, 57, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 49, 54, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 49, 49, 56, 51, 57, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 49, 52, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 48, 53, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 50, 50, 50, 54, 50, 53, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 49, 53, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 49, 52, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 48, 56, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 49, 54, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 49, 53, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 48, 55, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 76, 105, 110, 101, 78, 117, 109, 98, 101, 114, 32, 118, 61, 34, 49, 55, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 83, 116, 97, 116, 117, 115, 32, 118, 61, 34, 49, 52, 71, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 51, 48, 53, 34, 32, 118, 61, 34, 50, 49, 90, 48, 48, 48, 48, 48, 48, 48, 48, 48, 50, 51, 56, 77, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 69, 120, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 68, 83, 48, 48, 48, 48, 48, 56, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 73, 110, 116, 101, 114, 110, 97, 108, 83, 104, 105, 112, 112, 101, 114, 65, 99, 99, 111, 117, 110, 116, 32, 99, 111, 100, 105, 110, 103, 83, 99, 104, 101, 109, 101, 61, 34, 90, 83, 79, 34, 32, 118, 61, 34, 76, 84, 48, 48, 48, 48, 48, 52, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 84, 105, 109, 101, 73, 110, 116, 101, 114, 118, 97, 108, 32, 118, 61, 34, 50, 48, 49, 49, 45, 48, 56, 45, 49, 54, 84, 48, 52, 58, 48, 48, 90, 47, 50, 48, 49, 49, 45, 48, 56, 45, 49, 55, 84, 48, 52, 58, 48, 48, 90, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 68, 105, 114, 101, 99, 116, 105, 111, 110, 32, 118, 61, 34, 90, 48, 50, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 81, 117, 97, 110, 116, 105, 116, 121, 32, 118, 61, 34, 48, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 32, 32, 60, 77, 101, 97, 115, 117, 114, 101, 85, 110, 105, 116, 32, 118, 61, 34, 75, 87, 49, 34, 47, 62, 13, 10, 32, 32, 32, 32, 32, 32, 32, 32, 60, 47, 80, 101, 114, 105, 111, 100, 62, 13, 10, 32, 32, 32, 32, 32, 32, 60, 47, 67, 111, 110, 110, 101, 99, 116, 105, 111, 110, 80, 111, 105, 110, 116, 73, 110, 102, 111, 114, 109, 97, 116, 105, 111, 110, 62, 13, 10, 32, 32, 32, 32, 60, 47, 68, 101, 108, 105, 118, 101, 114, 121, 79, 114, 100, 101, 114, 62, 13, 10, 32, 32, 60, 47, 98, 111, 100, 121, 62, 13, 10, 60, 47, 110, 115, 48, 58, 65, 83, 50, 95, 101, 110, 118, 101, 108, 111, 112, 101, 62, 13, 10, 13, 10, 45, 45, 95, 53, 55, 54, 70, 67, 49, 49, 66, 45, 51, 52, 50, 57, 45, 52, 56, 67, 52, 45, 65, 51, 54, 57, 45, 56, 69, 51, 49, 67, 65, 50, 54, 57, 57, 53, 70, 95, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 116, 121, 112, 101, 58, 32, 97, 112, 112, 108, 105, 99, 97, 116, 105, 111, 110, 47, 112, 107, 99, 115, 55, 45, 115, 105, 103, 110, 97, 116, 117, 114, 101, 59, 32, 110, 97, 109, 101, 61, 34, 115, 109, 105, 109, 101, 46, 112, 55, 115, 34, 13, 10, 67, 111, 110, 116, 101, 110, 116, 45, 84, 114, 97, 110, 115, 102, 101, 114, 45, 69, 110, 99, 111, 100, 105, 110, 103, 58, 32, 98, 97, 115, 101, 54, 52, 13, 10, 13, 10, 77, 73, 65, 71, 67, 83, 113, 71, 83, 73, 98, 51, 68, 81, 69, 72, 65, 113, 67, 65, 77, 73, 65, 67, 65, 81, 69, 120, 67, 122, 65, 74, 66, 103, 85, 114, 68, 103, 77, 67, 71, 103, 85, 65, 77, 73, 65, 71, 67, 83, 113, 71, 83, 73, 98, 51, 68, 81, 69, 72, 65, 81, 65, 65, 111, 73, 73, 67, 56, 84, 67, 67, 65, 117, 48, 119, 13, 10, 103, 103, 74, 87, 111, 65, 77, 67, 65, 81, 73, 67, 69, 81, 67, 50, 70, 86, 118, 54, 89, 97, 115, 50, 52, 43, 74, 109, 122, 51, 90, 120, 48, 120, 70, 47, 77, 65, 48, 71, 67, 83, 113, 71, 83, 73, 98, 51, 68, 81, 69, 66, 66, 81, 85, 65, 77, 67, 103, 120, 69, 106, 65, 81, 66, 103, 78, 86, 66, 65, 77, 77, 67, 87, 86, 107, 13, 10, 97, 87, 78, 115, 97, 87, 86, 117, 100, 68, 69, 83, 77, 66, 65, 71, 65, 49, 85, 69, 67, 103, 119, 74, 90, 87, 82, 112, 89, 50, 120, 112, 90, 87, 53, 48, 77, 66, 52, 88, 68, 84, 69, 120, 77, 68, 89, 120, 78, 68, 69, 121, 78, 68, 107, 121, 77, 70, 111, 88, 68, 84, 73, 120, 77, 68, 89, 120, 78, 68, 69, 121, 78, 68, 107, 121, 13, 10, 77, 70, 111, 119, 97, 68, 69, 83, 77, 66, 65, 71, 65, 49, 85, 69, 65, 119, 119, 74, 90, 87, 82, 112, 89, 50, 120, 112, 90, 87, 53, 48, 77, 82, 73, 119, 69, 65, 89, 68, 86, 81, 81, 75, 68, 65, 108, 108, 90, 71, 108, 106, 98, 71, 108, 108, 98, 110, 81, 120, 68, 106, 65, 77, 66, 103, 78, 86, 66, 65, 99, 77, 66, 86, 90, 108, 13, 10, 97, 109, 120, 108, 77, 83, 69, 119, 72, 119, 89, 74, 75, 111, 90, 73, 104, 118, 99, 78, 65, 81, 107, 66, 70, 104, 74, 112, 98, 109, 90, 118, 81, 71, 82, 114, 76, 87, 100, 104, 100, 71, 86, 51, 89, 88, 107, 117, 90, 71, 115, 120, 67, 122, 65, 74, 66, 103, 78, 86, 66, 65, 89, 84, 65, 107, 82, 76, 77, 73, 73, 66, 73, 106, 65, 78, 13, 10, 66, 103, 107, 113, 104, 107, 105, 71, 57, 119, 48, 66, 65, 81, 69, 70, 65, 65, 79, 67, 65, 81, 56, 65, 77, 73, 73, 66, 67, 103, 75, 67, 65, 81, 69, 65, 108, 70, 118, 118, 87, 89, 104, 80, 110, 71, 57, 49, 69, 100, 79, 81, 109, 80, 49, 122, 107, 76, 122, 49, 53, 68, 56, 109, 117, 51, 104, 105, 71, 53, 68, 54, 105, 66, 109, 115, 13, 10, 89, 53, 85, 67, 73, 71, 109, 65, 117, 117, 80, 119, 118, 106, 73, 49, 106, 79, 104, 108, 104, 100, 83, 57, 108, 89, 81, 111, 115, 108, 78, 77, 114, 50, 115, 80, 75, 113, 66, 103, 109, 116, 50, 106, 105, 53, 78, 114, 109, 110, 67, 56, 72, 71, 51, 110, 100, 84, 51, 115, 100, 105, 116, 57, 97, 50, 102, 89, 105, 99, 121, 107, 90, 116, 88, 122, 13, 10, 66, 115, 52, 109, 104, 52, 105, 118, 111, 113, 100, 122, 86, 90, 79, 117, 71, 50, 74, 86, 106, 50, 57, 122, 99, 86, 57, 66, 99, 55, 73, 76, 81, 85, 73, 53, 111, 72, 50, 85, 106, 68, 120, 113, 111, 65, 106, 99, 90, 112, 57, 117, 122, 86, 107, 57, 98, 47, 99, 101, 116, 98, 112, 66, 77, 74, 48, 80, 90, 87, 117, 102, 75, 107, 121, 113, 13, 10, 80, 117, 48, 81, 100, 101, 52, 81, 52, 78, 43, 72, 105, 88, 67, 115, 77, 77, 71, 119, 83, 119, 78, 70, 56, 113, 108, 106, 82, 98, 47, 101, 115, 102, 70, 57, 112, 69, 120, 122, 78, 51, 116, 115, 67, 122, 65, 97, 77, 101, 73, 55, 51, 105, 70, 107, 53, 87, 73, 78, 66, 90, 76, 101, 100, 88, 104, 115, 122, 115, 89, 79, 71, 88, 115, 74, 13, 10, 103, 114, 75, 49, 82, 66, 89, 47, 56, 76, 90, 70, 65, 104, 82, 56, 74, 112, 72, 52, 87, 99, 98, 90, 102, 75, 120, 90, 52, 50, 122, 121, 84, 65, 117, 80, 81, 77, 85, 70, 118, 88, 79, 79, 118, 51, 79, 110, 87, 89, 53, 120, 103, 104, 81, 118, 100, 72, 103, 43, 99, 118, 65, 86, 116, 50, 77, 47, 47, 73, 74, 86, 98, 81, 73, 68, 13, 10, 65, 81, 65, 66, 111, 49, 77, 119, 85, 84, 65, 100, 66, 103, 78, 86, 72, 81, 52, 69, 70, 103, 81, 85, 114, 66, 117, 116, 87, 54, 43, 113, 86, 97, 69, 72, 107, 56, 78, 51, 109, 98, 102, 72, 57, 113, 67, 110, 71, 99, 107, 119, 68, 103, 89, 68, 86, 82, 48, 80, 65, 81, 72, 47, 66, 65, 81, 68, 65, 103, 83, 119, 77, 67, 65, 71, 13, 10, 65, 49, 85, 100, 74, 81, 69, 66, 47, 119, 81, 87, 77, 66, 81, 71, 67, 67, 115, 71, 65, 81, 85, 70, 66, 119, 77, 67, 66, 103, 103, 114, 66, 103, 69, 70, 66, 81, 99, 68, 66, 68, 65, 78, 66, 103, 107, 113, 104, 107, 105, 71, 57, 119, 48, 66, 65, 81, 85, 70, 65, 65, 79, 66, 103, 81, 66, 86, 67, 56, 110, 104, 110, 89, 69, 53, 13, 10, 48, 74, 86, 121, 79, 110, 56, 72, 90, 112, 52, 113, 101, 51, 101, 106, 83, 100, 97, 119, 108, 56, 74, 50, 43, 107, 67, 82, 120, 80, 51, 57, 106, 57, 108, 106, 111, 116, 98, 111, 84, 82, 84, 67, 78, 54, 48, 55, 69, 89, 72, 113, 82, 115, 66, 56, 106, 85, 104, 101, 70, 117, 98, 106, 104, 80, 120, 86, 81, 118, 114, 57, 90, 50, 55, 48, 13, 10, 69, 82, 73, 79, 50, 67, 89, 109, 47, 102, 80, 88, 113, 114, 55, 79, 49, 66, 103, 51, 88, 100, 50, 98, 55, 118, 120, 80, 51, 104, 72, 71, 88, 108, 115, 109, 56, 113, 51, 88, 120, 102, 74, 85, 74, 78, 108, 84, 89, 66, 81, 53, 83, 53, 108, 122, 55, 67, 74, 86, 102, 111, 73, 109, 120, 120, 67, 83, 52, 49, 101, 121, 50, 81, 54, 113, 13, 10, 109, 117, 80, 81, 56, 120, 49, 52, 107, 106, 71, 67, 65, 87, 81, 119, 103, 103, 70, 103, 65, 103, 69, 66, 77, 68, 48, 119, 75, 68, 69, 83, 77, 66, 65, 71, 65, 49, 85, 69, 65, 119, 119, 74, 90, 87, 82, 112, 89, 50, 120, 112, 90, 87, 53, 48, 77, 82, 73, 119, 69, 65, 89, 68, 86, 81, 81, 75, 68, 65, 108, 108, 90, 71, 108, 106, 13, 10, 98, 71, 108, 108, 98, 110, 81, 67, 69, 81, 67, 50, 70, 86, 118, 54, 89, 97, 115, 50, 52, 43, 74, 109, 122, 51, 90, 120, 48, 120, 70, 47, 77, 65, 107, 71, 66, 83, 115, 79, 65, 119, 73, 97, 66, 81, 65, 119, 68, 81, 89, 74, 75, 111, 90, 73, 104, 118, 99, 78, 65, 81, 69, 66, 66, 81, 65, 69, 103, 103, 69, 65, 80, 86, 85, 104, 13, 10, 50, 112, 77, 57, 55, 101, 115, 112, 50, 88, 87, 115, 105, 106, 90, 117, 57, 57, 99, 52, 115, 115, 76, 84, 43, 55, 102, 49, 111, 109, 80, 52, 104, 90, 55, 54, 53, 115, 110, 75, 74, 73, 69, 55, 79, 50, 107, 108, 57, 43, 88, 82, 102, 78, 75, 77, 116, 114, 73, 118, 102, 119, 104, 99, 77, 100, 52, 87, 52, 47, 43, 104, 103, 81, 115, 68, 13, 10, 65, 111, 108, 66, 80, 99, 52, 107, 69, 49, 116, 111, 122, 97, 68, 66, 120, 53, 87, 116, 48, 73, 82, 87, 110, 113, 120, 111, 70, 57, 78, 103, 71, 81, 54, 78, 105, 80, 118, 120, 51, 48, 54, 89, 102, 108, 47, 83, 109, 97, 105, 108, 52, 115, 97, 86, 76, 100, 104, 100, 120, 107, 54, 55, 43, 74, 75, 105, 71, 65, 50, 69, 55, 111, 90, 72, 13, 10, 53, 66, 69, 110, 66, 88, 56, 102, 83, 75, 48, 120, 84, 110, 47, 76, 87, 49, 73, 85, 104, 119, 48, 52, 69, 109, 51, 90, 117, 66, 90, 120, 79, 54, 79, 80, 69, 88, 66, 53, 43, 104, 110, 72, 88, 101, 102, 114, 80, 102, 50, 66, 87, 104, 81, 113, 73, 43, 112, 106, 109, 110, 82, 114, 115, 112, 108, 80, 68, 72, 84, 74, 120, 57, 56, 57, 13, 10, 113, 117, 69, 103, 109, 75, 55, 56, 82, 107, 112, 81, 48, 98, 78, 52, 104, 111, 114, 53, 99, 107, 57, 107, 114, 84, 55, 68, 83, 69, 115, 43, 89, 76, 99, 115, 50, 89, 77, 100, 65, 74, 78, 99, 69, 90, 104, 51, 66, 50, 104, 43, 90, 107, 70, 113, 107, 78, 103, 116, 51, 73, 49, 114, 48, 97, 104, 114, 80, 115, 104, 54, 102, 86, 86, 80, 13, 10, 75, 113, 113, 104, 71, 69, 70, 106, 87, 72, 89, 69, 51, 71, 81, 43, 82, 106, 110, 121, 114, 118, 120, 100, 86, 74, 67, 104, 116, 110, 122, 70, 81, 65, 65, 65, 65, 65, 65, 65, 65, 65, 61, 61, 13, 10, 13, 10, 45, 45, 95, 53, 55, 54, 70, 67, 49, 49, 66, 45, 51, 52, 50, 57, 45, 52, 56, 67, 52, 45, 65, 51, 54, 57, 45, 56, 69, 51, 49, 67, 65, 50, 54, 57, 57, 53, 70, 95, 45, 45, 13, 10 };
        int indexOfNULL = Array.IndexOf<byte>(input, 0);
        Console.WriteLine("Found NUL in input at index: " + indexOfNULL);
        var message = ParseMessage(input);

        if (message.Body is Multipart)
        {
            var multipart = message.Body as Multipart;
            var firstMimePart = multipart.First() as MimePart;
            using (var msOut = new MemoryStream())
            {
                firstMimePart.ContentObject.WriteTo(msOut);
                var output = msOut.ToArray();
                var temp = String.Join(", ", output);
                indexOfNULL = Array.IndexOf<byte>(output, 0);
                Console.WriteLine("Found NUL in output at index: " + indexOfNULL);
            }
        }

        Console.ReadLine();
    }

    private static MimeMessage ParseMessage(byte[] data)
    {
        using (var ms = new MemoryStream(data))
        {
            Parser p = new Parser(ms);
            return p.ParseMessage();
        }
    }

Thanks!

/Mikkel

SecureMimeContext.Sign does not support chain of certificates

Hello.
I wrote piece of code using MimeKit for email signing/encryption. I used signing certificate issued by my organization based on specific certification path starting from root. In order to sign message content I used MultipartSigned class:
MultipartSigned mps = MultipartSigned.Create(context, signer, mpMain);
based on signer with second constructor with chain of certificates.
In some reason I don't get in return whole chain.
I checked MimeKit sources and found something to consider:
In MultipartSigned.cs in public static MultipartSigned Create (SecureMimeContext ctx, CmsSigner signer, MimeEntity entity) signing is performed by
var signature = ctx.Sign (signer, memory);
Next in SecureMimeContext.cs method
public ApplicationPkcs7Signature Sign (CmsSigner signer, Stream content)
performs private method:

Stream Sign (CmsSigner signer, Stream content, bool encapsulate)
{
    var signedData = new CmsSignedDataStreamGenerator ();
    signedData.AddSigner (signer.PrivateKey, signer.Certificate, GetDigestOid (signer.DigestAlgorithm), AddSecureMimeCapabilities (signer.SignedAttributes), signer.UnsignedAttributes);
    var memory = new MemoryStream ();
    using (var stream = signedData.Open (memory, encapsulate)) {
        content.CopyTo (stream, 4096);
    }
    memory.Position = 0;
    return memory;
}

You do not pass chain of certificates if exists to signedData instance.
It seems like passing chain of certificates (to signer object) can't affect.

Am I wrong?

Cheers.

MimeMessage.Sender is an InternetAddressList, expected: InternetAddress

RFC-5322 section 3.6.2 defines the From and Sender headers. From is a list of authors, Sender is the transmitting author. Sender is required anytime From has more than one author.

In MimeKit, is Sender implemented as a list because it needs to support things that don't comply with RFC-5322?

MultipartSigned forces body ContentTransferEncoding for non-binary content

Part of my project (NHIN Direct) involves sending signed and encrypted MultipartReport content (RFC 3462). I am having some trouble with the ContentTransferEncoding of the parts within the MultipartReport after sending.

RFC 3462 says that 7-bit encoding should be sufficient, and so I'm trying to use 7-bit, but MultipartSigned.PrepareEntityForSigning is forcing it to either Base64 or QuotedPrintable.

I don't understand the motivation behind using those two encodings when signing, but I don't think that QuotedPrintable is required if the source content is not binary.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.