diff options
-rw-r--r-- | libexec/comsat/comsat.8 | 8 | ||||
-rw-r--r-- | libexec/comsat/comsat.c | 45 |
2 files changed, 42 insertions, 11 deletions
diff --git a/libexec/comsat/comsat.8 b/libexec/comsat/comsat.8 index 395522c..2608676 100644 --- a/libexec/comsat/comsat.8 +++ b/libexec/comsat/comsat.8 @@ -53,7 +53,7 @@ and .Xr inetd 8 ) . The one line messages are of the form: .Pp -.Dl user@mailbox-offset +.Dl user@mailbox-offset[:mailbox-name] .Pp If the .Em user @@ -72,10 +72,14 @@ the message header other than the or .Dq Subject lines are not included in the displayed message. +.Pp +If mailbox-name omitted, standard mailbox assumed. .Sh FILES -.Bl -tag -width /var/run/utmp -compact +.Bl -tag -width /var/mail/user -compact .It Pa /var/run/utmp to find out who's logged on and on what terminals +.It Pa /var/mail/user +standard mailbox .El .Sh SEE ALSO .Xr biff 1 , diff --git a/libexec/comsat/comsat.c b/libexec/comsat/comsat.c index e2e4477..f48c57c 100644 --- a/libexec/comsat/comsat.c +++ b/libexec/comsat/comsat.c @@ -75,7 +75,7 @@ int nutmp, uf; void jkfprintf __P((FILE *, char[], off_t)); void mailfor __P((char *)); -void notify __P((struct utmp *, off_t)); +void notify __P((struct utmp *, char[], off_t, int)); void onalrm __P((int)); void reapchildren __P((int)); @@ -87,7 +87,7 @@ main(argc, argv) struct sockaddr_in from; register int cc; int fromlen; - char msgbuf[100]; + char msgbuf[256]; /* verify proper invocation */ fromlen = sizeof(from); @@ -170,23 +170,39 @@ mailfor(name) { register struct utmp *utp = &utmp[nutmp]; register char *cp; + char *file; off_t offset; + int folder; + char buf[sizeof(_PATH_MAILDIR) + sizeof(utmp[0].ut_name) + 1]; + char buf2[sizeof(_PATH_MAILDIR) + sizeof(utmp[0].ut_name) + 1]; if (!(cp = strchr(name, '@'))) return; *cp = '\0'; offset = atoi(cp + 1); + if (!(cp = strchr(cp + 1, ':'))) + file = name; + else + file = cp + 1; + sprintf(buf, "%s/%.*s", _PATH_MAILDIR, sizeof(utmp[0].ut_name), name); + if (*file != '/') { + sprintf(buf2, "%s/%.*s", _PATH_MAILDIR, sizeof(utmp[0].ut_name), file); + file = buf2; + } + folder = strcmp(buf, file); while (--utp >= utmp) if (!strncmp(utp->ut_name, name, sizeof(utmp[0].ut_name))) - notify(utp, offset); + notify(utp, file, offset, folder); } static char *cr; void -notify(utp, offset) +notify(utp, file, offset, folder) register struct utmp *utp; + char file[]; off_t offset; + int folder; { FILE *tp; struct stat stb; @@ -218,9 +234,11 @@ notify(utp, offset) "\n" : "\n\r"; (void)strncpy(name, utp->ut_name, sizeof(utp->ut_name)); name[sizeof(name) - 1] = '\0'; - (void)fprintf(tp, "%s\007New mail for %s@%.*s\007 has arrived:%s----%s", - cr, name, (int)sizeof(hostname), hostname, cr, cr); - jkfprintf(tp, name, offset); + (void)fprintf(tp, "%s\007New mail for %s@%.*s\007 has arrived%s%s%s:%s----%s", + cr, name, (int)sizeof(hostname), hostname, + folder ? cr : "", folder ? "to " : "", folder ? file : "", + cr, cr); + jkfprintf(tp, file, offset); (void)fclose(tp); _exit(0); } @@ -271,9 +289,18 @@ jkfprintf(tp, name, offset) } /* strip weird stuff so can't trojan horse stupid terminals */ for (cp = line; (ch = *cp) && ch != '\n'; ++cp, --charcnt) { - ch = toascii(ch); - if (!isprint(ch) && !isspace(ch)) + if (!isprint(ch)) { + if (ch & 0x80) + (void)fputs("M-", tp); + ch &= 0177; + if (!isprint(ch)) { + if (ch == 0177) + ch = '?'; + else ch |= 0x40; + (void)fputc('^', tp); + } + } (void)fputc(ch, tp); } (void)fputs(cr, tp); |