<commit_before>/* <@LICENSE>
 * Copyright 2004 Apache Software Foundation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </@LICENSE>
 */

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#define MAXOPTS 16

#define TRY(exp) do {                                                         \
          if ((exp) == -1) {                                                  \
            printf("%s:%d: '%s' failed: ",                                    \
              __FILE__,                                                       \
              __LINE__,                                                       \
              #exp                                                            \
            ); perror(NULL);                                                  \
            exit(81);                                                         \
          }                                                                   \
        } while(0)

int main(int argc, char **argv)
{
    int pfds[2];
    pid_t childpid;
    char *socket = getenv("SPAMDSOCK");   /* Unix Domain Socket path  */
    char *host = getenv("SPAMDHOST");     /* remote spamd host name   */
    char *port = getenv("SPAMDPORT");     /* remote spamd host port   */
    char *ssl = getenv("SPAMDSSL");       /* use ssl for spamc/spamd  */
    char *limit = getenv("SPAMDLIMIT");   /* message size limit       */
    char *user = getenv("SPAMDUSER");     /* spamc user configuration */
    char *options[MAXOPTS];
    int opt = 0;

    /* create the array of options */
    options[opt++] = "spamc";             /* set zeroth argument */
    if (socket) {
        options[opt++] = "-U";
        options[opt++] = socket;
    }
    if (host) {
        options[opt++] = "-d";
        options[opt++] = host;
    }
    if (port) {
        options[opt++] = "-p";
        options[opt++] = port;
    }
    if (ssl) {
        options[opt++] = "-S";
    }
    if (limit) {
        options[opt++] = "-s";
        options[opt++] = limit;
    }
    if (user) {
        options[opt++] = "-u";
        options[opt++] = user;
    }
    options[opt] = NULL;

    TRY(pipe(pfds));
    TRY(childpid = fork());
    if (childpid == 0) {                /* the child ... */
        TRY(close(1));                    /* close normal stdout */
        TRY(dup(pfds[1]));                /* make stdout same as pfds[1] */
        TRY(close(pfds[0]));              /* we don't need this */
        TRY(execvp("spamc", options));
    }
    else {                              /* the parent ... */
        TRY(close(0));                    /* close normal stdin */
        TRY(dup(pfds[0]));                /* make stdin same as pfds[0] */
        TRY(close(pfds[1]));              /* we don't need this */
        TRY(execlp("qmail-queue", "qmail-queue", NULL));
    }
    
    /* never reached */
    return 81;
}<commit_msg>bug 2927: Added possibility to skip messages if RELAYCLIENT is set (configure check to follow). Also get rid of some vars.<commit_after>/* <@LICENSE>
 * Copyright 2004 Apache Software Foundation
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *     http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * </@LICENSE>
 */

#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>


#define MAXOPTS 16

#define TRY(exp) do {                                                         \
          if ((exp) == -1) {                                                  \
            fprintf(stderr, "%s:%d: '%s' failed: ",                           \
              __FILE__,                                                       \
              __LINE__,                                                       \
              #exp                                                            \
            ); perror(NULL);                                                  \
            exit(81);                                                         \
          }                                                                   \
        } while(0)


int main(int argc, char **argv)
{
    char *options[MAXOPTS];
    char *val = NULL;
    int   opt = 0;

    pid_t childpid;
    int pfds[2];


#ifdef HAVE_QMAIL_RELAYCLIENT
    /*
     * use standard qmail-queue if this is a RELAYCLIENT,
     * see <http://bugzilla.spamassassin.org/show_bug.cgi?id=2927>
     */
    if (getenv("RELAYCLIENT")) {
       TRY(execlp("qmail-queue", "qmail-queue", NULL));
    }
#endif


    /* create the array of options */
    options[opt++] = "spamc";            /* set zeroth argument */
    if ((val = getenv("SPAMDSOCK")) != NULL) {   /* Unix Domain Socket path */
        options[opt++] = "-U";
        options[opt++] = val;
    }
    if ((val = getenv("SPAMDHOST")) != NULL) {   /* remote spamd host name */
        options[opt++] = "-d";
        options[opt++] = val;
    }
    if ((val = getenv("SPAMDPORT")) != NULL) {   /* remote spamd port number */
        options[opt++] = "-p";
        options[opt++] = val;
    }
    if ((val = getenv("SPAMDSSL")) != NULL) {    /* use ssl for spamc/spamd */
        options[opt++] = "-S";
    }
    if ((val = getenv("SPAMDLIMIT")) != NULL) {  /* message size limit */
        options[opt++] = "-s";
        options[opt++] = val;
    }
    if ((val = getenv("SPAMDUSER")) != NULL) {   /* spamc user configuration */
        options[opt++] = "-u";
        options[opt++] = val;
    }
    options[opt] = NULL;                 /* terminate argument list */


    TRY(pipe(pfds));
    TRY(childpid = fork());
    if (childpid == 0) {                /* the child ... */
        TRY(close(1));                    /* close normal stdout */
        TRY(dup(pfds[1]));                /* make stdout same as pfds[1] */
        TRY(close(pfds[0]));              /* we don't need this */
        TRY(execvp("spamc", options));
    }
    else {                              /* the parent ... */
        TRY(close(0));                    /* close normal stdin */
        TRY(dup(pfds[0]));                /* make stdin same as pfds[0] */
        TRY(close(pfds[1]));              /* we don't need this */
        TRY(execlp("qmail-queue", "qmail-queue", NULL));
    }
    
    /* never reached */
    return 81;
}

{'fraction_non_alphanumeric': 0.1353498745469752, 'fraction_numerical': 0.008642319487036521, 'mean_word_length': 1.2894065092533504, 'pattern_counts': {'":': 0, '<': 14, '<?xml version=': 0, '>': 14, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 37, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7277890', 'n_tokens_mistral': 2002, 'n_tokens_neox': 1900, 'n_words': 559}