Skip to content

Commit

Permalink
add UIDValidity support
Browse files Browse the repository at this point in the history
  • Loading branch information
andyedinborough committed Sep 3, 2013
1 parent c1ebc24 commit c248b08
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 46 deletions.
33 changes: 17 additions & 16 deletions Imap/Mailbox.cs
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@

namespace AE.Net.Mail.Imap {
public class Mailbox {
public Mailbox() : this(string.Empty) { }
public Mailbox(string name) {
Name = ModifiedUtf7Encoding.Decode(name);
Flags = new string[0];
}
public virtual string Name { get; internal set; }
public virtual int NumNewMsg { get; internal set; }
public virtual int NumMsg { get; internal set; }
public virtual int NumUnSeen { get; internal set; }
public virtual string[] Flags { get; internal set; }
public virtual bool IsWritable { get; internal set; }
public class Mailbox {
public Mailbox() : this(string.Empty) { }
public Mailbox(string name) {
Name = ModifiedUtf7Encoding.Decode(name);
Flags = new string[0];
}
public virtual string Name { get; internal set; }
public virtual int NumNewMsg { get; internal set; }
public virtual int NumMsg { get; internal set; }
public virtual int NumUnSeen { get; internal set; }
public virtual int UIDValidity { get; internal set; }
public virtual string[] Flags { get; internal set; }
public virtual bool IsWritable { get; internal set; }

internal void SetFlags(string flags) {
Flags = flags.Split(' ');
}
}
internal void SetFlags(string flags) {
Flags = flags.Split(' ');
}
}
}

9 changes: 6 additions & 3 deletions ImapClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -286,13 +286,16 @@ public virtual Mailbox Examine(string mailbox) {
while (response.StartsWith("*")) {
Match m;
m = Regex.Match(response, @"(\d+) EXISTS");
if (m.Groups.Count > 1) { x.NumMsg = Convert.ToInt32(m.Groups[1].ToString()); }
if (m.Groups.Count > 1) { x.NumMsg = m.Groups[1].ToString().ToInt(); }
m = Regex.Match(response, @"(\d+) RECENT");
if (m.Groups.Count > 1)
x.NumNewMsg = Convert.ToInt32(m.Groups[1].ToString());
x.NumNewMsg = m.Groups[1].Value.ToInt();
m = Regex.Match(response, @"UNSEEN (\d+)");
if (m.Groups.Count > 1)
x.NumUnSeen = Convert.ToInt32(m.Groups[1].ToString());
x.NumUnSeen = m.Groups[1].Value.ToInt();
m = Regex.Match(response, @"UIDVALIDITY (\d+)");
if (m.Groups.Count > 1)
x.UIDValidity = m.Groups[1].Value.ToInt();
m = Regex.Match(response, @" FLAGS \((.*?)\)");
if (m.Groups.Count > 1)
x.SetFlags(m.Groups[1].ToString());
Expand Down
54 changes: 27 additions & 27 deletions Utilities.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,41 +192,41 @@ internal static string QuoteString(this string value) {
.Replace("\"", "\\\"") + "\"";
}

internal static bool StartsWithWhiteSpace(this string line) {
if (string.IsNullOrEmpty(line))
return false;
var chr = line[0];
return IsWhiteSpace(chr);
}
internal static bool StartsWithWhiteSpace(this string line) {
if (string.IsNullOrEmpty(line))
return false;
var chr = line[0];
return IsWhiteSpace(chr);
}

internal static bool EndsWithWhiteSpace(this string line) {
if (string.IsNullOrEmpty(line))
return false;
var chr = line[line.Length - 1];
return IsWhiteSpace(chr);
}
internal static bool EndsWithWhiteSpace(this string line) {
if (string.IsNullOrEmpty(line))
return false;
var chr = line[line.Length - 1];
return IsWhiteSpace(chr);
}

internal static bool IsWhiteSpace(this char chr) {
return chr == ' ' || chr == '\t' || chr == '\n' || chr == '\r';
}
internal static bool IsWhiteSpace(this char chr) {
return chr == ' ' || chr == '\t' || chr == '\n' || chr == '\r';
}

internal static string TrimStartOnce(this string line) {
var result = line;
internal static string TrimStartOnce(this string line) {
var result = line;

if (result.StartsWithWhiteSpace())
result = result.Substring(1, result.Length - 1);
if (result.StartsWithWhiteSpace())
result = result.Substring(1, result.Length - 1);

return result;
}
return result;
}

internal static string TrimEndOnce(this string line) {
var result = line;
internal static string TrimEndOnce(this string line) {
var result = line;

if (result.EndsWithWhiteSpace())
result = result.Substring(0, result.Length - 1);
if (result.EndsWithWhiteSpace())
result = result.Substring(0, result.Length - 1);

return result;
}
return result;
}

public static string DecodeQuotedPrintable(string value, Encoding encoding = null) {
if (encoding == null) {
Expand Down

0 comments on commit c248b08

Please sign in to comment.