/*remote mail, add rmtmsg */
/* zap header and trailing empty line */
#define MAXLET 300 /* maximum number of letters */
#define MAILMODE (~0644) /* mode of created mail */
char lettmp
[] = "/tmp/maXXXXX";
char maildir
[] = "/usr/spool/mail/";
char mailfile
[] = "/usr/spool/mail/xxxxxxxxxxxxxxxxxxxxxxx";
char dead
[] = "dead.letter";
char forwmsg
[] = " forwarded\n";
struct passwd
*getpwuid();
pwent
= getpwuid(getuid());
my_name
= pwent
->pw_name
;
if(setjmp(sjbuf
)) done();
tmpf
= fopen(lettmp
, "w");
fprintf(stderr
, "mail: cannot open %s for writing\n", lettmp
);
if (argv
[0][0] != 'r' && /* no favors for rmail*/
(argc
== 1 || argv
[1][0] == '-'))
if(signal(i
, SIG_IGN
)!=SIG_IGN
)
cat(mailfile
, maildir
, my_name
);
for (; argc
>1; argv
++, argc
--) {
else if (argv
[1][1]=='p') {
} else if (argv
[1][1]=='f') {
strcpy(mailfile
, argv
[2]);
} else if (argv
[1][1]=='r') {
fprintf(stderr
, "mail: unknown option %c\n", argv
[1][1]);
malf
= fopen(mailfile
, "r");
fprintf(stdout
, "No mail.\n");
tmpf
= fopen(lettmp
, "r");
for (i
= 0; i
< nlet
; ) {
j
= forward
? i
: nlet
- i
- 1;
copylet(j
, stdout
, ORDINARY
);
if (fgets(resp
, LSIZE
, stdin
) == NULL
)
fprintf(stderr
, "usage\n");
fprintf(stderr
, "q\tquit\n");
fprintf(stderr
, "x\texit without changing mail\n");
fprintf(stderr
, "p\tprint\n");
fprintf(stderr
, "s[file]\tsave (default mbox)\n");
fprintf(stderr
, "w[file]\tsame without header\n");
fprintf(stderr
, "-\tprint previous\n");
fprintf(stderr
, "d\tdelete\n");
fprintf(stderr
, "+\tnext (no delete)\n");
fprintf(stderr
, "m user\tmail to user\n");
fprintf(stderr
, "! cmd\texecute cmd\n");
if (resp
[1] != '\n' && resp
[1] != ' ') {
if (resp
[1] == '\n' || resp
[1] == '\0')
for (p
= resp
+1; (p
= getarg(lfil
, p
)) != NULL
; ) {
fprintf(stdout
, "mail: cannot append to %s\n", lfil
);
copylet(j
, malf
, resp
[0]=='w'? ZAP
: ORDINARY
);
if (resp
[1] == '\n' || resp
[1] == '\0') {
printf("invalid command\n");
for (p
= resp
+1; (p
= getarg(lfil
, p
)) != NULL
; )
if (!sendrmt(j
, lfil
)) /* couldn't send it */
copyback() /* copy temp or whatever back to /usr/spool/mail */
signal(SIGQUIT
, SIG_IGN
);
if (stbuf
.st_size
!= let
[nlet
].adr
) { /* new mail has arrived */
malf
= fopen(mailfile
, "r");
fprintf(stdout
, "mail: can't re-read %s\n", mailfile
);
fseek(malf
, let
[nlet
].adr
, 0);
tmpf
= fopen(lettmp
, "a");
fseek(tmpf
, let
[nlet
].adr
, 0);
while ((c
= fgetc(malf
)) != EOF
)
tmpf
= fopen(lettmp
, "r");
let
[++nlet
].adr
= stbuf
.st_size
;
malf
= fopen(mailfile
, "w");
fprintf(stderr
, "mail: can't rewrite %s\n", lfil
);
for (i
= 0; i
< nlet
; i
++)
if (let
[i
].change
!= 'd') {
copylet(i
, malf
, ORDINARY
);
fprintf(stdout
, "new mail arrived\n");
copymt(f1
, f2
) /* copy mail (f1) to temp (f2) */
while (fgets(line
, LSIZE
, f1
) != NULL
) {
let
[nlet
++].adr
= nextadr
;
let
[nlet
].adr
= nextadr
; /* last plus 1 */
copylet(n
, f
, type
) FILE *f
;
fseek(tmpf
, let
[n
].adr
, 0);
k
= let
[n
+1].adr
- let
[n
].adr
;
while(k
-- > 1 && (ch
=fgetc(tmpf
))!='\n')
if(type
!=ZAP
) fputc(ch
,f
);
fprintf(f
, " remote from %s\n", thissys
);
fputc(ch
=fgetc(tmpf
), f
);
if(type
!=ZAP
|| ch
!= '\n')
fprintf(tmpf
, "%s%s %s", from
, my_name
, ctime(&iop
));
while (fgets(line
, LSIZE
, stdin
) != NULL
) {
if (line
[0] == '.' && line
[1] == '\n')
let
[1].adr
= ftell(tmpf
);
tmpf
= fopen(lettmp
, "r");
fprintf(stderr
, "mail: cannot reopen %s for reading\n", lettmp
);
if (!send(0, *++argv
)) /* couldn't send to him */
fprintf(stdout
, "mail: cannot open %s\n", dead
);
fprintf(stdout
, "Mail saved in %s\n", dead
);
for(p
=rsys
; *name
!='!'; *p
++ = *name
++)
if ((!local
&& *name
=='\0') || (local
&& *rsys
=='\0')) {
fprintf(stdout
, "null name\n");
if ((pid
= fork()) == -1) {
fprintf(stderr
, "mail: can't create proc for remote\n");
while (wait(&sts
) != pid
) {
sprintf(cmd
, "mail %s", rsys
);
sprintf(cmd
, "uux - %s!rmail \\(%s\\)", rsys
, name
+1);
sprintf(cmd
, "uux - %s!rmail %s", rsys
, name
+1);
if ((rmf
=popen(cmd
, "w")) == NULL
)
copylet(n
, rmf
, local
? FORWARD
: REMOTE
);
send(n
, name
) /* send letter n to name */
struct passwd
*pw
, *getpwnam();
for(p
=name
; *p
!='!' &&*p
!='\0'; p
++)
return(sendrmt(n
, name
));
if ((pw
= getpwnam(name
)) == NULL
) {
fprintf(stdout
, "mail: can't send to %s\n", name
);
cat(file
, maildir
, name
);
fprintf(stdout
, "mail: cannot append to %s\n", file
);
chown(file
, pw
->pw_uid
, pw
->pw_gid
);
copylet(n
, malf
, ORDINARY
);
if (stat(file
, &stbuf
)<0)
if (stbuf
.st_mode
&01) { /* user x bit is the lock */
if (stbuf
.st_ctime
+60 >= time((long *)0)) {
fprintf(stderr
, "%s busy; try again in a minute\n", file
);
locked
= stbuf
.st_mode
& ~01;
chmod(file
, stbuf
.st_mode
|01);
char *to
, *from1
, *from2
;
char *getarg(s
, p
) /* copy p... into s, update p */
while (*p
== ' ' || *p
== '\t')
if (*p
== '\n' || *p
== '\0')
while (*p
!= ' ' && *p
!= '\t' && *p
!= '\n' && *p
!= '\0')