static char sccsid
[] = "%W% %E%";
char *ctime(), *index(), *rindex(), *ctime(), *strcpy(), *getlogin();
char *mktemp(), *sprintf();
struct passwd
*getpwnam(), *getpwuid();
#define MSGSCMD "/usr/ucb/msgs"
#define MAILDIR "/usr/spool/mail"
char lettmp
[] = "/tmp/MaXXXXX"; /* keep letter before sending it */
char preptmp
[] = "/tmp/mbXXXXX"; /* if prepending msg, use this file */
int chew
; /* if true, strip extra from lines */
int dflag
; /* if true, don't call sendmail */
char shopcnt
[30] = "0"; /* hop count parameter for rmt mail */
int errs
; /* no of errs in sending */
char deleteonly
; /* if true, just delete mailbox */
char remname
[50]; /* if non-empty, from line extra */
char namebuf
[128], *sn
= NULL
, logindir
[60];
if (sn
== NULL
|| *sn
== 0 || *sn
== ' ') {
pwd
= getpwuid(myuid
); /* will read passwd file */
(void) strcpy(logindir
, pwd
->pw_dir
);
fprintf(stderr
, "Who are you?\n");
(void) strcpy(namebuf
, sn
);
for (argc
--, argv
++; argc
> 0 && argv
[0][0] == '-'; argc
--, argv
++)
printmail(argc
, argv
, namebuf
, logindir
);
case 'r': /* one-arg -r-- -r addr */
/* ignore -r if not network or root */
if (strcmp("network", namebuf
) == 0 || myuid
== 0 ||
/*###86 [lint] index arg. 1 used inconsistently v6mail.c(86) :: v6mail.c(244)%%%*/
/*###86 [lint] index arg. 2 used inconsistently v6mail.c(86) :: v6mail.c(244)%%%*/
strcmp("uucp", namebuf
) == 0 || index('!', argv
[1])) {
(void) strcpy(namebuf
, argv
[1]);
chew
++; /* eat From lines */
(void) strcpy(remname
, argv
[1]);
case 'h': /* hop count - used by network */
(void) strcpy(shopcnt
, argv
[1]);
case 'd': /* really deliver this message */
case 'D': /* only delete the invokers mailbox */
goto hitit
; /* delete mail box, thats all */
/* if we are already ignoring signals, catch sigint */
if (signal(SIGINT
, SIG_IGN
) != SIG_IGN
)
(void) signal(SIGINT
, delexit
);
bulkmail(argc
, argv
, namebuf
);
printmail(argc
, argv
, name
, logindir
)
char sfnmail
[60], mbox
[120];
(void) sprintf(sfnmail
, "%s/%s", MAILDIR
, name
);
fdin
= fopen(sfnmail
, "r");
if (fdin
< 0 || fstat(fileno(fdin
), &stb
) < 0 || stb
.st_size
== 0) {
printf("%s: Too many links.\n", sfnmail
);
(void) getput(fdin
, stdout
);
printf("Save (y or n) ?"); (void) fflush(stdout
);
(void) sprintf(mbox
, "%s/mbox", logindir
);
printf("Saving mail in %s.\n", mbox
);
if (append(sfnmail
, mbox
, getuid(), getgid()) == 0)
bulkmail(argc
, argv
, from
)
execv("/usr/lib/sendmail", argv
);
perror("/usr/lib/sendmail");
fdout
= fopen(lettmp
, "w");
* If delivering mail from the network via mail -r,
* Strip the leading line and throw it away, as long
* as it begins with "From ..." (and preserve the date if poss.)
if (fgets(linebuf
, BUFSIZ
, stdin
) == 0)
if (!strncmp(linebuf
, "From ", 5) != 0)
printfromline(fdout
, getdate(linebuf
), from
);
printfromline(fdout
, (char *)0, from
);
fprintf(fdout
, "%s", linebuf
);
printfromline(fdout
, (char *)0, from
);
fprintf(fdout
, "(from %s)\n", remname
);
if (getput(stdin
, fdout
) == 0)
printfromline(fdout
, date
, from
)
fprintf(fdout
, "From %s %s", from
, date
);
/* look over linebuf and return ptr to date, NULL if error */
register char *s
= linebuf
;
/*###244 [lint] index arg. 2 used inconsistently v6mail.c(86) :: v6mail.c(244)%%%*/
/*###244 [lint] index arg. 1 used inconsistently v6mail.c(86) :: v6mail.c(244)%%%*/
while (s
= index(' ', s
))
if (!strncmp(s
, " Sun ", 5) ||
!strncmp(s
, " Mon ", 5) ||
!strncmp(s
, " Tue ", 5) ||
!strncmp(s
, " Wed ", 5) ||
!strncmp(s
, " Thu ", 5) ||
!strncmp(s
, " Fri ", 5) ||
char mailboxname
[BUFSIZ
];
if (index('/', person
)) {
if (!writeable(person
)) {
(void) append(lettmp
, person
, -1, -1);
(void) sprintf(mailboxname
, "%s/%s", MAILDIR
, person
);
(void) append(lettmp
, mailboxname
, pwd
->pw_uid
, pwd
->pw_gid
);
fprintf(stderr
, "Can't send to %s.\n", person
);
if (!writeable("dead.letter")) {
printf("Letter saved in 'dead.letter'\n");
(void) append(lettmp
, "dead.letter", getuid(), getgid());
struct sockaddr_in biffaddr
= { AF_INET
, IPPORT_BIFFUDP
};
append(from
, to
, uid
, gid
)
register FILE *fdin
, *fdout
;
char *cp
, buf
[100]; int f
;
if (stat(to
, &stb
) >= 0 && (stb
.st_mode
&S_IFMT
) != S_IFREG
) {
fprintf(stderr
, "Not a plain file: %s\n", to
);
(void) chown(to
, uid
, gid
);
(void) chmod(to
, MAILMODE
);
if ((fdin
= fopen(from
, "r")) == NULL
) {
char *host
= "localhost";
biffaddr
.sin_addr
.s_addr
= rhost(&host
);
(biffaddr
.sin_port
<<8) | ((biffaddr
.sin_port
>>8) & 0xff);
f
= socket(SOCK_DGRAM
, 0, 0, 0);
(void) sprintf(buf
, "%s@%d\n", cp
+1, ftell(fdout
));
ret
= getput(fdin
, fdout
);
send(f
, &biffaddr
, buf
, strlen(buf
)+1);
register FILE *fdin
, *fdout
;
while ((c
= getc(fdin
)) != EOF
) {
if (stat(name
, &stb
) < 0) {
ok
= access(cp
? "." : name
, 2) == 0;
return (access(name
, 2) == 0);
char locktmp
[30]; /* Usable lock temporary */
char curlock
[50]; /* Last used name of lock */
int locked
; /* To note that we locked it */
* Lock the specified mail file by setting the file mailfile.lock.
* We must, of course, be careful to unlink the lock file by a call
* to unlock before we stop. The algorithm used here is to see if
* the lock exists, and if it does, to check its modify time. If it
* is older than 30 seconds, we assume error and set our own file.
* Otherwise, we wait for 5 seconds and try again.
(void) sprintf(curlock
, "%s%s", file
, ".lock");
(void) sprintf(locktmp
, "%s/tmXXXXXX", MAILDIR
);
f
= lock1(locktmp
, curlock
);
if (stat(curlock
, &statbuf
) < 0)
if (curtime
< statbuf
.st_mtime
+ 30) {
* Attempt to set the lock by creating the temporary file,
* then doing a link/unlink. If it fails, return -1 else 0
fno
= creat(tempfile
, 0400);
if (link(tempfile
, name
) < 0) {
i
= creat(sfn
, MAILMODE
);