static char *sccsid
= "@(#)comsat.c 4.9 83/07/04";
#define dprintf if (debug) printf
#define MAXUTMP 100 /* down from init */
struct sockaddr_in sin
= { AF_INET
};
unsigned utmpmtime
; /* last modification time for utmp */
#define NAMLEN (sizeof (uts[0].ut_name) + 1)
sp
= getservbyname("biff", "udp");
fprintf(stderr
, "comsat: biff/udp: unknown service\n");
chdir("/usr/spool/mail");
if((uf
= open("/etc/utmp",0)) < 0)
perror("/etc/utmp"), exit(1);
signal(SIGTTOU
, SIG_IGN
);
s
= socket(AF_INET
, SOCK_DGRAM
, 0, 0);
sin
.sin_port
= sp
->s_port
;
if (bind(s
, &sin
, sizeof (sin
), 0) < 0) {
cc
= recv(s
, msgbuf
, sizeof (msgbuf
) - 1, 0);
if (statbf
.st_mtime
> utmpmtime
) {
utmpmtime
= statbf
.st_mtime
;
nutmp
= read(uf
,utmp
,sizeof(utmp
))/sizeof(struct utmp
);
register struct utmp
*utp
= &utmp
[nutmp
];
dprintf("mailfor %s\n", name
);
while (*cp
&& *cp
!= '@')
if (!strncmp(utp
->ut_name
, name
, sizeof(utmp
[0].ut_name
)))
signal(SIGALRM
, SIG_DFL
);
notify(utp
, offset
), exit(0);
while (wait3(0, WNOHANG
, 0) > 0)
register struct utmp
*utp
;
char tty
[20], hostname
[32];
char name
[sizeof (utmp
[0].ut_name
) + 1];
strncat(tty
, utp
->ut_line
, sizeof(utp
->ut_line
));
dprintf("notify %s on %s\n", utp
->ut_name
, tty
);
if (stat(tty
, &stb
) == 0 && (stb
.st_mode
& 0100) == 0) {
if ((tp
= fopen(tty
,"w")) == 0) {
dprintf("fopen failed\n");
ioctl(fileno(tp
), TIOCGETP
, >tybuf
);
cr
= (gttybuf
.sg_flags
& CRMOD
) ? "" : "\r";
gethostname(hostname
, sizeof (hostname
));
strncpy(name
, utp
->ut_name
, sizeof (utp
->ut_name
));
name
[sizeof (name
) - 1] = 0;
fprintf(tp
,"%s\n\007New mail for %s@%s\007 has arrived:%s\n",
fprintf(tp
,"----%s\n", cr
);
jkfprintf(tp
, name
, offset
);
jkfprintf(tp
, name
, offset
)
register int linecnt
, charcnt
;
dprintf("HERE %s's mail starting at %d\n",
if ((fi
= fopen(name
,"r")) == NULL
) {
dprintf("Cant read the mail\n");
* Print the first 7 lines or 560 characters of the new mail
* (whichever comes first). Skip header crap other than
* From, Subject, To, and Date.
while (fgets(line
, sizeof (line
), fi
) != NULL
) {
if (linecnt
<= 0 || charcnt
<= 0) {
fprintf(tp
,"...more...%s\n", cr
);
if (strncmp(line
, "From ", 5) == 0)
if (inheader
&& (line
[0] == ' ' || line
[0] == '\t'))
if (cp
== 0 || (index(line
, ' ') && index(line
, ' ') < cp
))
strncmp(line
, "Date", cnt
) &&
strncmp(line
, "From", cnt
) &&
strncmp(line
, "Subject", cnt
) &&
strncmp(line
, "To", cnt
))
fprintf(tp
,"%s%s\n", line
, cr
);
linecnt
--, charcnt
-= strlen(line
);
fprintf(tp
,"----%s\n", cr
);