Citadel now talks to Funambol, Funambol contacts phone, phone downloads email, everyones happy :) Attached patches implement the code required to tell Funambol we've got mail, add the config options necessary, and add a new pane to the Webcit site config dialog.
Index: serv_extensions.c
===================================================================
--- serv_extensions.c   (revision 4872)
+++ serv_extensions.c   (working copy)
@@ -234,7 +234,7 @@
        lprintf(CTDL_INFO, "%s\n", serv_postfix_tcpdict());
        lprintf(CTDL_INFO, "%s\n", serv_sieve_init());
        lprintf(CTDL_INFO, "%s\n", serv_managesieve_init());
-
+       lprintf(CTDL_INFO, "%s\n", serv_funambol_init());
        for (filter = 1; filter != 0; filter = filter << 1)
                if ((filter & DetailErrorFlags) != 0)
                        LogPrintMessages(filter);
Index: config.h
===================================================================
--- config.h    (revision 4872)
+++ config.h    (working copy)
@@ -76,6 +76,10 @@
        int c_pftcpdict_port;           /* postfix tcptable support, see 
http://www.postfix.org/tcp_table.5.html */
        int c_managesieve_port;         /* managesieve port. */
        int c_auth_mode;                /* 0 = built-in Citadel auth; 1 = 
underlying host system auth */
+       char c_funambol_host[256];      /* Funambol host. Blank to disable */
+       int c_funambol_port;            /* Funambol port */
+       char c_funambol_source[256];    /* Funambol sync source */
+       char c_funambol_auth[256];      /* Funambol auth details */
 };
 
 
Index: Makefile.in
===================================================================
--- Makefile.in (revision 4872)
+++ Makefile.in (working copy)
@@ -53,7 +53,8 @@
        serv_managesieve.o \
        ical_dezonify.o \
        serv_ldap.o \
-       serv_autocompletion.o 
+       serv_autocompletion.o \
+       serv_funambol.o
 
 UTIL_TARGETS=aidepost msgform \
        citmail userlist sendcommand \
@@ -102,7 +103,7 @@
        serv_newuser.c serv_pas2.c serv_pop3.c serv_rwho.c serv_smtp.c \
        serv_spam.c serv_test.c serv_mrtg.c serv_spam.c serv_upgrade.c \
        serv_vandelay.c serv_vcard.c serv_managesieve.c server_main.c \
-       serv_sieve.c setup.c snprintf.c imap_acl.c \
+       serv_sieve.c serv_funambol.c setup.c snprintf.c imap_acl.c \
        stress.c support.c sysdep.c tools.c user_ops.c userlist.c \
        whobbs.c vcard.c serv_notes.c serv_fulltext.c ft_wordbreaker.c \
        crc16.c journaling.c citadel_dirs.c
