Platon Technologies
not logged in Login Registration
EnglishSlovak
open source software development celebrating 10 years of open source development! Friday, March 29, 2024

File: [Platon] / libplaton / utils / meetmail / meetmail.c (download)

Revision 1.10, Sun Jan 22 20:16:41 2006 UTC (18 years, 2 months ago) by nepto


Changes since 1.9: +12 -12 lines

Updated copyright dates and URLs

/**************************************************************************
 *                                                                        *
 *  meetmail - mailinglist / conference e-mail modifier                   *
 *                                                                        *
 *  Developed by Ondrej Jombik <nepto@platon.sk>                          *
 *                                                                        *
 *  Copyright (c) 1999-2000 Condy software inc.                           *
 *  Copyright (c) 2001-2006 Platon Group, http://platon.sk/               *
 *  All rights reserved.                                                  *
 *                                                                        *
 *  Updates:                                                              *
 *    2000-07-17, 2000-09-15, 2000-10-05                                  *
 *    2001-01-19 - added 'Errors-To' header handling                      *
 *    2001-03-05 - fixed bug with empty 'Subject' line                    *
 *    2001-04-19 - changed name from 'konfmail' to 'meetmail'             *
 *    2001-05-14 - fixed bug with CONFFILENAMESIZE                        *
 *    2003-01-03 - import into CVS; project 'libplaton' directory 'utils' *
 *               - made meetmail to work with libplaton library           *
 *    2003-04-20 - numerous tiny fixes and code cleanups                  *
 *    2006-01-22 - skip signature appending when base64 encoding is used  *
 *                                                                        *
 **************************************************************************/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <platon/str/strplus.h>
#include <platon/str/strctype.h>

#ifndef __PRGVERSION__
#  define __PRGVERSION__    "0.3.5a"
#endif

#define MEETMAILSTR    \
"Meetmail " __PRGVERSION__ " by Ondrej Jombik <nepto@platon.sk>"

#define REPLYTOSTR        "Reply-To:"
#define SUBJECTSTR        "Subject:"
#define ERRORSTOSTR        "Errors-To:"
#define XCONFSOFTSTR    "X-Conference-Software:"
#define CTESTRANDVAL    "Content-Transfer-Encoding: base64"
#define XOLDSTR            "X-Old"
#define DEFSUBJECTSTR    "(ziadny predmet)"

#define BUFSIZE                    501

#define CONFNAMESIZE            30
#define CONFERRORSTOSIZE        50
#define CONFADDRESSSIZE            50
#define CONFFILENAMESIZE        250

