home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Fish 2
/
goldfish_vol2_cd1.bin
/
files
/
comm
/
mail
/
smail
/
src
/
rcs
/
mail.c,v
< prev
next >
Wrap
Text File
|
1993-12-21
|
19KB
|
1,011 lines
head 1.13;
access;
symbols
C_1:1.13;
locks; strict;
comment @ * @;
1.13
date 93.11.06.16.00.10; author Aussem; state Exp;
branches;
next 1.12;
1.12
date 93.11.02.20.12.42; author Aussem; state Exp;
branches;
next 1.11;
1.11
date 93.10.31.20.10.53; author Aussem; state Exp;
branches;
next 1.10;
1.10
date 93.10.23.21.22.49; author Aussem; state Exp;
branches;
next 1.9;
1.9
date 93.10.21.21.17.05; author Aussem; state Exp;
branches;
next 1.8;
1.8
date 93.10.16.14.54.51; author Aussem; state Exp;
branches;
next 1.7;
1.7
date 93.10.13.21.41.42; author Aussem; state Exp;
branches;
next 1.6;
1.6
date 93.10.02.00.14.38; author Aussem; state Exp;
branches;
next 1.5;
1.5
date 93.09.30.22.21.34; author Aussem; state Exp;
branches;
next 1.4;
1.4
date 93.09.30.21.07.03; author Aussem; state Exp;
branches;
next 1.3;
1.3
date 93.09.23.22.44.57; author Aussem; state Exp;
branches;
next 1.2;
1.2
date 93.09.18.16.47.47; author Aussem; state Exp;
branches;
next 1.1;
1.1
date 93.09.11.15.01.16; author Aussem; state Exp;
branches;
next ;
desc
@Local mailer for smail
@
1.13
log
@mail now don't stop at once if the delivering fails
@
text
@/*
* emulation of the unix mail command
* Just append it to the mail-folder
*
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
* $Log: mail.c,v $
* Revision 1.12 1993/11/02 20:12:42 Aussem
* MUFS routines insert
*
* Revision 1.11 1993/10/31 20:10:53 Aussem
* submitt a bigger stack
*
* Revision 1.10 1993/10/23 21:22:49 Aussem
* mail now uses the mail folder directly (uumail:user)
*
* Revision 1.9 1993/10/21 21:17:05 Aussem
* MailReadyCmd will be started via run <nil: >nil:
* only if t:mailrdy does not exists
* if the mail folder is locked, mail will be wait until
* the mail folder is unlocked
*
* Revision 1.8 1993/10/16 14:54:51 Aussem
* cosmetic changes
*
* Revision 1.7 1993/10/13 21:41:42 Aussem
* mail supports now more than one address for each
* invocation. This is needed for Maxrmaillength!=0 !
*
* Revision 1.6 1993/10/02 00:14:38 Aussem
* MailReadyCmd keyword in uulib:condif is supported by mail and mail_axsh
*
* Revision 1.5 1993/09/30 22:21:34 Aussem
* if env:MAILTONOEXIST mail will deliver a mail although the user does not
* exists on the site.
*
* Revision 1.4 1993/09/30 21:07:03 Aussem
* mail wait now 6 minutes to open uumail:<mail-folder>
*
* Revision 1.3 1993/09/23 22:44:57 Aussem
* removes uumail:<file>.o before backup uumail:<file>
*
* Revision 1.2 1993/09/18 16:47:47 Aussem
* put the "normal" and axsh version in this file (set define AXSH
* for the AXSh Version)
*
* Revision 1.1 1993/09/11 15:01:16 Aussem
* Initial revision
*
*
*/
static char *rcsid="$Id: mail.c,v 1.12 1993/11/02 20:12:42 Aussem Exp Aussem $";
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <dos.h>
#include <proto/dos.h>
#include <pragmas/dos_pragmas.h>
#include <proto/exec.h>
#include <pragmas/exec_pragmas.h>
#ifdef AXSH
#include "axsh/iomodes.h"
#include "axsh/misc.h"
#include "axsh/users.h"
static struct User usr;
#endif
extern struct DosLibrary *DOSBase;
/* should be large enough */
long __stack=20000L;
/* global Vars for this modul */
static const char *uumail = "UUMAIL:";
static const char *version = "$VER: mail V1.4 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
static const int maxretry = 30;
static const int retrysecs = 20;
static char *argv0 = "mail";
/* prototypes */
static char *readfile (char *);
static long filelength (char *);
static void sleep (unsigned long time);
char * findconfig(char *);
#ifdef AXSH
int
getuid (char *name)
{
if (search_userdata ("AXsh:etc/passwd", &usr, 0, name) == -1) /* if user not found */
return(0);
return(1);
}
#endif
#ifdef MUFS
#include <proto/multiuser.h>
#include <pragmas/multiuser_pragmas.h>
#include <libraries/multiuser.h>
struct muBase *muBase=NULL;
struct muUserInfo *ui=NULL;
int setup_mufs(void);
void kill_mufs(void);
int getuid(char *name)
{
if(!setup_mufs())
return(0);
strcpy(ui->UserID,name);
if(muGetUserInfo(ui,muKeyType_UserID)==NULL)
{
return(0);
}
return(1);
}
int setup_mufs(void)
{
if(!muBase)
{
muBase=(struct muBase *)OpenLibrary(MULTIUSERNAME,MULTIUSERVERSION);
if(!muBase)
{
#ifdef DEBUG
printf("%s: unable to open %s Version >= %d\n",argv0,MULTIUSERNAME,MULTIUSERVERSION);
#endif
return(0);
}
}
if(!ui)
{
ui=muAllocUserInfo();
if(!ui)
{
kill_mufs();
#ifdef DEBUG
printf("%s: unable to alloc mem\n");
#endif
return(NULL);
}
}
return(1);
}
void kill_mufs(void)
{
if(ui)
muFreeUserInfo(ui);
if(muBase)
CloseLibrary((struct Library *)muBase);
}
#endif /* MUFS */
/*
* sleep():
* wait <time> seconds
*/
static void
sleep (unsigned long time)
{
Delay (50L * time);
}
/*
* filelength():
* returns the length of file <fname>
* it returns -1 if the file does not exists or locked
* by someone else
*/
static
long
filelength (char *fname)
{
struct FileInfoBlock __aligned fileinfo;
long groesse;
BPTR fp;
fp=Open(fname,MODE_OLDFILE);
if(!fp)
{
LONG error=IoErr();
if(error == ERROR_OBJECT_IN_USE)
return(-2);
if(error == ERROR_OBJECT_NOT_FOUND)
return(-1);
}
ExamineFH (fp, &fileinfo);
groesse = (long) fileinfo.fib_Size;
Close (fp);
return (groesse);
}
long getpid(void)
{
struct Process *proc;
Forbid();
proc=(struct Process *)FindTask(NULL);
Permit();
if(proc)return(proc->pr_TaskNum);
return(0);
}
int lock_with_file(char *lockfilename)
{
FILE *file;
char buf[BUFSIZ];
while( ( file = fopen( lockfilename, "r" ) ) != NULL )
{
fgets( buf, sizeof(buf), file );
fclose( file );
#ifdef DEBUG
printf( "Mail locked by proc '%s'. Waiting 10 secs\n", buf);
#endif
sleep( 10 );
}
#ifdef DEBUG
printf("locking Mail.\n");
#endif
if( ( file = fopen( lockfilename, "w" ) ) == NULL ) return -1;
fprintf( file, "%d\n", getpid() );
fclose( file );
return 0;
}
int unlock_with_file( char *lockfilename )
{
#ifdef DEBUG
printf("unlock Mail.\n");
#endif
return remove( lockfilename );
}
/*
* readfile():
* read file <filename> and returns the buffer
*
*/
static
char *
readfile (char *filename)
{
char *puf;
size_t len, read;
FILE *fp;
#ifdef DEBUG
printf("Reading %s.\n",filename);
#endif
if (!filename)
return (NULL);
len = filelength (filename);
if (len < 1)
{
printf ("\n%s: unable to open file %s", argv0, filename);
return (NULL);
}
puf = malloc ((len + 1) * sizeof (char));
if (!puf)
{
printf ("\n%s: unable to allocate %d Bytes", argv0, (len + 1) * sizeof (char));
free (puf);
return (NULL);
}
fp = fopen (filename, "r");
if (!fp)
{
printf ("\n%s: unable to open file %s", argv0, filename);
free (puf);
return (NULL);
}
read = fread (puf, len, 1, fp) * len;
if (read != len)
{
printf ("\n%s: unable to read from %s %d (%d) bytes", argv0, filename, len, read);
free (puf);
fclose (fp);
return (NULL);
}
puf[len]='\0';
fclose (fp);
return (puf);
}
#define CTLZ ('z'&0x1F)
static char *ConfBuf = NULL;
char *
findconfig(field)
char *field;
{
char *str;
short flen = strlen(field);
/*
* load config file if not already loaded
*/
if (ConfBuf == NULL) {
FILE *fi;
fi = fopen("S:UUConfig", "r");
if (fi == NULL)
fi = fopen("UULIB:Config", "r");
if (fi) {
long buflen;
fseek(fi, 0L, 2);
buflen = ftell(fi);
fseek(fi, 0L, 0);
if (buflen > 0 && (ConfBuf = malloc(buflen + 1))) {
fread(ConfBuf, buflen, 1, fi);
ConfBuf[buflen] = CTLZ; /* can't use \0 */
for (str = ConfBuf; *str && *str != CTLZ; ++str) {
char *bup;
if (*str == '\n') { /* make separate strs */
*str = 0;
/* remove white space at end */
for (bup = str - 1; bup >= ConfBuf && (*bup == ' ' || *bup == 9); --bup)
*bup = 0;
}
}
} else {
ConfBuf = NULL;
}
fclose(fi);
}
}
if (ConfBuf == NULL)
return(NULL);
/*
* Search ConfBuf for Field<space/tab>
*/
for (str = ConfBuf; *str != CTLZ; str += strlen(str) + 1) {
if (*str == 0 || *str == '#')
continue;
if (strnicmp(str, field, flen) == 0 && (str[flen] == ' ' || str[flen] == '\t')) {
str += flen;
while (*str == ' ' || *str == 9)
++str;
return(str);
}
}
return(NULL);
}
/*
* MAIN
*/
int
main (int argc, char *argv[])
{
FILE *fp;
char file[128],lockfile[128], puf[128], *text, *cmd,*address;
long len;
int retry,i,fail=0;
argv0 = argv[0];
if (argc < 3)
{
printf ("usage %s mail-file address0 .. addressn\n", argv0);
exit (10);
}
text = readfile (argv[1]);
if (!text)
{
/* error messages are generated by readfile() */
remove (file);
unlock_with_file(lockfile);
exit (10);
}
for(i=2;i<argc;i++)
{
address=argv[i];
retry=0;
printf("sending mail to '%s'...",address);
strcpy (file, uumail);
strcat (file, address);
len=filelength(file);
while(len==-2)
{
len=filelength(file);
retry++;
printf ("\n%s: unable to open %s (%d retries done), waiting %d secs", argv0, file, retry-1,retrysecs);
sleep (retrysecs);
}
#if defined(AXSH) || defined(MUFS)
if(!getuid(address))
{
if(getenv("MAILTONOEXIST")==NULL)
{
printf (" No user '%s' exists\n",address);
fail=1;
continue;
}
}
#else
if(len==-1)
{
if(getenv("MAILTONOEXIST")==NULL)
{
printf (" No mail-folder for user '%s'\n",address);
fail=1;
continue;
}
}
#endif
strcpy (lockfile, "T:");
strcat (lockfile, address);
strcat (lockfile,".lck");
lock_with_file(lockfile);
fp = fopen (file, "a");
if (!fp)
{
printf ("\n%s: Unable to open the backup mail-folder for %s (%s)", argv0, address, file);
remove (file);
unlock_with_file(lockfile);
exit (10);
}
len = strlen (text);
if ((fwrite (text, len, 1, fp) * len) != len)
{
printf ("\n%s: Error appending mail to mail-folder %s", argv0, file);
fclose (fp);
remove (file);
unlock_with_file(lockfile);
exit (10);
}
fclose (fp);
unlock_with_file(lockfile);
cmd=findconfig("MailReadyCmd");
if(cmd)
{
if(filelength("T:MailRdy")==-1)
{
strcpy(puf,"echo >T:MailRdy");
system(puf);
strcpy(puf,"run <nil: >nil: ");
strcat(puf,cmd);
system(puf);
}
}
putchar('\n');
}
if(text)
free (text);
#ifdef MUFS
kill_mufs();
#endif
if(fail)
exit (5);
exit(0);
}
@
1.12
log
@MUFS routines insert
@
text
@d21 3
d66 1
a66 1
static char *rcsid="$Id: mail.c,v 1.11 1993/10/31 20:10:53 Aussem Exp Aussem $";
d385 1
a385 1
int retry,i;
d429 2
a430 1
exit (20);
d440 2
a441 1
exit (20);
d493 3
a495 1
exit (0);
@
1.11
log
@submitt a bigger stack
@
text
@d21 3
d63 1
a63 1
static char *rcsid="$Id: mail.c,v 1.10 1993/10/23 21:22:49 Aussem Exp Aussem $";
d110 62
d420 1
a420 1
#ifdef AXSH
d485 3
@
1.10
log
@mail now uses the mail folder directly (uumail:user)
@
text
@d21 3
d60 1
a60 1
static char *rcsid="$Id: mail.c,v 1.9 1993/10/21 21:17:05 Aussem Exp Aussem $";
d81 3
d86 1
a86 1
static const char *version = "$VER: mail V1.3 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
@
1.9
log
@MailReadyCmd will be started via run <nil: >nil:
only if t:mailrdy does not exists
if the mail folder is locked, mail will be wait until
the mail folder is unlocked
@
text
@d21 6
d57 1
a57 1
static char *rcsid="$Id: mail.c,v 1.8 1993/10/16 14:54:51 Aussem Exp Aussem $";
d311 1
a311 1
int rc, retry,i;
a374 23
/* remove uumail:<file>.o */
strcpy (puf, file);
strcat (puf, ".o");
remove(puf);
if(len>0)
{
strcpy (puf, "copy ");
strcat (puf, file);
strcat (puf, " to ");
strcat (puf, file);
strcat (puf, ".o");
rc = system (puf);
if (rc)
{
printf ("\n%s: Unable to create backup file (%s)", argv0, puf);
unlock_with_file(lockfile);
exit (10);
}
}
strcat (file, ".o");
d393 1
a394 18
strcpy (puf, "copy ");
strcat (puf, file);
strcat (puf, " to ");
strcat (puf, file);
len = strlen (puf);
if (len >= 2)
puf[len - 2] = '\0';
rc = system (puf);
if (rc)
{
printf ("\n%s: Unable to rename backup file (%s)", argv0, puf);
remove (file);
unlock_with_file(lockfile);
exit (10);
}
remove (file);
d409 1
a409 1
putc('\n',fp);
@
1.8
log
@cosmetic changes
@
text
@d21 3
d51 1
a51 1
static char *rcsid="$Id: mail.c,v 1.7 1993/10/13 21:41:42 Aussem Exp Aussem $";
d74 1
a74 1
static const char *version = "$VER: mail V1.2 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
a115 1
struct FileLock *lock;
d117 6
d124 6
a129 3
if (!(lock = (struct FileLock *) Lock (fname, ACCESS_READ)))
return (-1);
Examine ((BPTR) lock, &fileinfo);
d131 1
a131 1
UnLock ((BPTR) lock);
d201 1
a201 1
printf ("%s: unable to open file %s\n", argv0, filename);
d208 1
a208 1
printf ("%s: unable to allocate %d Bytes\n", argv0, (len + 1) * sizeof (char));
d216 1
a216 1
printf ("%s: unable to open file %s\n", argv0, filename);
d224 1
a224 1
printf ("%s: unable to read from %s %d (%d) bytes\n", argv0, filename, len, read);
d315 10
a330 5
strcpy (lockfile, "T:");
strcat (lockfile, address);
strcat (lockfile,".lck");
lock_with_file(lockfile);
d333 1
d335 7
a341 1
len=filelength(file);
a348 1
unlock_with_file(lockfile);
a358 1
unlock_with_file(lockfile);
d363 7
a376 1
d385 1
a385 1
printf ("%s: Unable to create backup file (%s)\n", argv0, puf);
d392 1
a392 20
text = readfile (argv[1]);
if (!text)
{
/* error messages are generated by readfile() */
remove (file);
unlock_with_file(lockfile);
exit (10);
}
do
{
retry++;
fp = fopen (file, "a");
if (fp)
break;
printf ("%s: unable to open %s, waiting %d secs\n", argv0, file, retrysecs);
sleep (retrysecs);
}
while (retry < maxretry);
d395 1
a395 1
printf ("%s: Unable to open the backup mail-folder for %s (%s)\n", argv0, address, file);
a396 2
if (text)
free (text);
d404 1
a404 1
printf ("%s: Error appending mail to mail-folder %s\n", argv0, file);
a405 2
if (text)
free (text);
a410 2
if (text)
free (text);
d422 1
a422 1
printf ("%s: Unable to rename backup file (%s)\n", argv0, puf);
d430 1
d433 11
a443 1
system(cmd);
d445 3
@
1.7
log
@mail supports now more than one address for each
invocation. This is needed for Maxrmaillength!=0 !
@
text
@d21 4
d48 1
a48 1
static char *rcsid="$Id: mail.c,v 1.6 1993/10/02 00:14:38 Aussem Exp Aussem $";
d71 1
a71 1
static const char *version = "$VER: mail V1.1 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
d368 1
d379 1
a379 1
break;
@
1.6
log
@MailReadyCmd keyword in uulib:condif is supported by mail and mail_axsh
@
text
@d21 3
d44 1
a44 1
static char *rcsid="$Id: mail.c,v 1.5 1993/09/30 22:21:34 Aussem Exp Aussem $";
d288 1
a288 1
char file[128],lockfile[128]="T:", puf[128], *text, *cmd;
d290 1
a290 1
int rc, retry = 0;
d294 1
a294 1
if (argc == 4)
d296 1
a296 1
printf ("%s: only mail to local host possible\nPlease use your sendmail program !\n", argv0);
d299 6
a304 5
if (argc != 3)
{
printf ("usage %s mail-file address\n", argv0);
exit (10);
}
d306 2
a307 1
strcat (lockfile, argv[2]);
d312 1
a312 1
strcat (file, argv[2]);
d317 1
a317 1
if(!getuid(argv[2]))
d321 1
a321 1
printf (" No user '%s' exists\n",argv[2]);
d332 1
a332 1
printf (" No mail-folder for user '%s'\n",argv[2]);
d382 1
a382 1
printf ("%s: Unable to open the backup mail-folder for %s (%s)\n", argv0, argv[2], file);
d426 1
@
1.5
log
@if env:MAILTONOEXIST mail will deliver a mail although the user does not
exists on the site.
@
text
@d21 4
d41 1
a41 1
static char *rcsid="$Id: mail.c,v 1.4 1993/09/30 21:07:03 Aussem Exp Aussem $";
d73 1
d216 62
d285 1
a285 1
char file[128],lockfile[128]="T:", puf[128], *text;
d418 3
@
1.4
log
@mail wait now 6 minutes to open uumail:<mail-folder>
@
text
@d21 3
d37 1
a37 1
static char *rcsid="$Id: mail.c,v 1.3 1993/09/23 22:44:57 Aussem Exp Aussem $";
d247 6
a252 3
printf (" No user '%s' exists\n",argv[2]);
unlock_with_file(lockfile);
exit (20);
d258 6
a263 3
printf (" No mail-folder for user '%s'\n",argv[2]);
unlock_with_file(lockfile);
exit (20);
@
1.3
log
@removes uumail:<file>.o before backup uumail:<file>
@
text
@d21 3
d34 1
a34 1
static char *rcsid="$Id: mail.c,v 1.2 1993/09/18 16:47:47 Aussem Exp Aussem $";
d57 3
a59 2
static const char *version = "$VER: mail V1.0 © 1993 by Ralph-Thomas Aussem ("__DATE__","__TIME__")";
static const int maxretry = 10;
d294 2
a295 2
printf ("%s: unable to open %s, waiting %d secs\n", argv0, file, retry);
sleep (retry);
@
1.2
log
@put the "normal" and axsh version in this file (set define AXSH
for the AXSh Version)
@
text
@d21 4
d31 1
a31 1
static char *rcsid="$Id: mail.c,v 1.1 1993/09/11 15:01:16 Aussem Exp Aussem $";
d253 5
d260 1
@
1.1
log
@Initial revision
@
text
@d5 19
a23 9
* Copyright:
* This package is freeware. This means you can copy it freely
* as long as you don't ask any money for it, except perhaps a
* nominal fee for copying. The package is however Copyright ©
* Ralph-Thomas Aussem, All Rights Reserved. The author
* reservers the right to change the status of this package
* whenever he may find it appropriate.
* $Log$
d27 1
a27 1
static char *rcsid="$Id$";
d38 8
d59 10
d101 43
d157 4
d207 1
a207 1
char file[128], puf[128], *text;
d224 4
d231 4
a234 1
if(filelength(file)==-1)
d236 2
a237 1
printf (" No mail-folder for user >>%s<< exists\n",argv[2]);
d240 3
a242 7
strcpy (puf, "copy ");
strcat (puf, file);
strcat (puf, " to ");
strcat (puf, file);
strcat (puf, ".o");
rc = system (puf);
if (rc)
d244 3
a246 2
printf ("%s: Unable to create backup file (%s)\n", argv0, puf);
exit (10);
d248 16
a263 1
d270 1
d291 1
d303 1
d322 1
d327 1
@