[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

timestamp.c



To: [email protected]

-----BEGIN PGP SIGNED MESSAGE-----

/* timestamp.c - Automatic PGP Time Stamper v0.1
*  by
*  Wei Dai <[email protected]>
*
*       Put the line "|timestamp" in your .forward file, and this
*  program will automaticly scan all your mail for a certain subject heading
*  and if found, will sign the body of that mail with PGP, and send it back.
*  Otherwise, the mail goes to your regular mailbox.
*  This is probably most useful as a "trusted" time stamping service.
*
*  Use for experimental purposes only.  Feel free to modify it, but please
*  send me some e-mail if you do more than change the #defines.
*/

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <sys/types.h>
#include <fcntl.h>

#define MAILBOX "/usr/spool/mail/weidai"
#define MAILLOCK "/usr/spool/mail/weidai.lock"
#define PGPPATH "/u/w/weidai/.pgp"
#define LOG "/u/w/weidai/.timestamp.log"

#define COMMAND "Time Stamp This Mail"
#define MAXLINE 1024
#define FROM "From "
#define SUBJECT "Subject: "

void Remove_nl (char *);

main()
{
        char sLine[MAXLINE], sFrom[255], sFile[255], sTmp[255];
        char *p;
        FILE *fOut, *fMail, *fLog;
        int bDoIt, fd;

        fLog = fopen(LOG, "a");

        sprintf(sFile, "/tmp/pts_%d", getpid());
        fOut = fopen(sFile, "w");

        sFrom[0]=0;

        while (fgets(sLine, MAXLINE, stdin) != NULL)
        {
                fputs(sLine, fOut);
                if (strncmp(sLine, FROM, strlen(FROM)) == 0)
                {
                        fputs(sLine, fLog);
                        for (p = sLine + strlen(FROM); *p && *p != ' '; ++p);
                        *p = '\0';
                        strcpy(sFrom, sLine+strlen(FROM));
                        Remove_nl(sFrom);
                }
                else if (strncmp(sLine, SUBJECT, strlen(SUBJECT)) == 0)
                {
                        fputs(sLine, fLog);
                        bDoIt = (strncasecmp(sLine+strlen(SUBJECT), COMMAND, str
                }
                else if (strlen(sLine) <= 1)
                        break;
        }


        if (sFrom[0]==0)
                bDoIt=0;

        if (bDoIt)
        {
                fclose(fOut);
                fOut = fopen(sFile, "w");

                while (fgets(sLine, MAXLINE, stdin) != NULL)
                        fputs(sLine, fOut);
                fclose(fOut);

                sprisFile);
                system(sTmp);
                fputs(sTmp, fLog);
                fputs("\n", fLog);
                unlink(sFile);

                sprintf(sTmp, "/usr/ucb/mail -s 'Time Stamp Output' '%s' < %s.as
                system(sTmp);
                fputs(sTmp, fLog);
                fputs("\n", fLog);
                sprintf(sTmp, "%s.asc", sFile);
                unlink(sTmp);

                fputs("*** time stamped ***********\n\n", fLog);
        }
        else
        {
                while (fgets(sLine, MAXLINE, stdin) != NULL)
                        fputs(sLine, fOut);
                fclose(fOut);

                while ( (fd=open(MAILLOCK, 0)) != -1)
                {
                        close(fd);
                        sleep(5);
                }
                fd=creat(MAILLOCK, 0600);
                close(fd);

                fOut=fopen(MAILBOX, "a");
                fMail=fopen(sFile, "r");
                while (fgets(sLine, MAXLINE, fMail) != NULL)
                        fputs(sLine, fOut);
                fputs("\n", fOut);
                fclose(fMail);
                fclose(fOut);

                unlink(MAILLOCK);
                unlink(sFile);

                fputs("--- personal mail -----------\n\n", fLog);
        }
        fclose(fLog);
        return(0);
}


void Remove_nl (char *string)
{
        int i=0;

        while(string[i]!='\n' && string[i]!=0)
                i++;

        string[i]=0;
}

-----BEGIN PGP SIGNATURE-----
Version: 2.3a

iQCVAgUBLlRcjjl0sXKgdnV5AQEv2AQAid9urvFjtaQjPYvpqcwhWLy8CCH2OI+O
9mWNnubDZuReH97upNvFYWbDQkFew2Gjfbsj7RwrYSe85gQm+RV0F+/ud64lTCe1
eoPuFrBy2kXugbtJVtp+HB2BGSNc2GtgxIfc61Z3x3E6F4eDagZxtAn2m3ht9Vib
n41IQtRk1uA=
=ojFS
-----END PGP SIGNATURE-----


PGP Public Key available