Thread: [csmaild-cvs] csmaild/src/Imap/Commands ListCommand.cs,1.6,1.7 LsubCommand.cs,1.5,1.6 SubscribeComma
Brought to you by:
tamc
|
From: <ta...@us...> - 2003-08-05 01:44:42
|
Update of /cvsroot/csmaild/csmaild/src/Imap/Commands
In directory sc8-pr-cvs1:/tmp/cvs-serv679/src/Imap/Commands
Modified Files:
ListCommand.cs LsubCommand.cs SubscribeCommand.cs
UnsubscribeCommand.cs
Log Message:
LIST, LSUB, SUBSCRIBE, UNSUBSCRIBE are done (hopefully)
Index: ListCommand.cs
===================================================================
RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/ListCommand.cs,v
retrieving revision 1.6
retrieving revision 1.7
diff -C2 -d -r1.6 -r1.7
*** ListCommand.cs 30 Jul 2003 22:37:12 -0000 1.6
--- ListCommand.cs 5 Aug 2003 01:44:39 -0000 1.7
***************
*** 49,55 ****
}
! private string ListSearchToRegex(string reference, string listSearch)
{
! string rv = "^" + mReferenceName;
char[] wildCards = CommandPart.ListWildcards.ToCharArray();
int lastIdx = 0;
--- 49,55 ----
}
! public static string ListSearchToRegex(string reference, string listSearch)
{
! string rv = "^" + reference;
char[] wildCards = CommandPart.ListWildcards.ToCharArray();
int lastIdx = 0;
***************
*** 83,87 ****
}
! private string BuildFlagList(Mailbox box)
{
StringBuilder str = new StringBuilder();
--- 83,87 ----
}
! public static string BuildFlagList(Mailbox box)
{
StringBuilder str = new StringBuilder();
***************
*** 92,96 ****
{
first = false;
! str.Append("NoSelect");
}
--- 92,96 ----
{
first = false;
! str.Append("\\NoSelect");
}
***************
*** 100,104 ****
str.Append(" ");
first = false;
! str.Append("NoInferiors");
}
--- 100,104 ----
str.Append(" ");
first = false;
! str.Append("\\NoInferiors");
}
***************
*** 108,112 ****
str.Append(" ");
first = false;
! str.Append("NoInferiors");
}
--- 108,112 ----
str.Append(" ");
first = false;
! str.Append("\\Marked");
}
***************
*** 116,120 ****
str.Append(" ");
first = false;
! str.Append("NoInferiors");
}
--- 116,120 ----
str.Append(" ");
first = false;
! str.Append("\\Unmarked");
}
Index: LsubCommand.cs
===================================================================
RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/LsubCommand.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** LsubCommand.cs 29 Jul 2003 00:46:28 -0000 1.5
--- LsubCommand.cs 5 Aug 2003 01:44:39 -0000 1.6
***************
*** 2,5 ****
--- 2,6 ----
using System;
+ using System.Text.RegularExpressions;
namespace Imap.Commands
***************
*** 10,13 ****
--- 11,18 ----
public class LsubCommand : ImapCommand
{
+ private string mReferenceName;
+ private string mMailboxSearchPattern;
+ private bool[] mSubscribedHandled;
+
public LsubCommand(ImapServer svr) : base(svr, "LSUB", ImapCommand.AuthSelectedState, ArgumentType.AString, ArgumentType.ListString)
{
***************
*** 16,24 ****
override protected void InternalProcess()
{
! // TODO: actually handle the arguments
! foreach(Mailbox box in mConnection.User.Mailboxes)
! mConnection.SendUntaggedMessage("LSUB () \"/\" \"" + box.Name + "\"");
mConnection.SendTaggedMessage("OK LSUB completed");
}
}
--- 21,84 ----
override protected void InternalProcess()
{
! mSubscribedHandled = new bool[mConnection.User.SubscribedMailboxes.Count];
!
! mReferenceName = mParsedArguments[0] as string;
! mMailboxSearchPattern = ListCommand.ListSearchToRegex(mReferenceName, mParsedArguments[1] as string);
!
! // if we have a reference name, navigate to it and perform the list from that level
! if(mReferenceName != string.Empty)
! {
! Mailbox box = mConnection.User.Mailboxes.FindMailbox(mReferenceName);
! if(box != null)
! ListBoxes(box.Children);
! }
! else
! ListBoxes(mConnection.User.Mailboxes);
!
! for(int idx = 0; idx < mSubscribedHandled.Length; ++idx)
! if(!mSubscribedHandled[idx])
! mConnection.SendUntaggedMessage("LSUB () \"/\" \"" + mConnection.User.SubscribedMailboxes[idx] + "\"");
mConnection.SendTaggedMessage("OK LSUB completed");
+
+ }
+
+ private bool ListBoxes(MailboxCollection boxes)
+ {
+ bool rv = false;
+ foreach(Mailbox box in boxes)
+ {
+ int idx = mConnection.User.SubscribedMailboxes.IndexOf(box.FullName);
+ if(idx != -1)
+ mSubscribedHandled[idx] = true;
+
+ if(Regex.IsMatch(box.FullName, mMailboxSearchPattern))
+ {
+ // it's a match and it's subscribed
+ if(idx != -1)
+ mConnection.SendUntaggedMessage("LSUB " + ListCommand.BuildFlagList(box) + " \"/\" \"" + box.FullName + "\"");
+ else
+ {
+ // it's a match, but not subscribed, if we have subscribed (but not matched) children, then we print
+ if(box.HasChildren)
+ {
+ if(ListBoxes(box.Children))
+ {
+ bool oldVal = box.NoSelect;
+ box.NoSelect = true;
+ mConnection.SendUntaggedMessage("LSUB " + ListCommand.BuildFlagList(box) + " \"/\" \"" + box.FullName + "\"");
+ box.NoSelect = oldVal;
+ }
+ continue;
+ }
+ }
+ }
+ else if(idx != -1)
+ rv = true;
+
+ if(box.HasChildren)
+ ListBoxes(box.Children);
+ }
+ return rv;
}
}
Index: SubscribeCommand.cs
===================================================================
RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/SubscribeCommand.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** SubscribeCommand.cs 29 Jul 2003 00:46:28 -0000 1.5
--- SubscribeCommand.cs 5 Aug 2003 01:44:39 -0000 1.6
***************
*** 1,2 ****
--- 1,4 ----
+ using Common;
+
using System;
***************
*** 8,12 ****
public class SubscribeCommand : ImapCommand
{
! public SubscribeCommand(ImapServer svr) : base(svr, "SUBSCRIBE", ImapCommand.AuthSelectedState)
{
}
--- 10,14 ----
public class SubscribeCommand : ImapCommand
{
! public SubscribeCommand(ImapServer svr) : base(svr, "SUBSCRIBE", ImapCommand.AuthSelectedState, ArgumentType.AString)
{
}
***************
*** 14,18 ****
override protected void InternalProcess()
{
! //return false;
}
}
--- 16,38 ----
override protected void InternalProcess()
{
! string boxName = mParsedArguments[0] as String;
!
! Mailbox box = mConnection.User.Mailboxes.FindMailbox(boxName);
! if(box == null)
! {
! mConnection.SendTaggedMessage("NO Mailbox doesn't exist");
! return;
! }
!
! if(mConnection.User.SubscribedMailboxes.IndexOf(box.FullName) != -1)
! {
! mConnection.SendTaggedMessage("NO Already subscribed");
! return;
! }
!
! mConnection.User.SubscribedMailboxes.Add(box.FullName);
! mConnection.User.Save();
!
! mConnection.SendTaggedMessage("OK SUBSCRIBE completed");
}
}
Index: UnsubscribeCommand.cs
===================================================================
RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/UnsubscribeCommand.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** UnsubscribeCommand.cs 29 Jul 2003 00:46:28 -0000 1.5
--- UnsubscribeCommand.cs 5 Aug 2003 01:44:39 -0000 1.6
***************
*** 1,2 ****
--- 1,4 ----
+ using Common;
+
using System;
***************
*** 8,12 ****
public class UnsubscribeCommand : ImapCommand
{
! public UnsubscribeCommand(ImapServer svr) : base(svr, "UNSUBSCRIBE", ImapCommand.AuthSelectedState)
{
}
--- 10,14 ----
public class UnsubscribeCommand : ImapCommand
{
! public UnsubscribeCommand(ImapServer svr) : base(svr, "UNSUBSCRIBE", ImapCommand.AuthSelectedState, ArgumentType.AString)
{
}
***************
*** 14,18 ****
override protected void InternalProcess()
{
! //return false;
}
}
--- 16,31 ----
override protected void InternalProcess()
{
! string boxName = mParsedArguments[0] as String;
!
! if(mConnection.User.SubscribedMailboxes.IndexOf(boxName) == -1)
! {
! mConnection.SendTaggedMessage("NO not subscibed to that mailbox");
! return;
! }
!
! mConnection.User.SubscribedMailboxes.Remove(boxName);
! mConnection.User.Save();
!
! mConnection.SendTaggedMessage("OK UNSUBSCRIBE completed");
}
}
|