indent -kr -i132 citserver.c
authorArt Cancro <ajc@citadel.org>
Fri, 27 Jul 2018 15:43:59 +0000 (11:43 -0400)
committerArt Cancro <ajc@citadel.org>
Fri, 27 Jul 2018 15:43:59 +0000 (11:43 -0400)
citadel/citserver.c
citadel/modules/smtp/serv_smtpclient.c

index 06b31b94429e9ba96c41b49b71120570dcb3d2c8..a9750dd6473e9e0b4932e2240da4dcaf3fd18a83 100644 (file)
@@ -38,7 +38,8 @@ int openid_level_supported = 0;
 /*
  * Various things that need to be initialized at startup
  */
-void master_startup(void) {
+void master_startup(void)
+{
        struct timeval tv;
        unsigned int seed;
        FILE *urandom;
@@ -46,7 +47,7 @@ void master_startup(void) {
        int rv;
        struct passwd *pw;
        gid_t gid;
-       
+
        syslog(LOG_DEBUG, "master_startup() started");
        time(&server_startup_time);
 
@@ -74,22 +75,22 @@ void master_startup(void) {
        check_ref_counts();
 
        syslog(LOG_INFO, "Creating base rooms (if necessary)");
-       CtdlCreateRoom(CtdlGetConfigStr("c_baseroom"),  0, "", 0, 1, 0, VIEW_BBS);
-       CtdlCreateRoom(AIDEROOM,                        3, "", 0, 1, 0, VIEW_BBS);
-       CtdlCreateRoom(SYSCONFIGROOM,                   3, "", 0, 1, 0, VIEW_BBS);
-       CtdlCreateRoom(CtdlGetConfigStr("c_twitroom"),  0, "", 0, 1, 0, VIEW_BBS);
+       CtdlCreateRoom(CtdlGetConfigStr("c_baseroom"), 0, "", 0, 1, 0, VIEW_BBS);
+       CtdlCreateRoom(AIDEROOM, 3, "", 0, 1, 0, VIEW_BBS);
+       CtdlCreateRoom(SYSCONFIGROOM, 3, "", 0, 1, 0, VIEW_BBS);
+       CtdlCreateRoom(CtdlGetConfigStr("c_twitroom"), 0, "", 0, 1, 0, VIEW_BBS);
 
        /* The "Local System Configuration" room doesn't need to be visible */
-        if (CtdlGetRoomLock(&qrbuf, SYSCONFIGROOM) == 0) {
-                qrbuf.QRflags2 |= QR2_SYSTEM;
-                CtdlPutRoomLock(&qrbuf);
-        }
+       if (CtdlGetRoomLock(&qrbuf, SYSCONFIGROOM) == 0) {
+               qrbuf.QRflags2 |= QR2_SYSTEM;
+               CtdlPutRoomLock(&qrbuf);
+       }
 
        /* Aide needs to be public postable, else we're not RFC conformant. */
-        if (CtdlGetRoomLock(&qrbuf, AIDEROOM) == 0) {
-                qrbuf.QRflags2 |= QR2_SMTP_PUBLIC;
-                CtdlPutRoomLock(&qrbuf);
-        }
+       if (CtdlGetRoomLock(&qrbuf, AIDEROOM) == 0) {
+               qrbuf.QRflags2 |= QR2_SMTP_PUBLIC;
+               CtdlPutRoomLock(&qrbuf);
+       }
 
        syslog(LOG_INFO, "Seeding the pseudo-random number generator...");
        urandom = fopen("/dev/urandom", "r");
@@ -99,8 +100,7 @@ void master_startup(void) {
                        syslog(LOG_ERR, "citserver: failed to read random seed: %m");
                }
                fclose(urandom);
-       }
-       else {
+       } else {
                gettimeofday(&tv, NULL);
                seed = tv.tv_usec;
        }
@@ -114,16 +114,19 @@ void master_startup(void) {
 /*
  * Cleanup routine to be called when the server is shutting down.  Returns the needed exit code.
  */
-int master_cleanup(int exitcode) {
+int master_cleanup(int exitcode)
+{
        struct CleanupFunctionHook *fcn;
        static int already_cleaning_up = 0;
 
-       if (already_cleaning_up) while(1) usleep(1000000);
+       if (already_cleaning_up)
+               while (1)
+                       usleep(1000000);
        already_cleaning_up = 1;
 
        /* Run any cleanup routines registered by loadable modules */
        for (fcn = CleanupHookTable; fcn != NULL; fcn = fcn->next) {
-               (*fcn->h_function_pointer)();
+               (*fcn->h_function_pointer) ();
        }
 
        /* Close the AdjRefCount queue file */
@@ -134,7 +137,7 @@ int master_cleanup(int exitcode) {
 
        /* Close the configuration system */
        shutdown_config_system();
-       
+
        /* Close databases */
        syslog(LOG_INFO, "Closing databases\n");
        close_databases();
@@ -142,23 +145,24 @@ int master_cleanup(int exitcode) {
        /* If the operator requested a halt but not an exit, halt here. */
        if (shutdown_and_halt) {
                syslog(LOG_ERR, "citserver: Halting server without exiting.");
-               fflush(stdout); fflush(stderr);
-               while(1) {
+               fflush(stdout);
+               fflush(stderr);
+               while (1) {
                        sleep(32767);
                }
        }
-       
+
        /* Now go away. */
        syslog(LOG_ERR, "citserver: Exiting with status %d", exitcode);
-       fflush(stdout); fflush(stderr);
-       
+       fflush(stdout);
+       fflush(stderr);
+
        if (restart_server != 0) {
                exitcode = 1;
-       }
-       else if ((running_as_daemon != 0) && ((exitcode == 0) )) {
+       } else if ((running_as_daemon != 0) && ((exitcode == 0))) {
                exitcode = CTDLEXIT_SHUTDOWN;
        }
-       return(exitcode);
+       return (exitcode);
 }
 
 
@@ -167,12 +171,12 @@ int master_cleanup(int exitcode) {
  * returns an asterisk if there are any instant messages waiting,
  * space otherwise.
  */
-char CtdlCheckExpress(void) {
+char CtdlCheckExpress(void)
+{
        if (CC->FirstExpressMessage == NULL) {
-               return(' ');
-       }
-       else {
-               return('*');
+               return (' ');
+       } else {
+               return ('*');
        }
 }
 
@@ -210,7 +214,7 @@ int CtdlIsPublicClient(void)
        if (stat(public_clients_file, &statbuf) != 0) {
                /* No public_clients file exists, so bail out */
                syslog(LOG_WARNING, "Warning: '%s' does not exist", public_clients_file);
-               return(0);
+               return (0);
        }
 
        if (statbuf.st_mtime > pc_timestamp) {
@@ -221,80 +225,78 @@ int CtdlIsPublicClient(void)
                public_clientsend = public_clientspos + SIZ;
                safestrncpy(public_clientspos, LOCALHOSTSTR, sizeof public_clients);
                public_clientspos += sizeof(LOCALHOSTSTR) - 1;
-               
+
                if (hostname_to_dotted_quad(addrbuf, CtdlGetConfigStr("c_fqdn")) == 0) {
                        *(public_clientspos++) = '|';
                        paddr = &addrbuf[0];
-                       while (!IsEmptyStr (paddr) && 
-                              (public_clientspos < public_clientsend))
+                       while (!IsEmptyStr(paddr) && (public_clientspos < public_clientsend))
                                *(public_clientspos++) = *(paddr++);
                }
 
                fp = fopen(public_clients_file, "r");
-               if (fp != NULL) 
-                       while ((fgets(buf, sizeof buf, fp)!=NULL) &&
-                              (public_clientspos < public_clientsend)){
+               if (fp != NULL)
+                       while ((fgets(buf, sizeof buf, fp) != NULL) && (public_clientspos < public_clientsend)) {
                                char *ptr;
                                ptr = buf;
                                while (!IsEmptyStr(ptr)) {
                                        if (*ptr == '#') {
                                                *ptr = 0;
                                                break;
-                                       }
-                               else ptr++;
+                                       } else
+                                               ptr++;
                                }
                                ptr--;
-                               while (ptr>buf && isspace(*ptr)) {
+                               while (ptr > buf && isspace(*ptr)) {
                                        *(ptr--) = 0;
                                }
                                if (hostname_to_dotted_quad(addrbuf, buf) == 0) {
                                        *(public_clientspos++) = '|';
                                        paddr = addrbuf;
-                                       while (!IsEmptyStr(paddr) && 
-                                              (public_clientspos < public_clientsend)){
+                                       while (!IsEmptyStr(paddr) && (public_clientspos < public_clientsend)) {
                                                *(public_clientspos++) = *(paddr++);
                                        }
                                }
                        }
-               if (fp != NULL) fclose(fp);
+               if (fp != NULL)
+                       fclose(fp);
                pc_timestamp = time(NULL);
                end_critical_section(S_PUBLIC_CLIENTS);
        }
 
        syslog(LOG_DEBUG, "Checking whether %s is a local or public client", CC->cs_addr);
-       for (i=0; i<num_parms(public_clients); ++i) {
+       for (i = 0; i < num_parms(public_clients); ++i) {
                extract_token(addrbuf, public_clients, i, '|', sizeof addrbuf);
                if (!strcasecmp(CC->cs_addr, addrbuf)) {
                        syslog(LOG_DEBUG, "... yes its local.");
-                       return(1);
+                       return (1);
                }
        }
 
        /* No hits.  This is not a public client. */
        syslog(LOG_DEBUG, "... no it isn't.");
-       return(0);
+       return (0);
 }
 
 
 
 
 
-void citproto_begin_session() {
-       if (CC->nologin==1) {
+void citproto_begin_session()
+{
+       if (CC->nologin == 1) {
                cprintf("%d %s: Too many users are already online (maximum is %d)\n",
-                       ERROR + MAX_SESSIONS_EXCEEDED,
-                       CtdlGetConfigStr("c_nodename"), CtdlGetConfigInt("c_maxsessions")
-               );
+                       ERROR + MAX_SESSIONS_EXCEEDED, CtdlGetConfigStr("c_nodename"), CtdlGetConfigInt("c_maxsessions")
+                   );
                CC->kill_me = KILLME_MAX_SESSIONS_EXCEEDED;
-       }
-       else {
+       } else {
                cprintf("%d %s Citadel server ready.\n", CIT_OK, CtdlGetConfigStr("c_nodename"));
                CC->can_receive_im = 1;
        }
 }
 
 
-void citproto_begin_admin_session() {
+void citproto_begin_admin_session()
+{
        CC->internal_pgm = 1;
        cprintf("%d %s Citadel server ADMIN CONNECTION ready.\n", CIT_OK, CtdlGetConfigStr("c_nodename"));
 }
@@ -303,7 +305,7 @@ void citproto_begin_admin_session() {
 /*
  * This loop performs all asynchronous functions.
  */
-void do_async_loop(void) {
+void do_async_loop(void)
+{
        PerformSessionHooks(EVT_ASYNC);
 }
-
index 84ac4e647ad2db9726b1c8a7fec8786d49d3675d..b8081fa2c396369514685f9f3c280fa80a9dc9e7 100644 (file)
 #include <sysconfig.h>
 
 #if TIME_WITH_SYS_TIME
-# include <sys/time.h>
-# include <time.h>
+#include <sys/time.h>
+#include <time.h>
 #else
-# if HAVE_SYS_TIME_H
-#  include <sys/time.h>
-# else
-#  include <time.h>
-# endif
+#if HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
 #endif
 
 #include <ctype.h>
@@ -68,7 +68,8 @@ int smtpq_alloc = 0;          // current allocation size for smtpq
 /*
  * Initialize the SMTP outbound queue
  */
-void smtp_init_spoolout(void) {
+void smtp_init_spoolout(void)
+{
        struct ctdlroom qrbuf;
 
        /*
@@ -93,7 +94,7 @@ void smtp_init_spoolout(void) {
  * not happen because the delivery instructions message does not
  * contain a recipient.
  */
-int smtp_aftersave(struct CtdlMessage *msg, recptypes *recps)
+int smtp_aftersave(struct CtdlMessage *msg, recptypes * recps)
 {
        if ((recps != NULL) && (recps->num_internet > 0)) {
                struct CtdlMessage *imsg = NULL;
@@ -105,15 +106,10 @@ int smtp_aftersave(struct CtdlMessage *msg, recptypes *recps)
                syslog(LOG_DEBUG, "smtpclient: generating delivery instructions");
 
                StrBufPrintf(SpoolMsg,
-                            "Content-type: "SPOOLMIME"\n"
+                            "Content-type: " SPOOLMIME "\n"
                             "\n"
                             "msgid|%s\n"
-                            "submitted|%ld\n"
-                            "bounceto|%s\n",
-                            msg->cm_fields[eVltMsgNum],
-                            (long)time(NULL),
-                            recps->bounce_to
-               );
+                            "submitted|%ld\n" "bounceto|%s\n", msg->cm_fields[eVltMsgNum], (long) time(NULL), recps->bounce_to);
 
                if (recps->envelope_from != NULL) {
                        StrBufAppendBufPlain(SpoolMsg, HKEY("envelope_from|"), 0);
@@ -127,7 +123,7 @@ int smtp_aftersave(struct CtdlMessage *msg, recptypes *recps)
                }
 
                nTokens = num_tokens(recps->recp_internet, '|');
-               for (i = 0; i < nTokens; i++) {
+               for (i = 0; i < nTokens; i++) {
                        long len;
                        len = extract_token(recipient, recps->recp_internet, i, '|', sizeof recipient);
                        if (len > 0) {
@@ -165,7 +161,7 @@ static size_t upload_source(void *ptr, size_t size, size_t nmemb, void *userp)
        sendbytes = (size * nmemb);
 
        if (s->bytes_sent >= s->bytes_total) {
-               return(0);                                      // no data remaining; we are done
+               return (0);     // no data remaining; we are done
        }
 
        if (sendbytes > (s->bytes_total - s->bytes_sent)) {
@@ -173,11 +169,11 @@ static size_t upload_source(void *ptr, size_t size, size_t nmemb, void *userp)
        }
 
        send_this = ChrPtr(s->TheMessage);
-       send_this += s->bytes_sent;                             // start where we last left off
+       send_this += s->bytes_sent;     // start where we last left off
 
        memcpy(ptr, send_this, sendbytes);
        s->bytes_sent += sendbytes;
-       return(sendbytes);                                      // return the number of bytes _actually_ copied
+       return (sendbytes);     // return the number of bytes _actually_ copied
 }
 
 
@@ -186,17 +182,20 @@ static size_t upload_source(void *ptr, size_t size, size_t nmemb, void *userp)
  * by the remote server.  This is an ugly way to extract it, by capturing debug data from
  * the library and filtering on the lines we want.
  */
-int ctdl_libcurl_smtp_debug_callback(CURL *handle, curl_infotype type, char *data, size_t size, void *userptr)
+int ctdl_libcurl_smtp_debug_callback(CURL * handle, curl_infotype type, char *data, size_t size, void *userptr)
 {
-       if (type != CURLINFO_HEADER_IN) return 0;
-       if (!userptr) return 0;
-       char *debugbuf = (char *)userptr;
+       if (type != CURLINFO_HEADER_IN)
+               return 0;
+       if (!userptr)
+               return 0;
+       char *debugbuf = (char *) userptr;
 
        int len = strlen(debugbuf);
-       if (len + size > SIZ) return 0;
+       if (len + size > SIZ)
+               return 0;
 
        memcpy(&debugbuf[len], data, size);
-       debugbuf[len+size] = 0;
+       debugbuf[len + size] = 0;
        return 0;
 }
 
@@ -224,23 +223,23 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from, char *res
 
        syslog(LOG_DEBUG, "smtpclient: smtp_attempt_delivery(%ld, %s)", msgid, recp);
 
-       process_rfc822_addr(recp, user, node, name);            // split recipient address into username, hostname, displayname
+       process_rfc822_addr(recp, user, node, name);    // split recipient address into username, hostname, displayname
        num_mx = getmx(mxes, node);
        if (num_mx < 1) {
-               return(421);
+               return (421);
        }
 
        CC->redirect_buffer = NewStrBufPlain(NULL, SIZ);
        CtdlOutputMsg(msgid, MT_RFC822, HEADERS_ALL, 0, 1, NULL, 0, NULL, &fromaddr, NULL);
        s.TheMessage = CC->redirect_buffer;
-       s.bytes_total =  StrLength(CC->redirect_buffer);
+       s.bytes_total = StrLength(CC->redirect_buffer);
        s.bytes_sent = 0;
        CC->redirect_buffer = NULL;
        response_code = 421;
 
-       for (i=0; ((i<num_mx)&&((response_code/100)==4)); ++i) {                                // keep trying MXes until one works or we run out
-               response_code = 421;                                                            // default 421 makes non-protocol errors transient
-               s.bytes_sent = 0;                                                               // rewind our buffer in case we try multiple MXes
+       for (i = 0; ((i < num_mx) && ((response_code / 100) == 4)); ++i) {      // keep trying MXes until one works or we run out
+               response_code = 421;    // default 421 makes non-protocol errors transient
+               s.bytes_sent = 0;       // rewind our buffer in case we try multiple MXes
 
                curl = curl_easy_init();
                if (curl) {
@@ -248,54 +247,54 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from, char *res
 
                        if (!IsEmptyStr(envelope_from)) {
                                curl_easy_setopt(curl, CURLOPT_MAIL_FROM, envelope_from);
-                       }
-                       else {
+                       } else {
                                curl_easy_setopt(curl, CURLOPT_MAIL_FROM, fromaddr);
                        }
-       
+
                        recipients = curl_slist_append(recipients, recp);
                        curl_easy_setopt(curl, CURLOPT_MAIL_RCPT, recipients);
                        curl_easy_setopt(curl, CURLOPT_READFUNCTION, upload_source);
                        curl_easy_setopt(curl, CURLOPT_READDATA, &s);
-                       curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);                                              // tell libcurl we are uploading
-                       curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);                                           // Time out after 20 seconds
+                       curl_easy_setopt(curl, CURLOPT_UPLOAD, 1);      // tell libcurl we are uploading
+                       curl_easy_setopt(curl, CURLOPT_TIMEOUT, 20L);   // Time out after 20 seconds
                        if (CtdlGetConfigInt("c_smtpclient_disable_starttls") == 0) {
-                               curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);                        // Attempt STARTTLS if offered
+                               curl_easy_setopt(curl, CURLOPT_USE_SSL, CURLUSESSL_TRY);        // Attempt STARTTLS if offered
                        }
                        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);
                        curl_easy_setopt(curl, CURLOPT_SSL_VERIFYHOST, 0L);
                        curl_easy_setopt(curl, CURLOPT_DEBUGFUNCTION, ctdl_libcurl_smtp_debug_callback);
-                       curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *)response);
+                       curl_easy_setopt(curl, CURLOPT_DEBUGDATA, (void *) response);
                        curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
 
                        // Construct an SMTP URL in the form of:
-                       //      smtp[s]://target_host/source_host
+                       //      smtp[s]://target_host/source_host
                        // This looks weird but libcurl uses that last part to set our name for EHLO or HELO.
                        // We check for "smtp://" and "smtps://" because the admin may have put those prefixes in a smart-host entry.
                        // If there is no prefix we add "smtp://"
                        extract_token(try_this_mx, mxes, i, '|', (sizeof try_this_mx - 7));
-                       snprintf(smtp_url, sizeof smtp_url,
-                               "%s%s/%s",
-                               (((!strncasecmp(try_this_mx, HKEY("smtp://"))) || (!strncasecmp(try_this_mx, HKEY("smtps://")))) ? "" : "smtp://"),
-                               try_this_mx,
-                               CtdlGetConfigStr("c_fqdn")
-                       );
+                       snprintf(smtp_url, sizeof smtp_url, "%s%s/%s", (((!strncasecmp(try_this_mx, HKEY("smtp://")))
+                                                                        ||
+                                                                        (!strncasecmp
+                                                                         (try_this_mx,
+                                                                          HKEY("smtps://")))) ? "" : "smtp://"),
+                                try_this_mx, CtdlGetConfigStr("c_fqdn")
+                           );
                        curl_easy_setopt(curl, CURLOPT_URL, smtp_url);
-                       syslog(LOG_DEBUG, "smtpclient: trying %s", smtp_url);                           // send the message
+                       syslog(LOG_DEBUG, "smtpclient: trying %s", smtp_url);   // send the message
                        res = curl_easy_perform(curl);
                        curl_easy_getinfo(curl, CURLINFO_RESPONSE_CODE, &response_code);
-                       syslog(LOG_DEBUG, "smtpclient: libcurl returned %d (%s) , SMTP response %ld",
-                               res, curl_easy_strerror(res), response_code
-                       );
+                       syslog(LOG_DEBUG,
+                              "smtpclient: libcurl returned %d (%s) , SMTP response %ld",
+                              res, curl_easy_strerror(res), response_code);
 
-                       if ((res != CURLE_OK) && (response_code == 0)) {                                // check for errors
+                       if ((res != CURLE_OK) && (response_code == 0)) {        // check for errors
                                response_code = 421;
                        }
 
                        curl_slist_free_all(recipients);
-                       recipients = NULL;                                                              // this gets reused; avoid double-free
+                       recipients = NULL;      // this gets reused; avoid double-free
                        curl_easy_cleanup(curl);
-                       curl = NULL;                                                                    // this gets reused; avoid double-free
+                       curl = NULL;    // this gets reused; avoid double-free
 
                        /* Trim the error message buffer down to just the actual message */
                        char response_code_str[4];
@@ -303,22 +302,25 @@ int smtp_attempt_delivery(long msgid, char *recp, char *envelope_from, char *res
                        char *respstart = strstr(response, response_code_str);
                        if (respstart == NULL) {
                                strcpy(response, smtpstatus(response_code));
-                       }
-                       else {
+                       } else {
                                strcpy(response, respstart);
                                char *p;
-                               for (p=response; *p!=0; ++p) {
-                                       if (*p == '\n') *p = ' ';
-                                       if (*p == '\r') *p = ' ';
-                                       if (!isprint(*p)) *p = ' ';
+                               for (p = response; *p != 0; ++p) {
+                                       if (*p == '\n')
+                                               *p = ' ';
+                                       if (*p == '\r')
+                                               *p = ' ';
+                                       if (!isprint(*p))
+                                               *p = ' ';
                                }
                        }
                }
        }
 
        FreeStrBuf(&s.TheMessage);
-       if (fromaddr) free(fromaddr);
-       return((int)response_code);
+       if (fromaddr)
+               free(fromaddr);
+       return ((int) response_code);
 }
 
 
@@ -350,13 +352,13 @@ void smtp_process_one_msg(long qmsgnum)
        // if the queue message has any CRLF's convert them to LF's
        char *crlf = NULL;
        while (crlf = strstr(instr, "\r\n"), crlf != NULL) {
-               strcpy(crlf, crlf+1);
+               strcpy(crlf, crlf + 1);
        }
 
        // Strip out the headers and we are now left with just the instructions.
        char *soi = strstr(instr, "\n\n");
        if (soi) {
-               strcpy(instr, soi+2);
+               strcpy(instr, soi + 2);
        }
 
        long msgid = 0;
@@ -366,26 +368,29 @@ void smtp_process_one_msg(long qmsgnum)
        char *envelope_from = NULL;
 
        char cfgline[SIZ];
-       for (i=0; i<num_tokens(instr, '\n'); ++i) {
+       for (i = 0; i < num_tokens(instr, '\n'); ++i) {
                extract_token(cfgline, instr, i, '\n', sizeof cfgline);
-               if (!strncasecmp(cfgline, HKEY("msgid|")))              msgid = atol(&cfgline[6]);
-               if (!strncasecmp(cfgline, HKEY("submitted|")))          submitted = atol(&cfgline[10]);
-               if (!strncasecmp(cfgline, HKEY("attempted|")))          attempted = atol(&cfgline[10]);
-               if (!strncasecmp(cfgline, HKEY("bounceto|")))           bounceto = strdup(&cfgline[9]);
-               if (!strncasecmp(cfgline, HKEY("envelope_from|")))      envelope_from = strdup(&cfgline[14]);
+               if (!strncasecmp(cfgline, HKEY("msgid|")))
+                       msgid = atol(&cfgline[6]);
+               if (!strncasecmp(cfgline, HKEY("submitted|")))
+                       submitted = atol(&cfgline[10]);
+               if (!strncasecmp(cfgline, HKEY("attempted|")))
+                       attempted = atol(&cfgline[10]);
+               if (!strncasecmp(cfgline, HKEY("bounceto|")))
+                       bounceto = strdup(&cfgline[9]);
+               if (!strncasecmp(cfgline, HKEY("envelope_from|")))
+                       envelope_from = strdup(&cfgline[14]);
        }
 
        int should_try_now = 0;
-       if (attempted < submitted) {                            // If no attempts have been made yet, try now
+       if (attempted < submitted) {    // If no attempts have been made yet, try now
                should_try_now = 1;
-       }
-       else if ((attempted - submitted) <= 14400) {
-               if ((time(NULL) - attempted) > 1800) {          // First four hours, retry every 30 minutes
+       } else if ((attempted - submitted) <= 14400) {
+               if ((time(NULL) - attempted) > 1800) {  // First four hours, retry every 30 minutes
                        should_try_now = 1;
                }
-       }
-       else {
-               if ((time(NULL) - attempted) > 14400) {         // After that, retry once every 4 hours
+       } else {
+               if ((time(NULL) - attempted) > 14400) { // After that, retry once every 4 hours
                        should_try_now = 1;
                }
        }
@@ -393,35 +398,38 @@ void smtp_process_one_msg(long qmsgnum)
        if (should_try_now) {
                syslog(LOG_DEBUG, "smtpclient: %ld attempting delivery now", qmsgnum);
                StrBuf *NewInstr = NewStrBuf();
-               StrBufAppendPrintf(NewInstr, "Content-type: "SPOOLMIME"\n\n");
+               StrBufAppendPrintf(NewInstr, "Content-type: " SPOOLMIME "\n\n");
                StrBufAppendPrintf(NewInstr, "msgid|%ld\n", msgid);
                StrBufAppendPrintf(NewInstr, "submitted|%ld\n", submitted);
-               if (bounceto) StrBufAppendPrintf(NewInstr, "bounceto|%s\n", bounceto);
-               if (envelope_from) StrBufAppendPrintf(NewInstr, "envelope_from|%s\n", envelope_from);
+               if (bounceto)
+                       StrBufAppendPrintf(NewInstr, "bounceto|%s\n", bounceto);
+               if (envelope_from)
+                       StrBufAppendPrintf(NewInstr, "envelope_from|%s\n", envelope_from);
 
-               for (i=0; i<num_tokens(instr, '\n'); ++i) {
+               for (i = 0; i < num_tokens(instr, '\n'); ++i) {
                        extract_token(cfgline, instr, i, '\n', sizeof cfgline);
                        if (!strncasecmp(cfgline, HKEY("remote|"))) {
                                char recp[SIZ];
                                int previous_result = extract_int(cfgline, 2);
-                               if ((previous_result == 0) || (previous_result == 4)) {
+                               if ((previous_result == 0)
+                                   || (previous_result == 4)) {
                                        int new_result = 421;
                                        extract_token(recp, cfgline, 1, '|', sizeof recp);
                                        new_result = smtp_attempt_delivery(msgid, recp, envelope_from, server_response);
-                                       syslog(LOG_DEBUG, "smtpclient: recp: <%s> , result: %d (%s)", recp, new_result, server_response);
+                                       syslog(LOG_DEBUG,
+                                              "smtpclient: recp: <%s> , result: %d (%s)", recp, new_result, server_response);
                                        if ((new_result / 100) == 2) {
                                                ++num_success;
-                                       }
-                                       else {
+                                       } else {
                                                if ((new_result / 100) == 5) {
                                                        ++num_fail;
-                                               }
-                                               else {
+                                               } else {
                                                        ++num_delayed;
                                                }
-                                               StrBufAppendPrintf(NewInstr, "remote|%s|%ld|%ld (%s)\n",
-                                                       recp, (new_result / 100) , new_result, server_response
-                                               );
+                                               StrBufAppendPrintf
+                                                   (NewInstr,
+                                                    "remote|%s|%ld|%ld (%s)\n",
+                                                    recp, (new_result / 100), new_result, server_response);
                                        }
                                }
                        }
@@ -432,7 +440,9 @@ void smtp_process_one_msg(long qmsgnum)
                // All deliveries have now been attempted.  Now determine the disposition of this queue entry.
 
                time_t age = time(NULL) - submitted;
-               syslog(LOG_DEBUG, "smtpclient: submission age: %ldd%ldh%ldm%lds", (age/86400) , ((age%86400)/3600) , ((age%3600)/60) , (age%60));
+               syslog(LOG_DEBUG,
+                      "smtpclient: submission age: %ldd%ldh%ldm%lds",
+                      (age / 86400), ((age % 86400) / 3600), ((age % 3600) / 60), (age % 60));
                syslog(LOG_DEBUG, "smtpclient: num_success=%d , num_fail=%d , num_delayed=%d", num_success, num_fail, num_delayed);
 
                // If there are permanent fails on this attempt, deliver a bounce to the user.
@@ -440,23 +450,21 @@ void smtp_process_one_msg(long qmsgnum)
                if (num_fail > 0) {
                        smtp_do_bounce(ChrPtr(NewInstr), SDB_BOUNCE_FATALS);
                }
-
                // If all deliveries have either succeeded or failed, we are finished with this queue entry.
                //
                if (num_delayed == 0) {
                        delete_this_queue = 1;
                }
-
                // If it's been more than five days, give up and tell the sender that delivery failed
                //
                else if ((time(NULL) - submitted) > SMTP_DELIVER_FAIL) {
                        smtp_do_bounce(ChrPtr(NewInstr), SDB_BOUNCE_ALL);
                        delete_this_queue = 1;
                }
-
                // If it's been more than four hours but less than five days, warn the sender that delivery is delayed
                //
-               else if ( ((attempted - submitted) < SMTP_DELIVER_WARN) && ((time(NULL) - submitted) >= SMTP_DELIVER_WARN) ) {
+               else if (((attempted - submitted) < SMTP_DELIVER_WARN)
+                        && ((time(NULL) - submitted) >= SMTP_DELIVER_WARN)) {
                        smtp_do_bounce(ChrPtr(NewInstr), SDB_WARN);
                }
 
@@ -465,23 +473,23 @@ void smtp_process_one_msg(long qmsgnum)
                        deletes[0] = qmsgnum;
                        deletes[1] = msgid;
                        CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, deletes, 2, "");
-                       FreeStrBuf(&NewInstr);                                          // We have to free NewInstr here, no longer needed
-               }
-               else {
+                       FreeStrBuf(&NewInstr);  // We have to free NewInstr here, no longer needed
+               } else {
                        // replace the old queue entry with the new one
                        syslog(LOG_DEBUG, "smtpclient: %ld rewriting", qmsgnum);
-                       msg = convert_internet_message_buf(&NewInstr);                  // This function will free NewInstr for us
+                       msg = convert_internet_message_buf(&NewInstr);  // This function will free NewInstr for us
                        CtdlSubmitMsg(msg, NULL, SMTP_SPOOLOUT_ROOM, 0);
                        CM_Free(msg);
                        CtdlDeleteMessages(SMTP_SPOOLOUT_ROOM, &qmsgnum, 1, "");
                }
-       }
-       else {
+       } else {
                syslog(LOG_DEBUG, "smtpclient: %ld retry time not reached", qmsgnum);
        }
 
-       if (bounceto != NULL)           free(bounceto);
-       if (envelope_from != NULL)      free(envelope_from);
+       if (bounceto != NULL)
+               free(bounceto);
+       if (envelope_from != NULL)
+               free(envelope_from);
        free(instr);
 }
 
@@ -489,7 +497,8 @@ void smtp_process_one_msg(long qmsgnum)
 /*
  * Callback for smtp_do_queue()
  */
-void smtp_add_msg(long msgnum, void *userdata) {
+void smtp_add_msg(long msgnum, void *userdata)
+{
 
        if (smtpq == NULL) {
                smtpq_count = 0;
@@ -509,7 +518,8 @@ void smtp_add_msg(long msgnum, void *userdata) {
 /*
  * Run through the queue sending out messages.
  */
-void smtp_do_queue(void) {
+void smtp_do_queue(void)
+{
        int i = 0;
 
        /*
@@ -518,27 +528,27 @@ void smtp_do_queue(void) {
         * don't really require extremely fine granularity here, we'll do it
         * with a static variable instead.
         */
-       if (doing_smtpclient) return;
+       if (doing_smtpclient)
+               return;
        doing_smtpclient = 1;
 
        syslog(LOG_DEBUG, "smtpclient: start queue run");
-       pthread_setspecific(MyConKey, (void *)&smtp_client_CC);
+       pthread_setspecific(MyConKey, (void *) &smtp_client_CC);
 
        if (CtdlGetRoom(&CC->room, SMTP_SPOOLOUT_ROOM) != 0) {
                syslog(LOG_WARNING, "Cannot find room <%s>", SMTP_SPOOLOUT_ROOM);
                doing_smtpclient = 0;
                return;
        }
-
        // Put the queue in memory so we can close the db cursor
        CtdlForEachMessage(MSGS_ALL, 0L, NULL, SPOOLMIME, NULL, smtp_add_msg, NULL);
 
        // We are ready to run through the queue now.
-       for (i=0; i<smtpq_count; ++i) {
+       for (i = 0; i < smtpq_count; ++i) {
                smtp_process_one_msg(smtpq[i]);
        }
 
-       smtpq_count = 0;                // don't free it, we will use this memory on the next run
+       smtpq_count = 0;        // don't free it, we will use this memory on the next run
        doing_smtpclient = 0;
        syslog(LOG_DEBUG, "smtpclient: end queue run");
 }
@@ -549,8 +559,7 @@ void smtp_do_queue(void) {
  */
 CTDL_MODULE_INIT(smtpclient)
 {
-       if (!threading)
-       {
+       if (!threading) {
                CtdlFillSystemContext(&smtp_client_CC, "SMTP_Send");
                CtdlRegisterMessageHook(smtp_aftersave, EVT_AFTERSAVE);
                CtdlRegisterSessionHook(smtp_do_queue, EVT_TIMER, PRIO_AGGR + 50);
@@ -558,5 +567,5 @@ CTDL_MODULE_INIT(smtpclient)
        }
 
        /* return our module id for the log */
-       return "smtpclient";
+       return "smtpclient";
 }