本文整理汇总了C#中MailKit.Net.Imap.ImapEngine类的典型用法代码示例。如果您正苦于以下问题:C# ImapEngine类的具体用法?C# ImapEngine怎么用?C# ImapEngine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ImapEngine类属于MailKit.Net.Imap命名空间,在下文中一共展示了ImapEngine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例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;
};
}
示例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));
}
}
示例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));
}
示例6: ThreadMatches
static void ThreadMatches (ImapEngine engine, ImapCommand ic, int index)
{
ic.UserData = ImapUtils.ParseThreads (engine, ic.Folder.UidValidity, ic.CancellationToken);
}
示例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;
}
示例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);
//.........这里部分代码省略.........
示例9: QResyncFetch
static void QResyncFetch (ImapEngine engine, ImapCommand ic, int index)
{
ic.Folder.OnFetch (engine, index, ic.CancellationToken);
}
示例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 ());
}
}
}
}
示例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.");
}
}
}
}
示例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.");
}
}
}
}
示例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);
}
}
}
}
示例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);
}
}
示例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));
}