本文整理汇总了C#中MailKit.Net.Imap.ImapEngine类的典型用法代码示例。如果您正苦于以下问题:C# ImapEngine类的具体用法?C# ImapEngine怎么用?C# ImapEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImapEngine类属于MailKit.Net.Imap命名空间,在下文中一共展示了ImapEngine类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C#代码示例。
示例1: ImapFolder
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapFolder"/> class.
/// </summary>
/// <param name="engine">The IMAP engine.</param>
/// <param name="encodedName">The encoded name.</param>
/// <param name="attrs">The folder attributes.</param>
/// <param name="delim">The path delimeter.</param>
internal ImapFolder(ImapEngine engine, string encodedName, FolderAttributes attrs, char delim)
{
FullName = ImapEncoding.Decode (encodedName);
Name = GetBaseName (FullName, delim);
DirectorySeparator = delim;
EncodedName = encodedName;
Attributes = attrs;
Engine = engine;
}
开发者ID:rashoodkhan,项目名称:MailKit,代码行数:16,代码来源:ImapFolder.cs
示例2: ImapFolderConstructorArgs
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapFolderConstructorArgs"/> class.
/// </summary>
/// <param name="engine">The IMAP command engine.</param>
/// <param name="encodedName">The encoded name.</param>
/// <param name="attributes">The attributes.</param>
/// <param name="delim">The directory separator.</param>
internal ImapFolderConstructorArgs (ImapEngine engine, string encodedName, FolderAttributes attributes, char delim)
{
FullName = engine.DecodeMailboxName (encodedName);
Name = GetBaseName (FullName, delim);
DirectorySeparator = delim;
EncodedName = encodedName;
Attributes = attributes;
Engine = engine;
}
开发者ID:Gekctek,项目名称:MailKit,代码行数:16,代码来源:ImapFolderConstructorArgs.cs
示例3: ImapFolder
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapFolder"/> class.
/// </summary>
/// <param name="engine">The IMAP engine.</param>
/// <param name="encodedName">The encoded name.</param>
/// <param name="attrs">The folder attributes.</param>
/// <param name="delim">The path delimeter.</param>
internal ImapFolder(ImapEngine engine, string encodedName, FolderAttributes attrs, char delim)
{
FullName = engine.DecodeMailboxName (encodedName);
Name = GetBaseName (FullName, delim);
DirectorySeparator = delim;
EncodedName = encodedName;
Attributes = attrs;
Engine = engine;
engine.Disconnected += (sender, e) => {
Access = FolderAccess.None;
};
}
开发者ID:rajeshwarn,项目名称:MailKit,代码行数:20,代码来源:ImapFolder.cs
示例4: ImapCommand
/// <summary>
/// Initializes a new instance of the <see cref="MailKit.Net.Imap.ImapCommand"/> class.
/// </summary>
/// <remarks>
/// Creates a new <see cref="MailKit.Net.Imap.ImapCommand"/>.
/// </remarks>
/// <param name="engine">The IMAP engine that will be sending the command.</param>
/// <param name="cancellationToken">The cancellation token.</param>
/// <param name="folder">The IMAP folder that the command operates on.</param>
/// <param name="options">The formatting options.</param>
/// <param name="format">The command format.</param>
/// <param name="args">The command arguments.</param>
public ImapCommand (ImapEngine engine, CancellationToken cancellationToken, ImapFolder folder, FormatOptions options, string format, params object[] args)
{
UntaggedHandlers = new Dictionary<string, ImapUntaggedHandler> ();
RespCodes = new List<ImapResponseCode> ();
CancellationToken = cancellationToken;
Response = ImapCommandResponse.None;
Status = ImapCommandStatus.Created;
Engine = engine;
Folder = folder;
using (var builder = new MemoryStream ()) {
var plus = (Engine.Capabilities & ImapCapabilities.LiteralPlus) != 0 ? "+" : string.Empty;
int argc = 0;
byte[] buf;
string str;
char c;
for (int i = 0; i < format.Length; i++) {
if (format[i] == '%') {
switch (format[++i]) {
case '%': // a literal %
builder.WriteByte ((byte) '%');
break;
case 'c': // a character
c = (char) args[argc++];
builder.WriteByte ((byte) c);
break;
case 'd': // an integer
str = ((int) args[argc++]).ToString ();
buf = Encoding.ASCII.GetBytes (str);
builder.Write (buf, 0, buf.Length);
break;
case 'u': // an unsigned integer
str = ((uint) args[argc++]).ToString ();
buf = Encoding.ASCII.GetBytes (str);
builder.Write (buf, 0, buf.Length);
break;
case 'F': // an ImapFolder
var utf7 = ((ImapFolder) args[argc++]).EncodedName;
AppendString (options, true, builder, utf7);
break;
case 'L':
var literal = new ImapLiteral (options, args[argc++], UpdateProgress);
var length = literal.Length;
totalSize += length;
if (options.International)
str = "UTF8 (~{" + length + plus + "}\r\n";
else
str = "{" + length + plus + "}\r\n";
buf = Encoding.ASCII.GetBytes (str);
builder.Write (buf, 0, buf.Length);
parts.Add (new ImapCommandPart (builder.ToArray (), literal));
builder.SetLength (0);
if (options.International)
builder.WriteByte ((byte) ')');
break;
case 'S': // a string which may need to be quoted or made into a literal
AppendString (options, true, builder, (string) args[argc++]);
break;
case 'Q': // similar to %S but string must be quoted at a minimum
AppendString (options, false, builder, (string) args[argc++]);
break;
case 's': // a safe atom string
buf = Encoding.ASCII.GetBytes ((string) args[argc++]);
builder.Write (buf, 0, buf.Length);
break;
default:
throw new FormatException ();
}
} else {
builder.WriteByte ((byte) format[i]);
}
}
parts.Add (new ImapCommandPart (builder.ToArray (), null));
}
}
开发者ID:BehnamEmamian,项目名称:MailKit,代码行数:94,代码来源:ImapCommand.cs
示例5: OnVanished
internal void OnVanished (ImapEngine engine, CancellationToken cancellationToken)
{
var token = engine.ReadToken (cancellationToken);
UniqueIdSet vanished;
bool earlier = false;
if (token.Type == ImapTokenType.OpenParen) {
do {
token = engine.ReadToken (cancellationToken);
if (token.Type == ImapTokenType.CloseParen)
break;
if (token.Type != ImapTokenType.Atom)
throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "VANISHED", token);
var atom = (string) token.Value;
if (atom == "EARLIER")
earlier = true;
} while (true);
token = engine.ReadToken (cancellationToken);
}
if (token.Type != ImapTokenType.Atom || !UniqueIdSet.TryParse ((string) token.Value, UidValidity, out vanished))
throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "VANISHED", token);
OnMessagesVanished (new MessagesVanishedEventArgs (vanished, earlier));
}
开发者ID:dcga,项目名称:MailKit,代码行数:30,代码来源:ImapFolder.cs
示例6: ThreadMatches
static void ThreadMatches (ImapEngine engine, ImapCommand ic, int index)
{
ic.UserData = ImapUtils.ParseThreads (engine, ic.Folder.UidValidity, ic.CancellationToken);
}
开发者ID:dcga,项目名称:MailKit,代码行数:4,代码来源:ImapFolder.cs
示例7: SearchMatches
static void SearchMatches (ImapEngine engine, ImapCommand ic, int index)
{
var results = new SearchResults ();
var uids = new List<UniqueId> ();
ImapToken token;
ulong modseq;
uint uid;
do {
token = engine.PeekToken (ic.CancellationToken);
// keep reading UIDs until we get to the end of the line or until we get a "(MODSEQ ####)"
if (token.Type == ImapTokenType.Eoln || token.Type == ImapTokenType.OpenParen)
break;
token = engine.ReadToken (ic.CancellationToken);
if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out uid) || uid == 0)
throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "SEARCH", token);
uids.Add (new UniqueId (ic.Folder.UidValidity, uid));
} while (true);
if (token.Type == ImapTokenType.OpenParen) {
engine.ReadToken (ic.CancellationToken);
do {
token = engine.ReadToken (ic.CancellationToken);
if (token.Type == ImapTokenType.CloseParen)
break;
if (token.Type != ImapTokenType.Atom)
throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "SEARCH", token);
var atom = (string) token.Value;
switch (atom) {
case "MODSEQ":
token = engine.ReadToken (ic.CancellationToken);
if (token.Type != ImapTokenType.Atom || !ulong.TryParse ((string) token.Value, out modseq)) {
Debug.WriteLine ("Expected 64-bit nz-number as the MODSEQ value, but got: {0}", token);
throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token);
}
break;
}
token = engine.PeekToken (ic.CancellationToken);
} while (token.Type != ImapTokenType.Eoln);
}
results.UniqueIds = uids;
ic.UserData = results;
}
开发者ID:dcga,项目名称:MailKit,代码行数:55,代码来源:ImapFolder.cs
示例8: FetchSummaryItems
void FetchSummaryItems (ImapEngine engine, ImapCommand ic, int index)
{
var token = engine.ReadToken (ic.CancellationToken);
if (token.Type != ImapTokenType.OpenParen)
throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "FETCH", token);
var ctx = (FetchSummaryContext) ic.UserData;
IMessageSummary isummary;
MessageSummary summary;
if (!ctx.Results.TryGetValue (index, out isummary)) {
summary = new MessageSummary (index);
ctx.Results.Add (index, summary);
} else {
summary = (MessageSummary) isummary;
}
do {
token = engine.ReadToken (ic.CancellationToken);
if (token.Type == ImapTokenType.CloseParen || token.Type == ImapTokenType.Eoln)
break;
if (token.Type != ImapTokenType.Atom)
throw ImapEngine.UnexpectedToken (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "FETCH", token);
var atom = (string) token.Value;
string format;
ulong value64;
uint value;
int idx;
switch (atom) {
case "INTERNALDATE":
token = engine.ReadToken (ic.CancellationToken);
switch (token.Type) {
case ImapTokenType.QString:
case ImapTokenType.Atom:
summary.InternalDate = ImapUtils.ParseInternalDate ((string) token.Value);
break;
case ImapTokenType.Nil:
summary.InternalDate = null;
break;
default:
throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token);
}
summary.Fields |= MessageSummaryItems.InternalDate;
break;
case "RFC822.SIZE":
token = engine.ReadToken (ic.CancellationToken);
if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out value))
throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token);
summary.Fields |= MessageSummaryItems.MessageSize;
summary.Size = value;
break;
case "BODYSTRUCTURE":
format = string.Format (ImapEngine.GenericItemSyntaxErrorFormat, "BODYSTRUCTURE", "{0}");
summary.Body = ImapUtils.ParseBody (engine, format, string.Empty, ic.CancellationToken);
summary.Fields |= MessageSummaryItems.BodyStructure;
break;
case "BODY":
token = engine.PeekToken (ic.CancellationToken);
if (token.Type == ImapTokenType.OpenBracket) {
// consume the '['
token = engine.ReadToken (ic.CancellationToken);
if (token.Type != ImapTokenType.OpenBracket)
throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token);
// References and/or other headers were requested...
do {
token = engine.ReadToken (ic.CancellationToken);
if (token.Type == ImapTokenType.CloseBracket)
break;
if (token.Type == ImapTokenType.OpenParen) {
do {
token = engine.ReadToken (ic.CancellationToken);
if (token.Type == ImapTokenType.CloseParen)
break;
// the header field names will generally be atoms or qstrings but may also be literals
switch (token.Type) {
case ImapTokenType.Literal:
engine.ReadLiteral (ic.CancellationToken);
break;
case ImapTokenType.QString:
case ImapTokenType.Atom:
break;
default:
throw ImapEngine.UnexpectedToken (ImapEngine.GenericItemSyntaxErrorFormat, atom, token);
//.........这里部分代码省略.........
开发者ID:dcga,项目名称:MailKit,代码行数:101,代码来源:ImapFolder.cs
示例9: QResyncFetch
static void QResyncFetch (ImapEngine engine, ImapCommand ic, int index)
{
ic.Folder.OnFetch (engine, index, ic.CancellationToken);
}
开发者ID:dcga,项目名称:MailKit,代码行数:4,代码来源:ImapFolder.cs
示例10: TestParseDovcotEnvelopeWithGroupAddresses
public void TestParseDovcotEnvelopeWithGroupAddresses ()
{
const string text = "(\"Mon, 13 Jul 2015 21:15:32 -0400\" \"Test message\" ((\"Example From\" NIL \"from\" \"example.com\")) ((\"Example Sender\" NIL \"sender\" \"example.com\")) ((\"Example Reply-To\" NIL \"reply-to\" \"example.com\")) ((NIL NIL \"boys\" NIL)(NIL NIL \"aaron\" \"MISSING_DOMAIN\")(NIL NIL \"jeff\" \"MISSING_DOMAIN\")(NIL NIL \"zach\" \"MISSING_DOMAIN\")(NIL NIL NIL NIL)(NIL NIL \"girls\" NIL)(NIL NIL \"alice\" \"MISSING_DOMAIN\")(NIL NIL \"hailey\" \"MISSING_DOMAIN\")(NIL NIL \"jenny\" \"MISSING_DOMAIN\")(NIL NIL NIL NIL)) NIL NIL NIL \"<[email protected]>\")";
using (var memory = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) {
using (var tokenizer = new ImapStream (memory, null, new NullProtocolLogger ())) {
using (var engine = new ImapEngine (null)) {
Envelope envelope;
engine.SetStream (tokenizer);
try {
envelope = ImapUtils.ParseEnvelope (engine, CancellationToken.None);
} catch (Exception ex) {
Assert.Fail ("Parsing ENVELOPE failed: {0}", ex);
return;
}
Assert.AreEqual ("\"Example Sender\" <[email protected]>", envelope.Sender.ToString ());
Assert.AreEqual ("\"Example From\" <[email protected]>", envelope.From.ToString ());
Assert.AreEqual ("\"Example Reply-To\" <[email protected]>", envelope.ReplyTo.ToString ());
Assert.AreEqual ("boys: aaron, jeff, zach;, girls: alice, hailey, jenny;", envelope.To.ToString ());
}
}
}
}
开发者ID:Gekctek,项目名称:MailKit,代码行数:26,代码来源:ImapUtilsTests.cs
示例11: TestParseExampleEnvelopeRfc3501
public void TestParseExampleEnvelopeRfc3501 ()
{
const string text = "(\"Wed, 17 Jul 1996 02:23:25 -0700 (PDT)\" \"IMAP4rev1 WG mtg summary and minutes\" ((\"Terry Gray\" NIL \"gray\" \"cac.washington.edu\")) ((\"Terry Gray\" NIL \"gray\" \"cac.washington.edu\")) ((\"Terry Gray\" NIL \"gray\" \"cac.washington.edu\")) ((NIL NIL \"imap\" \"cac.washington.edu\")) ((NIL NIL \"minutes\" \"CNRI.Reston.VA.US\") (\"John Klensin\" NIL \"KLENSIN\" \"MIT.EDU\")) NIL NIL \"<[email protected]>\")\r\n";
using (var memory = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) {
using (var tokenizer = new ImapStream (memory, null, new NullProtocolLogger ())) {
using (var engine = new ImapEngine (null)) {
Envelope envelope;
engine.SetStream (tokenizer);
try {
envelope = ImapUtils.ParseEnvelope (engine, CancellationToken.None);
} catch (Exception ex) {
Assert.Fail ("Parsing ENVELOPE failed: {0}", ex);
return;
}
var token = engine.ReadToken (CancellationToken.None);
Assert.AreEqual (ImapTokenType.Eoln, token.Type, "Expected new-line, but got: {0}", token);
Assert.IsTrue (envelope.Date.HasValue, "Parsed ENVELOPE date is null.");
Assert.AreEqual ("Wed, 17 Jul 1996 02:23:25 -0700", DateUtils.FormatDate (envelope.Date.Value), "Date does not match.");
Assert.AreEqual ("IMAP4rev1 WG mtg summary and minutes", envelope.Subject, "Subject does not match.");
Assert.AreEqual (1, envelope.From.Count, "From counts do not match.");
Assert.AreEqual ("\"Terry Gray\" <[email protected]>", envelope.From.ToString (), "From does not match.");
Assert.AreEqual (1, envelope.Sender.Count, "Sender counts do not match.");
Assert.AreEqual ("\"Terry Gray\" <[email protected]>", envelope.Sender.ToString (), "Sender does not match.");
Assert.AreEqual (1, envelope.ReplyTo.Count, "Reply-To counts do not match.");
Assert.AreEqual ("\"Terry Gray\" <[email protected]>", envelope.ReplyTo.ToString (), "Reply-To does not match.");
Assert.AreEqual (1, envelope.To.Count, "To counts do not match.");
Assert.AreEqual ("[email protected]", envelope.To.ToString (), "To does not match.");
Assert.AreEqual (2, envelope.Cc.Count, "Cc counts do not match.");
Assert.AreEqual ("[email protected], \"John Klensin\" <[email protected]>", envelope.Cc.ToString (), "Cc does not match.");
Assert.AreEqual (0, envelope.Bcc.Count, "Bcc counts do not match.");
Assert.IsNull (envelope.InReplyTo, "In-Reply-To is not null.");
Assert.AreEqual ("[email protected]", envelope.MessageId, "Message-Id does not match.");
}
}
}
}
开发者ID:Gekctek,项目名称:MailKit,代码行数:49,代码来源:ImapUtilsTests.cs
示例12: TestParseExampleBodyRfc3501
public void TestParseExampleBodyRfc3501 ()
{
const string text = "(\"TEXT\" \"PLAIN\" (\"CHARSET\" \"US-ASCII\") NIL NIL \"7BIT\" 3028 92)\r\n";
using (var memory = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) {
using (var tokenizer = new ImapStream (memory, null, new NullProtocolLogger ())) {
using (var engine = new ImapEngine (null)) {
BodyPartText basic;
BodyPart body;
engine.SetStream (tokenizer);
try {
body = ImapUtils.ParseBody (engine, "Unexpected token: {0}", string.Empty, CancellationToken.None);
} catch (Exception ex) {
Assert.Fail ("Parsing BODY failed: {0}", ex);
return;
}
var token = engine.ReadToken (CancellationToken.None);
Assert.AreEqual (ImapTokenType.Eoln, token.Type, "Expected new-line, but got: {0}", token);
Assert.IsInstanceOf<BodyPartText> (body, "Body types did not match.");
basic = (BodyPartText) body;
Assert.IsTrue (body.ContentType.IsMimeType ("text", "plain"), "Content-Type did not match.");
Assert.AreEqual ("US-ASCII", body.ContentType.Parameters["charset"], "charset param did not match");
Assert.IsNotNull (basic, "The parsed body is not BodyPartText.");
Assert.AreEqual ("7BIT", basic.ContentTransferEncoding, "Content-Transfer-Encoding did not match.");
Assert.AreEqual (3028, basic.Octets, "Octet count did not match.");
Assert.AreEqual (92, basic.Lines, "Line count did not match.");
}
}
}
}
开发者ID:Gekctek,项目名称:MailKit,代码行数:36,代码来源:ImapUtilsTests.cs
示例13: TestParseLabelsListWithNIL
public void TestParseLabelsListWithNIL ()
{
const string text = "(atom-label \\flag-label \"quoted-label\" NIL)\r\n";
using (var memory = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) {
using (var tokenizer = new ImapStream (memory, null, new NullProtocolLogger ())) {
using (var engine = new ImapEngine (null)) {
IList<string> labels;
engine.SetStream (tokenizer);
try {
labels = ImapUtils.ParseLabelsList (engine, CancellationToken.None);
} catch (Exception ex) {
Assert.Fail ("Parsing X-GM-LABELS failed: {0}", ex);
return;
}
var token = engine.ReadToken (CancellationToken.None);
Assert.AreEqual (ImapTokenType.Eoln, token.Type, "Expected new-line, but got: {0}", token);
}
}
}
}
开发者ID:Gekctek,项目名称:MailKit,代码行数:24,代码来源:ImapUtilsTests.cs
示例14: UntaggedQuotaRoot
static void UntaggedQuotaRoot (ImapEngine engine, ImapCommand ic, int index)
{
// The first token should be the mailbox name
ReadStringToken (engine, ic.CancellationToken);
// ...followed by 0 or more quota roots
var token = engine.PeekToken (ic.CancellationToken);
while (token.Type != ImapTokenType.Eoln) {
ReadStringToken (engine, ic.CancellationToken);
token = engine.PeekToken (ic.CancellationToken);
}
}
开发者ID:sstraus,项目名称:MailKit,代码行数:14,代码来源:ImapFolder.cs
示例15: UntaggedMyRights
static void UntaggedMyRights (ImapEngine engine, ImapCommand ic, int index)
{
var access = (AccessRights) ic.UserData;
// read the mailbox name
ReadStringToken (engine, ic.CancellationToken);
// read the access rights
access.AddRange (ReadStringToken (engine, ic.CancellationToken));
}
开发者ID:sstraus,项目名称:MailKit,代码行数:10,代码来源:ImapFolder.cs
示例16: UntaggedQuota
static void UntaggedQuota (ImapEngine engine, ImapCommand ic, int index)
{
string format = string.Format (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "QUOTA", "{0}");
var encodedName = ReadStringToken (engine, format, ic.CancellationToken);
ImapFolder quotaRoot;
FolderQuota quota;
if (!engine.GetCachedFolder (encodedName, out quotaRoot)) {
// Note: this shouldn't happen because the quota root should
// be one of the parent folders which will all have been added
// to the folder cache by this point.
}
ic.UserData = quota = new FolderQuota (quotaRoot);
var token = engine.ReadToken (ic.CancellationToken);
if (token.Type != ImapTokenType.OpenParen)
throw ImapEngine.UnexpectedToken (format, token);
while (token.Type != ImapTokenType.CloseParen) {
uint used, limit;
string resource;
token = engine.ReadToken (ic.CancellationToken);
if (token.Type != ImapTokenType.Atom)
throw ImapEngine.UnexpectedToken (format, token);
resource = (string) token.Value;
token = engine.ReadToken (ic.CancellationToken);
if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out used))
throw ImapEngine.UnexpectedToken (format, token);
token = engine.ReadToken (ic.CancellationToken);
if (token.Type != ImapTokenType.Atom || !uint.TryParse ((string) token.Value, out limit))
throw ImapEngine.UnexpectedToken (format, token);
switch (resource.ToUpperInvariant ()) {
case "MESSAGE":
quota.CurrentMessageCount = used;
quota.MessageLimit = limit;
break;
case "STORAGE":
quota.CurrentStorageSize = used;
quota.StorageLimit = limit;
break;
}
token = engine.PeekToken (ic.CancellationToken);
}
// read the closing paren
engine.ReadToken (ic.CancellationToken);
}
开发者ID:dcga,项目名称:MailKit,代码行数:58,代码来源:ImapFolder.cs
示例17: UntaggedMetadata
static void UntaggedMetadata (ImapEngine engine, ImapCommand ic, int index)
{
string format = string.Format (ImapEngine.GenericUntaggedResponseSyntaxErrorFormat, "METADATA", "{0}");
var encodedName = ReadStringToken (engine, format, ic.CancellationToken);
var metadata = (MetadataCollection) ic.UserData;
ImapFolder folder;
engine.GetCachedFolder (encodedName, out folder);
var token = engine.ReadToken (ic.CancellationToken);
if (token.Type != ImapTokenType.OpenParen)
throw ImapEngine.UnexpectedToken (format, token);
while (token.Type != ImapTokenType.CloseParen) {
var tag = ReadStringToken (engine, format, ic.CancellationToken);
var value = ReadStringToken (engine, format, ic.CancellationToken);
metadata.Add (new Metadata (MetadataTag.Create (tag), value));
token = engine.PeekToken (ic.CancellationToken);
}
// read the closing paren
engine.ReadToken (ic.CancellationToken);
}
开发者ID:dcga,项目名称:MailKit,代码行数:26,代码来源:ImapFolder.cs
示例18: TestParseExampleMultiLevelDovecotBodyStructure
public void TestParseExampleMultiLevelDovecotBodyStructure ()
{
const string text = "(((\"text\" \"plain\" (\"charset\" \"iso-8859-2\") NIL NIL \"quoted-printable\" 28 2 NIL NIL NIL NIL) (\"text\" \"html\" (\"charset\" \"iso-8859-2\") NIL NIL \"quoted-printable\" 1707 65 NIL NIL NIL NIL) \"alternative\" (\"boundary\" \"----=_NextPart_001_0078_01CBB179.57530990\") NIL NIL NIL) (\"message\" \"rfc822\" NIL NIL NIL \"7bit\" 641 (\"Sat, 8 Jan 2011 14:16:36 +0100\" \"Subj 2\" ((\"Some Name, SOMECOMPANY\" NIL \"recipient\" \"example.com\")) ((\"Some Name, SOMECOMPANY\" NIL \"recipient\" \"example.com\")) ((\"Some Name, SOMECOMPANY\" NIL \"recipient\" \"example.com\")) ((\"Recipient\" NIL \"example\" \"gmail.com\")) NIL NIL NIL NIL) (\"text\" \"plain\" (\"charset\" \"iso-8859-2\") NIL NIL \"quoted-printable\" 185 18 NIL NIL (\"cs\") NIL) 31 NIL (\"attachment\" NIL) NIL NIL) (\"message\" \"rfc822\" NIL NIL NIL \"7bit\" 50592 (\"Sat, 8 Jan 2011 13:58:39 +0100\" \"Subj 1\" ((\"Some Name, SOMECOMPANY\" NIL \"recipient\" \"example.com\")) ((\"Some Name, SOMECOMPANY\" NIL \"recipient\" \"example.com\")) ((\"Some Name, SOMECOMPANY\" NIL \"recipient\" \"example.com\")) ((\"Recipient\" NIL \"example\" \"gmail.com\")) NIL NIL NIL NIL) ( (\"text\" \"plain\" (\"charset\" \"iso-8859-2\") NIL NIL \"quoted-printable\" 4296 345 NIL NIL NIL NIL) (\"text\" \"html\" (\"charset\" \"iso-8859-2\") NIL NIL \"quoted-printable\" 45069 1295 NIL NIL NIL NIL) \"alternative\" (\"boundary\" \"----=_NextPart_000_0073_01CBB179.57530990\") NIL (\"cs\") NIL) 1669 NIL (\"attachment\" NIL) NIL NIL) \"mixed\" (\"boundary\" \"----=_NextPart_000_0077_01CBB179.57530990\") NIL (\"cs\") NIL)\r\n";
using (var memory = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) {
using (var tokenizer = new ImapStream (memory, null, new NullProtocolLogger ())) {
using (var engine = new ImapEngine (null)) {
BodyPartMultipart multipart;
BodyPart body;
engine.SetStream (tokenizer);
try {
body = ImapUtils.ParseBody (engine, "Unexpected token: {0}", string.Empty, CancellationToken.None);
} catch (Exception ex) {
Assert.Fail ("Parsing BODYSTRUCTURE failed: {0}", ex);
return;
}
var token = engine.ReadToken (CancellationToken.None);
Assert.AreEqual (ImapTokenType.Eoln, token.Type, "Expected new-line, but got: {0}", token);
Assert.IsInstanceOf<BodyPartMultipart> (body, "Body types did not match.");
multipart = (BodyPartMultipart) body;
Assert.IsTrue (body.ContentType.IsMimeType ("multipart", "mixed"), "Content-Type did not match.");
Assert.AreEqual ("----=_NextPart_000_0077_01CBB179.57530990", body.ContentType.Parameters["boundary"], "boundary param did not match");
Assert.AreEqual (3, multipart.BodyParts.Count, "BodyParts count does not match.");
Assert.IsInstanceOf<BodyPartMultipart> (multipart.BodyParts[0], "The type of the first child does not match.");
Assert.IsInstanceOf<BodyPartMessage> (multipart.BodyParts[1], "The type of the second child does not match.");
Assert.IsInstanceOf<BodyPartMessage> (multipart.BodyParts[2], "The type of the third child does not match.");
// FIXME: assert more stuff?
}
}
}
}
开发者ID:Gekctek,项目名称:MailKit,代码行数:37,代码来源:ImapUtilsTests.cs
示例19: ReadLiteralData
static void ReadLiteralData (ImapEngine engine, CancellationToken cancellationToken)
{
var buf = new byte[4096];
int nread;
do {
nread = engine.Stream.Read (buf, 0, buf.Length, cancellationToken);
} while (nread > 0);
}
开发者ID:dcga,项目名称:MailKit,代码行数:9,代码来源:ImapFolder.cs
示例20: TestParseExampleThreads
public void TestParseExampleThreads ()
{
const string text = "(2)(3 6 (4 23)(44 7 96))\r\n";
using (var memory = new MemoryStream (Encoding.ASCII.GetBytes (text), false)) {
using (var tokenizer = new ImapStream (memory, null, new NullProtocolLogger ())) {
using (var engine = new ImapEngine (null)) {
IList<MessageThread> threads;
engine.SetStream (tokenizer);
try {
threads = ImapUtils.ParseThreads (engine, 0, CancellationToken.None);
} catch (Exception ex) {
Assert.Fail ("Parsing THREAD response failed: {0}", ex);
return;
}
var token = engine.ReadToken (CancellationToken.None);
Assert.AreEqual (ImapTokenType.Eoln, token.Type, "Expected new-line, but got: {0}", token);
Assert.AreEqual (2, threads.Count, "Expected 2 threads.");
Assert.AreEqual ((uint) 2, threads[0].UniqueId.Value.Id);
Assert.AreEqual ((uint) 3, threads[1].UniqueId.Value.Id);
var branches = threads[1].Children.ToArray ();
Assert.AreEqual (1, branches.Length, "Expected 1 child.");
Assert.AreEqual ((uint) 6, branches[0].UniqueId.Value.Id);
branches = branches[0].Children.ToArray ();
Assert.AreEqual (2, branches.Length, "Expected 2 branches.");
Assert.AreEqual ((uint) 4, branches[0].UniqueId.Value.Id);
Assert.AreEqual ((uint) 44, branches[1].UniqueId.Value.Id);
var children = branches[0].Children.ToArray ();
Assert.AreEqual (1, children.Length, "Expected 1 child.");
Assert.AreEqual ((uint) 23, children[0].UniqueId.Value.Id);
Assert.AreEqual (0, children[0].Children.Count (), "Expected no children.");
children = branches[1].Children.ToArray ();
Assert.AreEqual (1, children.Length, "Expected 1 child.");
Assert.AreEqual ((uint) 7, children[0].UniqueId.Value.Id);
children = children[0].Children.ToArray ();
Assert.AreEqual (1, children.Length, "Expected 1 child.");
Assert.AreEqual ((uint) 96, children[0].UniqueId.Value.Id);
Assert.AreEqual (0, children[0].Children.Count (), "Expected no children.");
}
}
}
}
开发者ID:Gekctek,项目名称:MailKit,代码行数:53,代码来源:ImapUtilsTests.cs
注:本文中的MailKit.Net.Imap.ImapEngine类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论