trunk delimiter patch

Jerry Lundström <[email protected]> Tue, 17 May 2005 16:27:50 +0200
Newsgroups gmane.mail.imap.binc.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------060304090207020903060600
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

This patch add what I belive to be full support for changing the 
delimiter of folders in IMAP.

Side note, this is very needed for us when moving from courier since 
nearly all clients seem to store the delimiter after first contact with 
the IMAP server.

-- 
Jerry Lundström
Sektionen för IT och media, Stockholms universitet
+46 (0)8 16 19 99 / http://www.it.su.se

--------------060304090207020903060600
Content-Type: text/x-patch;
 name="bincimap-trunk-delimiter.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="bincimap-trunk-delimiter.patch"

Index: bincimap.trunk/src/depot.cc
===================================================================
--- bincimap.trunk/src/depot.cc	(revision 321)
+++ bincimap.trunk/src/depot.cc	(working copy)
@@ -595,10 +595,10 @@
   trim(mm, string(&delimiter, 1));
   string tmp = mm;
   uppercase(tmp);
-  if (tmp != "INBOX" && tmp.substr(0, 6) != "INBOX/") {
+  if (tmp != "INBOX" && tmp.substr(0, 6) != prefix) {
     setLastError("With a Maildir++ depot, you must create all"
 		 " mailboxes under INBOX. Try creating"
-		 " INBOX/" + mm + ".");
+		 " " + prefix + mm + " .");
     return "";
   }
 
@@ -619,13 +619,13 @@
     setLastError("Invalid character combination " 
 		 + twodelim + " in mailbox name");
     return "";
-  } else if (mm != "" && mm.substr(1).find('.') != string::npos) {
+  } else if (mm != "" && delimiter != '.' && mm.substr(1).find('.') != string::npos) {
     setLastError("Invalid character '.' in mailbox name");
     return "";
   } else {
     string tmp = mm.substr(6);
     for (string::iterator i = tmp.begin(); i != tmp.end(); ++i)
-      if (*i == '/') *i = '.';
+      if (*i == delimiter) *i = '.';
 
     return "." + tmp;
   }
@@ -635,7 +635,7 @@
 string MaildirPPDepot::filenameToMailbox(const string &m) const
 {
   if (m == ".") return "INBOX";
-  else if (m.find(delimiter) != string::npos) return "";
+  else if (delimiter != '.' && m.find(delimiter) != string::npos) return "";
   else if (m != "" && m[0] == '.') {
     string tmp = m;
     for (string::iterator i = tmp.begin(); i != tmp.end(); ++i)
Index: bincimap.trunk/src/session-initialize-bincimapd.cc
===================================================================
--- bincimap.trunk/src/session-initialize-bincimapd.cc	(revision 321)
+++ bincimap.trunk/src/session-initialize-bincimapd.cc	(working copy)
@@ -180,6 +180,10 @@
   depot->assign(new Maildir());
   depot->setDefaultType("Maildir");
 
+  // Configurable delimiter to ease crossover from other IMAPservers
+  string delimiter = session.getEnv("DELIMITER");
+  if (delimiter != "") depot->setDelimiter(delimiter[0]);
+
   BrokerFactory &brokerfactory = BrokerFactory::getInstance();
 
   brokerfactory.assign("APPEND", new AppendOperator());

--------------060304090207020903060600--