Index: b/SoObjects/SOGo/SOGoSieveManager.m
===================================================================
--- a/SoObjects/SOGo/SOGoSieveManager.m	2012-07-04 18:57:44.000000000 +0200
+++ b/SoObjects/SOGo/SOGoSieveManager.m	2012-07-04 20:13:17.000000000 +0200
@@ -38,6 +38,7 @@
 #import "../Mailer/SOGoMailAccount.h"
 
 #import "SOGoSieveManager.h"
+#import "SOGoUserManager.h"
 
 typedef enum {
   UIxFilterFieldTypeAddress,
@@ -623,10 +624,12 @@
   NSMutableArray *req;
   NSMutableString *script, *header;
   NSDictionary *result, *values;
+  NSDictionary *contactInfos;
+  SOGoUserManager *um;
   SOGoUserDefaults *ud;
   SOGoDomainDefaults *dd;
   NGSieveClient *client;
-  NSString *filterScript, *v, *sieveServer;
+  NSString *filterScript, *v, *sieveScheme, *sieveServer, *sieveQuery, *ldapImapServer;
   NSURL *url;
   
   int sievePort;
@@ -749,10 +752,16 @@
   //
   // Values such as "localhost" or "localhost:2000" are NOT supported.
   //
+  sieveScheme = @"sieve";
   sieveServer = [dd sieveServer];
   sievePort = 2000;
-  url = nil;
-      
+  sieveQuery = @"";
+  url = [NSURL URLWithString: sieveServer];
+
+  if ([url scheme])
+    sieveScheme = [url scheme];
+  if ([url host])
+    sieveServer = [url host];
   if (!sieveServer)
     {
       NSString *s;
@@ -770,16 +779,23 @@
 	  else
 	    sieveServer = s;
 	}
-      else
-	sieveServer = @"localhost";
-      
-      url = [NSURL URLWithString: [NSString stringWithFormat: @"%@:%d", sieveServer, sievePort]];
-    }
-  else
-    {
-      url = [NSURL URLWithString: sieveServer];
     }
 
+  um = [SOGoUserManager sharedUserManager];
+  contactInfos = [um contactInfosForUserWithUIDorEmail: theLogin ];
+  ldapImapServer = [contactInfos objectForKey: @"c_imaphostname"];
+  if (ldapImapServer)
+    sieveServer = ldapImapServer;
+  if (!sieveServer)
+    sieveServer = @"localhost";
+  if ([url port])
+    sievePort = [[url port] intValue];
+  if ([url query])
+    sieveQuery = [NSString stringWithFormat: @"/?%@", [url query]];
+      
+  url = [NSURL URLWithString: [NSString stringWithFormat: @"%@://%@:%d%@",
+                               sieveScheme, sieveServer, sievePort, sieveQuery]];
+
   client = [[NGSieveClient alloc] initWithURL: url];
   
   if (!client) {