int main(int argc, char **argv)
{
    /* Buffers */
    char buf[BUFSIZE],
    confname[CONFNAMESIZE+1],
    conferrorsto[CONFERRORSTOSIZE+1],
    confaddress[CONFADDRESSSIZE+1],
    conffilename[CONFFILENAMESIZE+1];

    /* Flags */
    unsigned char fLastBufWasEOL = 0,
    fErrorsToModified = 0,
    fReplyToModified = 0,
    fSubjectModified = 0,
    fXConfSoftModified = 0,
    fAppendSignature = 1;

    int eol_count = 0;
    FILE *f;

    /* Information and help */
    if (argc < 3) {
        printf("meetmail - MS-Dos/UNIX conference e-mail modifier"
                " v%s / %s %s\n",__PRGVERSION__,__DATE__,__TIME__);
        puts("Developed by Ondrej Jombik, " \
                "e-mail: nepto@platon.sk, web: http://nepto.org/");
        puts("Copyright (c) 2001-2006 Platon Group, http://platon.org/, "
                "All rights reserved.");

        puts("\nUsage: meetmail <Name> <errors-to-e-mail-address> "
                "[<address>] [<infofile>]");
        puts("default address: name@pobox.sk, " \
                "default infofile: conf.name.txt");

        return 1;
    }

    /* confname */
    strncpy(confname, argv[1], CONFNAMESIZE);
    confname[CONFNAMESIZE] = '\0';

    /* confadminemail */
    strncpy(conferrorsto, argv[2], CONFERRORSTOSIZE);
    confname[CONFERRORSTOSIZE] = '\0';

    /* confaddress */
    if (argc > 3) {
        strncpy(confaddress, argv[3], CONFADDRESSSIZE);
    } else {
        strncpy(confaddress, argv[1], CONFADDRESSSIZE);
        confaddress[CONFADDRESSSIZE] = '\0';
        strncpy(strchr(confaddress, '\0'), "@pobox.sk",
                CONFADDRESSSIZE - strlen(confaddress));
    }
    confaddress[CONFADDRESSSIZE] = '\0';
    strlwr(confaddress);

    /* conffilename */
    if (argc > 4) {
        strncpy(conffilename, argv[4], CONFFILENAMESIZE);
    } else {
        strncpy(conffilename, "conf.", CONFFILENAMESIZE);
        conffilename[CONFFILENAMESIZE] = '\0';
        strncpy(strchr(conffilename, '\0'), argv[1],
                CONFFILENAMESIZE - strlen(conffilename));
        conffilename[CONFFILENAMESIZE] = '\0';
        strncpy(strchr(conffilename, '\0'), ".txt",
                CONFFILENAMESIZE - strlen(conffilename));
    }
    conffilename[CONFFILENAMESIZE] = '\0';
    strlwr(conffilename);

    /* E-mail headers alternation ("Subject:", "Reply-to:") */
    while (fgets(buf, BUFSIZE, stdin) != NULL) {
        if (stristr(buf, CTESTRANDVAL) == buf) {
            fAppendSignature = 0;
        }
        /* Subject modification */
        if (strstr(buf, SUBJECTSTR) == buf) {
            char*pom;
            if ((pom = (char*)malloc(strlen(confname)+2+1)) == NULL) {
#if DEBUG
                fprintf(stderr,"main() WARNING: malloc() allocation error.\n");
#endif
                pom=confname;
            } else {
                strcpy(pom,"[");
                strcpy(strchr(pom,'\0'),confname);
                strcpy(strchr(pom,'\0'),"]");
            }

            if (strstr(buf, pom) == NULL) {
                fputs(SUBJECTSTR,stdout);
                fputc(' ',stdout);
                fputs(pom,stdout);
                fputs(strestr(buf,SUBJECTSTR),stdout);
            } else fputs(buf,stdout);

            fSubjectModified = 1;
            if (pom != NULL)
                free(pom);
        } else if (stristr(buf, REPLYTOSTR) == buf) {
            /* Header "Reply-to:" found */
            fputs(REPLYTOSTR,stdout);
            fputc(' ',stdout);
            fputs(confaddress,stdout);
            fputc('\n',stdout);
            fputs(XOLDSTR, stdout);
            fputc('-', stdout);
            fputs(buf, stdout);
            fReplyToModified=1;
        } else if (stristr(buf, ERRORSTOSTR) == buf) {
            /* Header "Errors-To:" found */
            fputs(ERRORSTOSTR, stdout);
            fputc(' ', stdout);
            fputs(conferrorsto, stdout);
            fputc('\n', stdout);
            fputs(XOLDSTR, stdout);
            fputc('-', stdout);
            fputs(buf, stdout);
            fErrorsToModified=1;
        } else if (stristr(buf, XCONFSOFTSTR) == buf) {
            /* Header "X-Conference-Software:" found */
            fputs(XCONFSOFTSTR,stdout);
            fputc(' ',stdout);
            fputs(MEETMAILSTR, stdout);
            fputc('\n',stdout);
            if (strchr(buf, '-') != NULL) {
                fputs(XOLDSTR, stdout);
                fputs(strchr(buf, '-'), stdout);
            }
            fXConfSoftModified=1;
        } else {
            if (! strcmp(buf, "\n"))
                break;
            fputs(buf, stdout);
        }
    }

    /* Adding "Subject:" header if missing */
    if (! fSubjectModified) {
        fputs(SUBJECTSTR, stdout);
        fputc(' ', stdout);
        fputc('[', stdout);
        fputs(confname, stdout);
        fputc(']', stdout);
        fputc(' ', stdout);
        fputs(DEFSUBJECTSTR, stdout);
        fputc('\n', stdout);
    }

    /* Adding "Reply-to:" header if missing */
    if (! fReplyToModified) {
        fputs(REPLYTOSTR,stdout);
        fputc(' ',stdout);
        fputs(confaddress,stdout);
        fputc('\n',stdout);
    }

    /* Adding "X-Conference-Software:" header if missing */
    if (! fXConfSoftModified) {
        fputs(XCONFSOFTSTR,stdout);
        fputc(' ',stdout);
        fputs(MEETMAILSTR,stdout);
        fputc('\n',stdout);
    }

    /* Adding "Errors-To:" header if missing */
    if (! fErrorsToModified) {
        fputs(ERRORSTOSTR, stdout);
        fputc(' ', stdout);
        fputs(conferrorsto, stdout);
        fputc('\n', stdout);
    }

    fputc('\n',stdout);

    /* E-mail message copying */
    while (fgets(buf, BUFSIZE, stdin) != NULL) {
        fLastBufWasEOL = strchr(buf, '\n') != NULL ? 1 : 0;

        if (strchr(buf, '\n') == buf) {
            eol_count++;
        } else {
            for (; eol_count > 0; eol_count--)
                fputc('\n', stdout);
            fputs(buf, stdout);
        }
    }

    if (fAppendSignature) {

        /* End of e-mail message altering and preparing e-mail conference
           informational text adding */
        if (!fLastBufWasEOL)
            fputc('\n',stdout);

        /* Adding info text from file */
        if ((f = fopen(conffilename, "rt")) != NULL) {
            while (fgets(buf,BUFSIZE,f) != NULL)
                fputs(buf, stdout);
            fclose(f);
        } else {
            fprintf(stdout, "\n\n--\nMeetmail WARNING: "
                    "Cannot open conference signature file '%s'.", conffilename);
            fputs("\nPlease, notice your conference administrator"
                    " with this problem.\n", stdout);
        }

        /* Warning text if already altered e-mail was modified */
        if (fXConfSoftModified) {
            fputs("\n\n--\nMeetmail WARNING: "
                    "E-mail message was already modified.", stdout);
            fputs("\nPlease, notice your conference administrator"
                    " with this problem.\n", stdout);
        }
    }

    return 0;
}


Platon Group <platon@platon.org> http://platon.org/
Copyright © 2002-2006 Platon Group
Site powered by Metafox CMS
Go to Top