* Implemented the 'getsubaddress' callback, but then realized
authorArt Cancro <ajc@citadel.org>
Sat, 14 Oct 2006 22:11:48 +0000 (22:11 +0000)
committerArt Cancro <ajc@citadel.org>
Sat, 14 Oct 2006 22:11:48 +0000 (22:11 +0000)
that it is actually more proper to return SIEVE2_ERROR_UNSUPPORTED because
Citadel doesn't have subaddresses.

citadel/internet_addressing.c
citadel/serv_sieve.c
citadel/serv_sieve.h

index a8487d38a0042b1a3457ff14aff504fc232ac332..a456e3266d418ec1efb2484d481e10cbce0f53df 100644 (file)
@@ -164,6 +164,8 @@ void process_rfc822_addr(const char *rfc822, char *user, char *node, char *name)
        strcpy(node, config.c_fqdn);
        strcpy(name, "");
 
+       if (rfc822 == NULL) return;
+
        /* extract full name - first, it's From minus <userid> */
        strcpy(name, rfc822);
        stripout(name, '<', '>');
index bf096a6c78187e46be42ccdd0e462a8f1988fa16..0faaf3980955b97f149d73af7f9759e0b52f2495 100644 (file)
@@ -42,6 +42,7 @@
 #include "policy.h"
 #include "database.h"
 #include "msgbase.h"
+#include "internet_addressing.h"
 #include "tools.h"
 
 #ifdef HAVE_LIBSIEVE
@@ -245,11 +246,25 @@ int ctdl_vacation(sieve2_context_t *s, void *my)
 
 /*
  * Callback function to parse addresses per local system convention
- * FIXME implement this
  */
 int ctdl_getsubaddress(sieve2_context_t *s, void *my)
 {
+       struct ctdl_sieve *cs = (struct ctdl_sieve *)my;
+
+       /*
+        * Citadel doesn't support subaddresses, so just give up.
+        */
        return SIEVE2_ERROR_UNSUPPORTED;
+
+       /* libSieve does not take ownership of the memory used here.  But, since we
+        * are just pointing to locations inside a struct which we are going to free
+        * later, we're ok.
+        */
+       sieve2_setvalue_string(s, "user", cs->recp_user);
+       sieve2_setvalue_string(s, "detail", "");        /* we don't support user+detail@domain yet */
+       sieve2_setvalue_string(s, "localpart", cs->recp_user);
+       sieve2_setvalue_string(s, "domain", cs->recp_node);
+       return SIEVE2_OK;
 }
 
 
@@ -361,13 +376,17 @@ void sieve_do_msg(long msgnum, void *userdata) {
        sieve2_context_t *sieve2_context = u->sieve2_context;
        struct ctdl_sieve my;
        int res;
+       struct CtdlMessage *msg;
 
        lprintf(CTDL_DEBUG, "Performing sieve processing on msg <%ld>\n", msgnum);
 
+       msg = CtdlFetchMessage(msgnum, 0);
+       if (msg == NULL) return;
+
        CC->redirect_buffer = malloc(SIZ);
        CC->redirect_len = 0;
        CC->redirect_alloc = SIZ;
-       CtdlOutputMsg(msgnum, MT_RFC822, HEADERS_ONLY, 0, 1, NULL);
+       CtdlOutputPreLoadedMsg(msg, MT_RFC822, HEADERS_ONLY, 0, 1);
        my.rfc822headers = CC->redirect_buffer;
        CC->redirect_buffer = NULL;
        CC->redirect_len = 0;
@@ -379,6 +398,11 @@ void sieve_do_msg(long msgnum, void *userdata) {
        my.msgnum = msgnum;     /* Keep track of the message number in our local store */
        my.u = u;               /* Hand off a pointer to the rest of this info */
 
+       /* Keep track of the recipient so we can do handling based on it later */
+       process_rfc822_addr(msg->cm_fields['R'], my.recp_user, my.recp_node, my.recp_name);
+
+       free(msg);
+
        sieve2_setvalue_string(sieve2_context, "allheaders", my.rfc822headers);
        
        lprintf(CTDL_DEBUG, "Calling sieve2_execute()\n");
index b58f2c72b4dd25006737b776312589de48583def..a8c6f52afbd3fe6a671592303e617a7de536767b 100644 (file)
@@ -30,6 +30,9 @@ struct ctdl_sieve {
        long usernum;                   /* Owner of the mailbox we're processing */
        long msgnum;                    /* Message base ID of the message being processed */
        struct sdm_userdata *u;         /* Info related to the current session */
+       char recp_user[256];
+       char recp_node[256];
+       char recp_name[256];
 };