Update of /cvsroot/csmaild/csmaild/src/Imap/Commands
In directory sc8-pr-cvs1:/tmp/cvs-serv15627/src/Imap/Commands
Modified Files:
ListCommand.cs
Log Message:
Actually uses the arguments, *should* be completed
Index: ListCommand.cs
===================================================================
RCS file: /cvsroot/csmaild/csmaild/src/Imap/Commands/ListCommand.cs,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ListCommand.cs 29 Jul 2003 00:46:28 -0000 1.5
--- ListCommand.cs 30 Jul 2003 22:37:12 -0000 1.6
***************
*** 3,6 ****
--- 3,7 ----
using System;
using System.Text;
+ using System.Text.RegularExpressions;
namespace Imap.Commands
***************
*** 11,14 ****
--- 12,18 ----
public class ListCommand : ImapCommand
{
+ private string mReferenceName;
+ private string mMailboxSearchPattern;
+
public ListCommand(ImapServer svr) : base(svr, "LIST", ImapCommand.AuthSelectedState, ArgumentType.AString, ArgumentType.ListString)
{
***************
*** 17,21 ****
override protected void InternalProcess()
{
! ListBoxes(mConnection.User.Mailboxes);
mConnection.SendTaggedMessage("OK LIST completed");
--- 21,36 ----
override protected void InternalProcess()
{
! mReferenceName = mParsedArguments[0] as string;
! mMailboxSearchPattern = 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);
mConnection.SendTaggedMessage("OK LIST completed");
***************
*** 24,35 ****
private void ListBoxes(MailboxCollection boxes)
{
- // TODO: actually handle the arguments
foreach(Mailbox box in boxes)
{
! mConnection.SendUntaggedMessage("LIST " + BuildFlagList(box) + " \"/\" \"" + box.FullName + "\"");
if(box.HasChildren)
ListBoxes(box.Children);
}
}
--- 39,84 ----
private void ListBoxes(MailboxCollection boxes)
{
foreach(Mailbox box in boxes)
{
! if(Regex.IsMatch(box.FullName, mMailboxSearchPattern))
! mConnection.SendUntaggedMessage("LIST " + BuildFlagList(box) + " \"/\" \"" + box.FullName + "\"");
if(box.HasChildren)
ListBoxes(box.Children);
}
+ }
+
+ private string ListSearchToRegex(string reference, string listSearch)
+ {
+ string rv = "^" + mReferenceName;
+ char[] wildCards = CommandPart.ListWildcards.ToCharArray();
+ int lastIdx = 0;
+ while(true)
+ {
+ int idx = listSearch.IndexOfAny(wildCards, lastIdx);
+
+ if(idx == -1)
+ {
+ if(lastIdx < listSearch.Length)
+ rv += Regex.Escape(listSearch.Substring(lastIdx));
+ break;
+ }
+ else
+ {
+ if(idx != lastIdx)
+ rv += Regex.Escape(listSearch.Substring(lastIdx, idx-lastIdx));
+ switch(listSearch[idx])
+ {
+ case '%':
+ rv += "[^/]*";
+ break;
+ case '*':
+ rv += ".*";
+ break;
+ }
+ lastIdx = idx+1;
+ }
+ }
+ return rv + "$";
}
|