Index: serv_funambol.c
===================================================================
--- serv_funambol.c     (revision 0)
+++ serv_funambol.c     (revision 0)
@@ -0,0 +1,183 @@
+/*
+ * This module implements a notifier for Funambol push email.
+ */
+
+#define FUNAMBOL_WS       "/funambol/services/admin"
+#include "sysdep.h"
+#include <stdlib.h>
+#include <unistd.h>
+#include <stdio.h>
+#include <fcntl.h>
+#include <signal.h>
+#include <pwd.h>
+#include <errno.h>
+#include <sys/types.h>
+
+#if TIME_WITH_SYS_TIME
+# include <sys/time.h>
+# include <time.h>
+#else
+# if HAVE_SYS_TIME_H
+#  include <sys/time.h>
+# else
+#  include <time.h>
+# endif
+#endif
+
+#include <sys/wait.h>
+#include <string.h>
+#include <limits.h>
+#include <sys/socket.h>
+#include "citadel.h"
+#include "server.h"
+#include "sysdep_decls.h"
+#include "citserver.h"
+#include "support.h"
+#include "config.h"
+#include "control.h"
+#include "serv_extensions.h"
+#include "room_ops.h"
+#include "user_ops.h"
+#include "policy.h"
+#include "database.h"
+#include "msgbase.h"
+#include "tools.h"
+#include "internet_addressing.h"
+#include "domain.h"
+#include "clientsocket.h"
+
+
+
+/*
+ * Connect to the SpamAssassin server and scan a message.
+ */
+int notify_funambol(struct CtdlMessage *msg) {
+       int sock = (-1);
+       char fnblhosts[SIZ];
+       int num_fnblhosts;
+       char buf[SIZ];
+       int is_spam = 0;
+       int fnbl;
+       char *msgtext;
+       size_t msglen;
+       char host[SIZ];
+       char SOAPHeader[SIZ];
+       char SOAPData[SIZ];
+       char port[SIZ];
+       /* W means 'Wireless'... */
+       if ( msg->cm_fields['W'] == NULL) {
+               return(0);
+       }
+       /* Are we allowed to push? */
+       if ( strlen(config.c_funambol_host) == 0) {
+               return (0);
+       } else {
+               lprintf(CTDL_INFO, "Push enabled\n");
+       }
+       sprintf(port, "%d", config.c_funambol_port);
+                lprintf(CTDL_INFO, "Connecting to Funambol at <%s>\n", 
config.c_funambol_host);
+                sock = sock_connect(config.c_funambol_host, port, "tcp");
+                if (sock >= 0) lprintf(CTDL_DEBUG, "Connected!\n");
+
+       if (sock < 0) {
+               /* If the service isn't running, just pass the mail
+                * through.  Potentially throwing away mails isn't good.
+                */
+               return(0);
+       }
+       
+       /* Build a SOAP message, delicately, by hand */
+       strcat(SOAPData, "<?xml version=\"1.0\" 
encoding=\"UTF-8\"?><soapenv:Envelope 
xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"; 
xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"; 
xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\";>");
+       strcat(SOAPData, "<soapenv:Body><sendNotificationMessages 
soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\";>");
+       strcat(SOAPData, "<arg0 xsi:type=\"soapenc:string\" 
xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\";>");
+       strcat(SOAPData, msg->cm_fields['W']);
+       strcat(SOAPData, "</arg0>");
+       strcat(SOAPData, "<arg1 xsi:type=\"soapenc:string\" 
xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\";>&lt;?xml 
version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;\r\n");
+       strcat(SOAPData, "&lt;java version=&quot;1.5.0_10&quot; 
class=&quot;java.beans.XMLDecoder&quot;&gt; \r\n");
+       strcat(SOAPData, " &lt;array 
class=&quot;com.funambol.framework.core.Alert&quot; 
length=&quot;1&quot;&gt;\r\n");
+       strcat(SOAPData, "  &lt;void index=&quot;0&quot;&gt;\r\n");
+       strcat(SOAPData, "   &lt;object 
class=&quot;com.funambol.framework.core.Alert&quot;&gt;\r\n");
+       strcat(SOAPData, "    &lt;void property=&quot;cmdID&quot;>\r\n");
+       strcat(SOAPData, "     &lt;object 
class=&quot;com.funambol.framework.core.CmdID&quot;/&gt;\r\n");
+       strcat(SOAPData, "    &lt;/void&gt;");
+       strcat(SOAPData, "    &lt;void property=&quot;data&quot;&gt;\r\n");
+       strcat(SOAPData, "     &lt;int&gt;210&lt;/int&gt;\r\n");
+       strcat(SOAPData, "    &lt;/void&gt;\r\n");
+       strcat(SOAPData, "    &lt;void property=&quot;items&quot;&gt;\r\n");
+        strcat(SOAPData, "     &lt;void method=&quot;add&quot;&gt;\r\n"); 
+       strcat(SOAPData, "      &lt;object 
class=&quot;com.funambol.framework.core.Item&quot;&gt;\r\n"); 
+       strcat(SOAPData, "       &lt;void property=&quot;meta&quot;&gt;\r\n"); 
+       strcat(SOAPData, "        &lt;object 
class=&quot;com.funambol.framework.core.Meta&quot;&gt;\r\n"); 
+       strcat(SOAPData, "         &lt;void 
property=&quot;metInf&quot;&gt;\r\n");
+       strcat(SOAPData, "          &lt;void 
property=&quot;type&quot;&gt;\r\n");
+       strcat(SOAPData, "           
&lt;string&gt;application/vnd.omads-email+xml&lt;/string&gt;\r\n");
+       strcat(SOAPData, "          &lt;/void&gt;\r\n"); 
+       strcat(SOAPData, "         &lt;/void&gt;\r\n"); 
+       strcat(SOAPData, "        &lt;/object&gt;\r\n"); 
+       strcat(SOAPData, "       &lt;/void&gt;\r\n"); 
+       strcat(SOAPData, "       &lt;void 
property=&quot;target&quot;&gt;\r\n"); 
+       strcat(SOAPData, "        &lt;object 
class=&quot;com.funambol.framework.core.Target&quot;&gt;\r\n");
+       strcat(SOAPData, "         &lt;void 
property=&quot;locURI&quot;&gt;\r\n");
+       strcat(SOAPData, "          &lt;string&gt;");
+       strcat(SOAPData, config.c_funambol_source);
+       strcat(SOAPData, "&lt;/string&gt;\r\n");
+       strcat(SOAPData, "         &lt;/void&gt;\r\n");
+       strcat(SOAPData, "        &lt;/object&gt;\r\n");
+       strcat(SOAPData, "       &lt;/void&gt;\r\n");
+       strcat(SOAPData, "      &lt;/object&gt;\r\n");
+       strcat(SOAPData, "     &lt;/void&gt;\r\n");
+       strcat(SOAPData, "    &lt;/void&gt;\r\n");
+       strcat(SOAPData, "   &lt;/object&gt;\r\n");
+       strcat(SOAPData, "  &lt;/void&gt;\r\n");
+       strcat(SOAPData, " &lt;/array&gt;\r\n");
+       strcat(SOAPData, "&lt;/java&gt;");
+       strcat(SOAPData,"</arg1><arg2 
href=\"#id0\"/></sendNotificationMessages><multiRef id=\"id0\" 
soapenc:root=\"0\"\r\n");
+       
strcat(SOAPData,"soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\";
 xsi:type=\"soapenc:int\" 
xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\";>1</multiRef></soapenv:Body></soapenv:Envelope>");
+       
+       /* Command */
+       lprintf(CTDL_DEBUG, "Transmitting command\n");
+       sprintf(buf, "POST %s HTTP/1.0\r\nContent-type: text/xml; 
charset=utf-8\r\n",
+               FUNAMBOL_WS);
+       strcat(SOAPHeader,buf);
+       strcat(SOAPHeader,"Accept: application/soap+xml, application/dime, 
multipart/related, text/*\r\n");
+       sprintf(buf, "User-Agent: %s/%d\r\nHost: %s:%d\r\nCache-control: 
no-cache\r\n",
+               "Citadel",
+               REV_LEVEL,
+               config.c_funambol_host,
+               config.c_funambol_port
+               );
+               strcat(SOAPHeader,buf);
+       strcat(SOAPHeader,"Pragma: no-cache\r\nSOAPAction: \"\"\r\n");
+       sprintf(buf, "Content-Length: %d\r\n",
+               strlen(SOAPData));
+       strcat(SOAPHeader, buf);
+       sprintf(buf, "Authorization: Basic %s\r\n\r\n",
+               config.c_funambol_auth);
+       strcat(SOAPHeader, buf);
+       
+       sock_write(sock, SOAPHeader, strlen(SOAPHeader));
+       sock_write(sock, SOAPData, strlen(SOAPData));
+       sock_shutdown(sock, SHUT_WR);
+       
+       /* Response */
+       lprintf(CTDL_DEBUG, "Awaiting response\n");
+        if (sock_gets(sock, buf) < 0) {
+                goto bail;
+        }
+        lprintf(CTDL_DEBUG, "<%s\n", buf);
+       if (strncasecmp(buf, "HTTP/1.1 200 OK", strlen("HTTP/1.1 200 OK"))) {
+               goto bail;
+       }
+       lprintf(CTDL_DEBUG, "Funambol notified\n");
+
+bail:  close(sock);
+       return(is_spam);
+}
+
+
+
+char *serv_funambol_init(void)
+{
+       CtdlRegisterMessageHook(notify_funambol, EVT_AFTERSAVE);
+        return "$Id: serv_funambol.c $";
+}
Index: control.c
===================================================================
--- control.c   (revision 4872)
+++ control.c   (working copy)
@@ -242,6 +242,11 @@
                cprintf("%s\n", config.c_default_cal_zone);
                cprintf("%d\n", config.c_pftcpdict_port);
                cprintf("%d\n", config.c_managesieve_port);
+               cprintf("%d\n", config.c_auth_mode);
+               cprintf("%s\n", config.c_funambol_host);
+               cprintf("%d\n", config.c_funambol_port);
+               cprintf("%s\n", config.c_funambol_source);
+               cprintf("%s\n", config.c_funambol_auth);
                cprintf("000\n");
        }
 
@@ -447,6 +452,25 @@
                        case 51:
                                config.c_managesieve_port = atoi(buf);
                                break;
+                       case 52:
+                               config.c_auth_mode = atoi(buf);
+                       case 53:
+                               safestrncpy(config.c_funambol_host, buf,
+                                       sizeof config.c_funambol_host);
+                               break;
+                       case 54:
+                               config.c_funambol_port = atoi(buf);
+                               break;
+                       case 55:
+                               safestrncpy(config.c_funambol_source,
+                                       buf, 
+                                       sizeof config.c_funambol_source);
+                               break;
+                       case 56:
+                               safestrncpy(config.c_funambol_auth,
+                                       buf,
+                                       sizeof config.c_funambol_auth);
+                               break;
                        }
                        ++a;
                }
Index: msgbase.c
===================================================================
--- msgbase.c   (revision 4872)
+++ msgbase.c   (working copy)
@@ -2567,6 +2567,8 @@
                lprintf(CTDL_DEBUG, "Delivering private local mail to <%s>\n",
                        recipient);
                if (getuser(&userbuf, recipient) == 0) {
+                       // Add a flag so the Funambol module knows its mail
+                       msg->cm_fields['W'] = strdup(recipient);
                        MailboxName(actual_rm, sizeof actual_rm,
                                        &userbuf, MAILROOM);
                        CtdlSaveMsgPointerInRoom(actual_rm, newmsgid, 0, msg);
Index: siteconfig.c
===================================================================
--- siteconfig.c        (revision 4806)
+++ siteconfig.c        (working copy)
@@ -25,7 +25,7 @@
        char directory[SIZ];
        char purger[SIZ];
        char idxjnl[SIZ];
-
+       char funambol[SIZ];
        /** expire policy settings */
        int sitepolicy = 0;
        int sitevalue = 0;
@@ -65,7 +65,8 @@
                _("Tuning"),
                _("Directory"),
                _("Auto-purger"),
-               _("Indexing/Journaling")
+               _("Indexing/Journaling"),
+               _("Funambol Intergraton")
        };
 
        sprintf(general, "<center><h1>%s</h1><table border=\"0\">",
@@ -105,8 +106,10 @@
                        _("Indexing and Journaling"),
                        _("Warning: these facilities are resource intensive.")
        );
+       sprintf(funambol, "<center><h1>%s</h1><table border=\"0\">",
+               _("Funambol Push Email Intergration")
+               );
 
-
        wprintf("<form method=\"post\" action=\"siteconfig\">\n");
 
        i = 0;
@@ -524,7 +527,43 @@
                        sprintf(&network[strlen(network)], "<input 
type=\"text\" NAME=\"c_mgesve_port\" MAXLENGTH=\"5\" VALUE=\"%s\">", buf);
                        sprintf(&network[strlen(network)], "</TD></TR>\n");
                        break;
+               case 52:
+                       sprintf(&general[strlen(general)], "<TR><TD>");
+                       sprintf(&general[strlen(general)], _("Use system 
authentication"));
+                       sprintf(&general[strlen(general)], "</TD><TD><input 
type=\"checkbox\" NAME=\"c_auth_mode\" VALUE=\"yes\" %s>",
+                               ((atoi(buf) != 0) ? "CHECKED" : ""));
+                       sprintf(&general[strlen(general)], "</TD></TR>\n");
+                       break;
+               case 53:
+                       sprintf(&funambol[strlen(funambol)], "<TR><TD>");
+                       sprintf(&funambol[strlen(funambol)], _("Funambol server 
host (blank to disable)"));
+                       sprintf(&funambol[strlen(funambol)], "</TD><TD>");
+                       sprintf(&funambol[strlen(funambol)], "<input 
type=\"text\" NAME=\"c_funambol_host\" MAXLENGTH=\"255\" VALUE=\"%s\">", buf);
+                       sprintf(&funambol[strlen(funambol)], "</TD></TR>\n");
+                       break;
+               case 54:
+                       sprintf(&funambol[strlen(funambol)], "<TR><TD>");
+                       sprintf(&funambol[strlen(funambol)], _("Funambol server 
port "));
+                       sprintf(&funambol[strlen(funambol)], "</TD><TD>");
+                       sprintf(&funambol[strlen(funambol)], "<input 
type=\"text\" NAME=\"c_funambol_port\" MAXLENGTH=\"5\" VALUE=\"%s\">", buf);
+                       sprintf(&funambol[strlen(funambol)], "</TD></TR>\n");
+                       break;
+               case 55:
+                       sprintf(&funambol[strlen(funambol)], "<TR><TD>");
+                       sprintf(&funambol[strlen(funambol)], _("Funambol sync 
source"));
+                       sprintf(&funambol[strlen(funambol)], "</TD><TD>");
+                       sprintf(&funambol[strlen(funambol)], "<input 
type=\"text\" NAME=\"c_funambol_source\" MAXLENGTH=\"255\" VALUE=\"%s\">", buf);
+                       sprintf(&funambol[strlen(funambol)], "</TD></TR>\n");
+                       break;
+               case 56:
+                       sprintf(&funambol[strlen(funambol)], "<TR><TD>");
+                       sprintf(&funambol[strlen(funambol)], _("Funambol auth 
details (user:pass in Base64)"));
+                       sprintf(&funambol[strlen(funambol)], "</TD><TD>");
+                       sprintf(&funambol[strlen(funambol)], "<input 
type=\"text\" NAME=\"c_funambol_auth\" MAXLENGTH=\"255\" VALUE=\"%s\">", buf);
+                       sprintf(&funambol[strlen(funambol)], "</TD></TR>\n");
+                       break;
                }
+       
        }
 
        serv_puts("GPEX site");
@@ -598,8 +637,9 @@
        sprintf(&directory[strlen(directory)], "</table>");
        sprintf(&purger[strlen(purger)], "</table>");
        sprintf(&idxjnl[strlen(idxjnl)], "</table>");
+       sprintf(&funambol[strlen(funambol)], "</table");
 
-       tabbed_dialog(7, tabnames);
+       tabbed_dialog(8, tabnames);
 
        begin_tab(0, 7);        client_write(general, strlen(general));         
 end_tab(0, 7);
        begin_tab(1, 7);        client_write(access, strlen(access));           
 end_tab(1, 7);
@@ -608,7 +648,7 @@
        begin_tab(4, 7);        client_write(directory, strlen(directory));     
 end_tab(4, 7);
        begin_tab(5, 7);        client_write(purger, strlen(purger));           
 end_tab(5, 7);
        begin_tab(6, 7);        client_write(idxjnl, strlen(idxjnl));           
 end_tab(6, 7);
-
+       begin_tab(7, 8);        client_write(funambol, strlen(funambol));       
 end_tab(7, 8);
        wprintf("<div align=\"center\"><br>");
        wprintf("<input type=\"submit\" NAME=\"ok_button\" VALUE=\"%s\">", 
_("Save changes"));
        wprintf("&nbsp;");
@@ -688,6 +728,11 @@
        serv_printf("%s", bstr("c_default_cal_zone"));
        serv_printf("%s", bstr("c_pftcpdict_port"));
        serv_printf("%s", bstr("c_mgesve_port"));
+       serv_printf("%s", ((!strcasecmp(bstr("c_auth_mode"), "yes") ? "1" : 
"0")));
+       serv_printf("%s", bstr("c_funambol_host"));
+       serv_printf("%s", bstr("c_funambol_port"));
+       serv_printf("%s", bstr("c_funambol_source"));
+       serv_printf("%s", bstr("c_funambol_auth"));
        serv_printf("000");
 
        serv_printf("SPEX site|%d|%d", atoi(bstr("sitepolicy")), 
atoi(bstr("sitevalue")));

Reply via email to